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 ¶
- func New() resource.Resource
- type Model
- type Resource
- func (r *Resource) ConfigValidators(_ context.Context) []resource.ConfigValidator
- func (r *Resource) Configure(_ context.Context, req resource.ConfigureRequest, ...)
- func (r *Resource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse)
- func (r *Resource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse)
- func (r *Resource) ImportState(ctx context.Context, req resource.ImportStateRequest, ...)
- func (r *Resource) Metadata(_ context.Context, req resource.MetadataRequest, ...)
- func (r *Resource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse)
- func (r *Resource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse)
- func (r *Resource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
func (r *Resource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse)
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 ¶
func (r *Resource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse)
Create runs new.ps1 with the plan's attributes and writes the post-create read shape back to state.
func (*Resource) Delete ¶
func (r *Resource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse)
Delete runs remove.ps1. ErrNotFound is treated as success -- the switch is already gone, no need to error.
func (*Resource) ImportState ¶
func (r *Resource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse)
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 ¶
func (r *Resource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse)
Metadata sets the resource's TF type name.
func (*Resource) Read ¶
func (r *Resource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse)
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 ¶
func (r *Resource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse)
Schema returns the locked-in schema (see schema.go).
func (*Resource) Update ¶
func (r *Resource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse)
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.