From 8dec84ecddca58328ce6e6c4b7ca3af15adc65b0 Mon Sep 17 00:00:00 2001 From: Marco Sinhoreli Date: Thu, 11 Jun 2026 11:41:43 +0200 Subject: [PATCH] Add import support to network rule resources Adds a passthrough Importer (same pattern as affinity_group and disk) so existing rules can be adopted with `terraform import` / import blocks: - cloudstack_ipaddress (id = public IP id) - cloudstack_loadbalancer_rule (id = LB rule id) - cloudstack_port_forward (id = the IP address id; Read lists its forwards) - cloudstack_static_nat (id = the IP address id; Read checks static NAT) All four Read functions are already id-driven, so no further changes are required for import to populate state. Co-Authored-By: Claude Opus 4.8 Signed-off-by: Marco Sinhoreli --- cloudstack/resource_cloudstack_ipaddress.go | 3 +++ cloudstack/resource_cloudstack_loadbalancer_rule.go | 3 +++ cloudstack/resource_cloudstack_port_forward.go | 3 +++ cloudstack/resource_cloudstack_static_nat.go | 3 +++ 4 files changed, 12 insertions(+) diff --git a/cloudstack/resource_cloudstack_ipaddress.go b/cloudstack/resource_cloudstack_ipaddress.go index c7db4ac0..536196ec 100644 --- a/cloudstack/resource_cloudstack_ipaddress.go +++ b/cloudstack/resource_cloudstack_ipaddress.go @@ -33,6 +33,9 @@ func resourceCloudStackIPAddress() *schema.Resource { Create: resourceCloudStackIPAddressCreate, Read: resourceCloudStackIPAddressRead, Delete: resourceCloudStackIPAddressDelete, + Importer: &schema.ResourceImporter{ + State: importStatePassthrough, + }, Schema: map[string]*schema.Schema{ "is_portable": { diff --git a/cloudstack/resource_cloudstack_loadbalancer_rule.go b/cloudstack/resource_cloudstack_loadbalancer_rule.go index 6ebf52b5..1c53f17b 100644 --- a/cloudstack/resource_cloudstack_loadbalancer_rule.go +++ b/cloudstack/resource_cloudstack_loadbalancer_rule.go @@ -37,6 +37,9 @@ func resourceCloudStackLoadBalancerRule() *schema.Resource { Read: resourceCloudStackLoadBalancerRuleRead, Update: resourceCloudStackLoadBalancerRuleUpdate, Delete: resourceCloudStackLoadBalancerRuleDelete, + Importer: &schema.ResourceImporter{ + State: importStatePassthrough, + }, Schema: map[string]*schema.Schema{ "name": { diff --git a/cloudstack/resource_cloudstack_port_forward.go b/cloudstack/resource_cloudstack_port_forward.go index 2b006738..836fb6a7 100644 --- a/cloudstack/resource_cloudstack_port_forward.go +++ b/cloudstack/resource_cloudstack_port_forward.go @@ -38,6 +38,9 @@ func resourceCloudStackPortForward() *schema.Resource { Read: resourceCloudStackPortForwardRead, Update: resourceCloudStackPortForwardUpdate, Delete: resourceCloudStackPortForwardDelete, + Importer: &schema.ResourceImporter{ + State: importStatePassthrough, + }, Schema: map[string]*schema.Schema{ "ip_address_id": { diff --git a/cloudstack/resource_cloudstack_static_nat.go b/cloudstack/resource_cloudstack_static_nat.go index 2b2c4027..36fef6c6 100644 --- a/cloudstack/resource_cloudstack_static_nat.go +++ b/cloudstack/resource_cloudstack_static_nat.go @@ -34,6 +34,9 @@ func resourceCloudStackStaticNAT() *schema.Resource { Exists: resourceCloudStackStaticNATExists, Read: resourceCloudStackStaticNATRead, Delete: resourceCloudStackStaticNATDelete, + Importer: &schema.ResourceImporter{ + State: importStatePassthrough, + }, Schema: map[string]*schema.Schema{ "ip_address_id": {