vhd

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package vhd implements the hyperv_vhd resource. Wraps the vhd/{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             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

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 dispatches on vhd_type to the appropriate client method and writes the post-create read shape back to state.

func (*Resource) Delete

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

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

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. Other errors -> AddError so a transient fault doesn't silently drop the resource from state.

func (*Resource) Schema

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

func (*Resource) Update

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.

Jump to

Keyboard shortcuts

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