nat_static_mapping

package
v0.3.0 Latest Latest
Warning

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

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

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() resource.Resource

New is the framework factory.

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

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 runs new.ps1 with the plan's attributes and writes the post-create read shape back to state.

func (*Resource) Delete

Delete runs remove.ps1. ErrNotFound is treated as success -- the mapping is already gone, no need to error.

func (*Resource) ImportState

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

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.

func (*Resource) Schema

Schema returns the locked-in schema (see schema.go).

func (*Resource) Update

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.

Jump to

Keyboard shortcuts

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