Documentation
¶
Overview ¶
Package nat_static_mapping implements the hyperv_nat_static_mapping resource. Wraps the nat_static_mapping/{get,new,set,remove}.ps1 contract via the typed hyperv.Client. Composes with hyperv_virtual_switch's NAT type (or any pre-existing NetNat instance) to build a Windows-native reverse proxy in front of one or more VMs on a private network.
Index ¶
- func New() resource.Resource
- type FirewallRuleModel
- 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)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type FirewallRuleModel ¶
type FirewallRuleModel struct {
Enabled types.Bool `tfsdk:"enabled"`
Name types.String `tfsdk:"name"`
Profile types.String `tfsdk:"profile"`
}
FirewallRuleModel is the nested-attribute model. Carried through types.Object on the parent Model so the framework can serialize it. Defaults applied at the schema layer (enabled=true, profile=Any); name derived in resource.go from protocol + external_port when unset.
type Model ¶
type Model struct {
ID types.String `tfsdk:"id"`
NatName types.String `tfsdk:"nat_name"`
Protocol types.String `tfsdk:"protocol"`
AddressFamily types.String `tfsdk:"address_family"`
ExternalIP types.String `tfsdk:"external_ip"`
ExternalPort types.Int64 `tfsdk:"external_port"`
InternalIP types.String `tfsdk:"internal_ip"`
InternalPort types.Int64 `tfsdk:"internal_port"`
FirewallRule types.Object `tfsdk:"firewall_rule"`
}
Model is the tfsdk-bound struct backing the resource state. Field tags align with schema.go attribute names; conversion to/from the typed hyperv.NatStaticMapping DTO lives in resource.go.
Lookup tuple (NatName, Protocol, ExternalIP, ExternalPort) is RequiresReplace at the schema layer -- it identifies the mapping uniquely and Hyper-V has no rename. internal_ip / internal_port and the firewall sub-attributes are in-place mutable.
type Resource ¶
type Resource struct {
// contains filtered or unexported fields
}
Resource implements hyperv_nat_static_mapping.
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 runs new.ps1 with the plan's attributes 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 mapping is already gone, no need to error.
func (*Resource) ImportState ¶
func (r *Resource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse)
ImportState parses the composite identifier and seeds the lookup tuple in state. Two forms are accepted:
<nat_name>:<protocol>:<external_ip>:<external_port> <nat_name>:<protocol>:<external_ip>:<external_port>:<firewall_rule_name>
The 5-segment form lets users adopt an existing netnat-static-mapping whose firewall rule has a non-default DisplayName -- without it, `Read` can't locate the rule (it keys on the name) and `firewall_rule.name` in state lands as the derived default; any later config that sets a different name then trips `RequiresReplace` on the first plan. The 4-segment form falls back to `derivedFirewallRuleName(...)` so users who created their resource via this provider (or with the same naming convention) can import without knowing the rule name.
The composite `id` attribute keeps its 4-segment form regardless -- it's the resource's stable identifier, not a re-export of the import-only firewall name.
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.
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 runs set.ps1 with the plan's mutable attributes (internal_ip, internal_port, firewall_rule.{enabled, profile}) and writes the post-update read shape back. The lookup tuple (nat_name, protocol, external_ip, external_port, firewall_rule.name) is RequiresReplace at the schema layer, so any change there forces destroy+recreate rather than reaching Update.