Documentation
¶
Overview ¶
Package path provides a custom Terraform attribute type for Windows file paths used by the Hyper-V provider. The custom type's purpose is to suppress spurious diffs and "inconsistent result after apply" failures arising from path-representation mismatches between user input and what Hyper-V cmdlets emit on Read.
Two kinds of mismatch are handled:
- Slash style. Users may write `C:/hyperv/vhds/disk.vhdx` (forward slashes -- HCL-friendly, no escaping needed) but Hyper-V cmdlets return paths with backslashes. Without semantic equality, the framework's plan-vs-apply consistency check fires and rejects the apply with "Provider produced inconsistent result after apply" -- a real bug surfaced by the M1d acceptance tests.
- Casing. Windows file systems are case-insensitive (NTFS exposes a stable casing for each file, but `c:\foo` and `C:\foo` refer to the same path). Users who write `c:\foo` and read back `C:\foo` would otherwise see a phantom diff on every plan.
The stored attribute value preserves the user's original form -- only equality comparison (StringSemanticEquals) normalizes. This keeps plan output readable in the user's chosen style while keeping the provider's plan/apply contract honest.
Usage:
"destination_path": schema.StringAttribute{
CustomType: path.Type,
Required: true,
...
}
And in the model struct:
type Model struct {
DestinationPath path.Path `tfsdk:"destination_path"`
...
}
Path embeds basetypes.StringValue, so existing call sites that use .ValueString() / .IsNull() / .IsUnknown() continue to work unchanged.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Type = pathType{}
Type is the singleton attribute type for Windows file paths. Pass it as `CustomType:` on string attributes whose value is a path emitted by a Hyper-V cmdlet.
Functions ¶
This section is empty.
Types ¶
type Path ¶
type Path struct {
basetypes.StringValue
}
Path is the attribute-value implementation. Embeds StringValue so the .ValueString() / .IsNull() / .IsUnknown() accessors that resource code uses continue to work unchanged after a schema's CustomType is set to path.Type.
func NewPathNull ¶
func NewPathNull() Path
NewPathNull constructs a null Path. Convenient for collapsing empty optional-attribute reads to schema-null on the wire.
func NewPathUnknown ¶
func NewPathUnknown() Path
NewPathUnknown constructs an unknown Path. Used in plan modification when a value depends on apply-time information.
func NewPathValue ¶
NewPathValue constructs a known, non-null Path. Convenient when hydrating a model from a typed-client struct on Read.
func (Path) Equal ¶
Equal compares two Path values for raw equality (byte-for-byte). The framework calls this for known-after-apply tracking and other plan-machinery checks where we DO want strict equality. Semantic equality is the separate StringSemanticEquals method.
func (Path) StringSemanticEquals ¶
func (p Path) StringSemanticEquals(_ context.Context, newValuable basetypes.StringValuable) (bool, diag.Diagnostics)
StringSemanticEquals is the load-bearing method. The framework calls this when comparing planned vs applied (or stored vs refreshed) values; if it returns true, the framework treats the values as the same and suppresses the diff. Returning true here is what bridges "user wrote C:/foo, Hyper-V returned C:\foo" without losing the strict-equality guarantees the framework needs elsewhere.
Both values are normalized (slash-folded + lowercased) before comparison. Null/unknown handling is left to the framework's pre-check: StringSemanticEquals is only invoked when both sides are known and non-null.