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. The lookup tuple (NatName, Protocol, ExternalIP, ExternalPort) is RequiresReplace at the schema layer, since 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 result 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. The 5-segment form is for a non-default firewall rule name, since Read can't locate a rule without already knowing it; the 4-segment form derives it instead. The stored `id` always keeps the 4-segment form: a stable identifier, not the import-only firewall name.
<nat_name>:<protocol>:<external_ip>:<external_port> <nat_name>:<protocol>:<external_ip>:<external_port>:<firewall_rule_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 state via get.ps1 and reconciles it. 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 result back. The lookup tuple (nat_name, protocol, external_ip, external_port, firewall_rule.name) is RequiresReplace at the schema layer, so a change there forces destroy+recreate instead.