Help us shape the future of Go! Take the 2026 Go Developer Survey

vswitch

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MPL-2.0 Imports: 19 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"`
	NatName                        types.String `tfsdk:"nat_name"`
	NatInternalAddressPrefix       types.String `tfsdk:"nat_internal_address_prefix"`
	NatHostAddress                 types.String `tfsdk:"nat_host_address"`
	ForceManagementOSMigration     types.Bool   `tfsdk:"force_management_os_migration"`
}

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. NAT fields (NatName, NatInternalAddressPrefix, NatHostAddress) are required when SwitchType == "NAT" and rejected on other types via the resource-layer validators; ForceManagementOSMigration is opt-in for External-switch destroy paths (see 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 result back to state.

func (*Resource) Delete

Delete runs remove.ps1; ErrNotFound is success. An External switch with AllowManagementOS=true triggers an asynchronous IP migration back to the physical NIC during teardown; if the SSH session traverses this switch's vNIC, a mid-migration drop can leave the host LAN-unreachable, recoverable only via console or IPMI. Destroy refuses without force_management_os_migration as the operator's explicit acknowledgement, since detecting the actual network topology from inside the provider would need cross-backend introspection this flag sidesteps.

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 state via get.ps1 and reconciles it. 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 result 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