image_file

package
v0.1.3 Latest Latest
Warning

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

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

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

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"`
	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

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 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

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

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

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. ErrUnauthorized / ErrPSExecution -> 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 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.

type URLConfig

type URLConfig struct {
	URL      types.String `tfsdk:"url"`
	Checksum types.String `tfsdk:"checksum"`
}

URLConfig is the user-supplied URL-mode source configuration. Both fields are required when the block is present; the schema-layer Required flag enforces this without a separate config validator.

Jump to

Keyboard shortcuts

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