Documentation
¶
Overview ¶
Package vhd implements the hyperv_vhd resource. Wraps the vhd/{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 pathtype.Path `tfsdk:"id"`
Path pathtype.Path `tfsdk:"path"`
VhdType types.String `tfsdk:"vhd_type"`
SizeBytes types.Int64 `tfsdk:"size_bytes"`
ParentPath pathtype.Path `tfsdk:"parent_path"`
BlockSizeBytes types.Int64 `tfsdk:"block_size_bytes"`
FileSizeBytes types.Int64 `tfsdk:"file_size_bytes"`
Format types.String `tfsdk:"format"`
Attached types.Bool `tfsdk:"attached"`
}
Model is the tfsdk-bound struct backing the resource state. Field tags align with schema.go attribute names; conversion to/from the typed hyperv.VHD DTO lives in resource.go.
vhd_type is "fixed" | "dynamic" | "differencing" on the schema/wire-stdin side; Get-VHD's VhdType property emits PascalCase ("Fixed"/"Dynamic"/ "Differencing") on the wire-stdout side. modelFromVHD lowercases when hydrating from the cmdlet read-back.
Path and ParentPath use the pathtype.Path custom type so users can write either `C:/foo` or `C:\foo` without the framework rejecting the apply with "Provider produced inconsistent result after apply" when Hyper-V returns the canonical backslash form.
type Resource ¶
type Resource struct {
// contains filtered or unexported fields
}
Resource implements hyperv_vhd.
func (*Resource) ConfigValidators ¶
func (r *Resource) ConfigValidators(_ context.Context) []resource.ConfigValidator
ConfigValidators rejects mode/attribute combinations at plan time so the operator gets a clear, attribute-anchored diagnostic instead of the cmdlet's opaque "wrong parameter set" error at apply time -- or, in the case of block_size_bytes on differencing, an infinite-replace loop where the user's config value never matches the parent-inherited state value.
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 dispatches on vhd_type to the appropriate client method 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 file is already gone). The cmdlet errors loudly when the disk is attached to a running VM (open file handle); we surface that as-is so the operator sees the cause and can detach.
func (*Resource) ImportState ¶
func (r *Resource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse)
ImportState lets `terraform import hyperv_vhd.foo C:\path\to\file.vhdx` work by treating the import ID as the path. Read populates vhd_type and the rest of the attributes via Get-VHD on the immediately-following refresh.
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. Other errors -> AddError so a transient fault doesn't silently drop the resource from state.
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 handles the only in-place mutation: size_bytes change. Every other attribute is RequiresReplace at the schema layer and triggers destroy+recreate before reaching here.
When size_bytes hasn't changed (e.g., framework re-runs Update due to a Computed-attribute diff after refresh), pass plan straight to state without a host call.