Documentation
¶
Overview ¶
Package image_file implements the hyperv_image_file resource. Wraps the image_file/{get,new,remove}.ps1 contract via the typed hyperv.Client.
Index ¶
- func New() resource.Resource
- type Model
- type Resource
- 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)
- type URLConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Model ¶
type Model struct {
ID pathtype.Path `tfsdk:"id"`
DestinationPath pathtype.Path `tfsdk:"destination_path"`
URL *URLConfig `tfsdk:"url"`
Sha256 types.String `tfsdk:"sha256"`
SizeBytes types.Int64 `tfsdk:"size_bytes"`
}
Model is the tfsdk-bound struct backing the resource state. Field tags align with schema.go attribute names; conversion to/from the typed hyperv.ImageFile DTO lives in resource.go.
URL is a pointer so its presence/absence acts as the source-mode discriminator: non-nil => url-mode (HttpClient fetch), nil => host_path-mode (verify-only). Mode switches between configs trigger RequiresReplace at the schema layer; Delete keys on this same nil check to gate the host-side remove.
DestinationPath uses 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. ID mirrors destination_path and is also Path so the same semantic-equality covers the Computed mirror's refresh path.
type Resource ¶
type Resource struct {
// contains filtered or unexported fields
}
Resource implements hyperv_image_file.
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 source mode (url vs host_path) and writes the post-create read shape back to state.
url-mode: the provider fetches via HttpClient and verifies the checksum. ErrChecksumMismatch is surfaced on path.Root("url").AtName("checksum") so the diagnostic anchors to the offending attribute, not the resource.
host_path-mode: the provider verifies the file already exists at destination_path. ErrNotFound is anchored to destination_path.
func (*Resource) Delete ¶
func (r *Resource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse)
Delete runs remove.ps1 ONLY for url-mode resources. For host_path-mode (state.URL == nil), the file was already on the host before the resource was created -- removing it on destroy would surprise the operator.
ErrNotFound from RemoveImageFile is treated as success (the file 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_image_file.foo C:\path\file.vhdx` work by treating the import ID as the destination path. The imported resource lands in host_path mode (no url block) -- importing inherently means "this file already exists on the host." Users can convert to url-mode later by adding the block, which will trigger replacement.
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. ErrUnauthorized / ErrPSExecution -> 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 is effectively unreachable -- every user-settable schema field is RequiresReplace -- but the framework requires the method. Pass the plan through to state so any framework-internal Computed propagation lands.