vswitch

package
v0.0.0-...-ab035be Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2026 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package vswitch implements the hyperv_virtual_switch resource. Wraps the vswitch/{get,new,set,remove}.ps1 contract via the typed hyperv.Client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() resource.Resource

New is the framework factory.

Types

type Model

type Model struct {
	ID                             types.String `tfsdk:"id"`
	Name                           types.String `tfsdk:"name"`
	SwitchType                     types.String `tfsdk:"switch_type"`
	NetAdapterNames                types.List   `tfsdk:"net_adapter_names"`
	AllowManagementOS              types.Bool   `tfsdk:"allow_management_os"`
	Notes                          types.String `tfsdk:"notes"`
	NetAdapterInterfaceDescription types.String `tfsdk:"net_adapter_interface_description"`
}

Model is the tfsdk-bound struct backing the resource state. Field tags align with schema.go attribute names; conversion to/from the typed hyperv.VMSwitch DTO lives in resource.go.

type Resource

type Resource struct {
	// contains filtered or unexported fields
}

Resource implements hyperv_virtual_switch.

func (*Resource) ConfigValidators

func (r *Resource) ConfigValidators(_ context.Context) []resource.ConfigValidator

ConfigValidators surfaces cross-attribute checks at plan time. The script layer still enforces the same invariants as defense-in-depth (direct script invocation in tests bypasses the framework), but plan-time rejection is the better UX -- `terraform validate` and `plan` catch the bad config before any cmdlet runs.

func (*Resource) Configure

Configure stashes the typed Hyper-V client built by the provider's Configure pass. Skips when ProviderData is nil (validate-time invocation before the provider has resolved its config).

func (*Resource) Create

Create runs new.ps1 with the plan's attributes and writes the post-create read shape back to state.

func (*Resource) Delete

Delete runs remove.ps1. ErrNotFound is treated as success -- the switch is already gone, no need to error.

func (*Resource) ImportState

ImportState lets `terraform import hyperv_virtual_switch.foo my-switch` work by treating the import ID as the switch name. Read populates the rest of the attributes by calling GetVMSwitch.

func (*Resource) Metadata

Metadata sets the resource's TF type name.

func (*Resource) Read

Read fetches the current shape via get.ps1 and reconciles state.

ErrNotFound -> RemoveResource so Terraform plans recreate. ErrUnavailable -> AddError so a transient vmms outage doesn't drop the resource from state. (See errors.go for the sentinel rationale.)

func (*Resource) Schema

Schema returns the locked-in schema (see schema.go).

func (*Resource) Update

Update runs set.ps1 with the plan's mutable attributes (net_adapter_names, allow_management_os, notes) and writes the post-update read shape back.

switch_type is taken from STATE -- the schema marks it RequiresReplace, so any change there forces destroy+recreate rather than reaching Update -- and forwarded so set.ps1's Private + AllowManagementOS guard fires with a clear error instead of the cmdlet's opaque one.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL