Skip to content

Add support to import ACL rules by ACL id#224

Merged
kiranchavala merged 3 commits intomainfrom
support-acl-rule-import
Sep 23, 2025
Merged

Add support to import ACL rules by ACL id#224
kiranchavala merged 3 commits intomainfrom
support-acl-rule-import

Conversation

@Pearl1594
Copy link
Copy Markdown
Contributor

@Pearl1594 Pearl1594 commented Sep 17, 2025

  1. create the resource configuration in the root module

resource "cloudstack_network_acl_rule" "customAclRules" {
}

  1. execute:
terraform import cloudstack_network_acl_rule.customAclRules 6efef584-d405-41f7-92a0-a66625496c97

Where 6efef584-d405-41f7-92a0-a66625496c97 is the UUID of the ACL from which the rules need to be imported

  1. Run terraform show and find the ACL rules now managed by terraform:
# cloudstack_network_acl_rule.customAclRules:
resource "cloudstack_network_acl_rule" "customAclRules" {
    acl_id  = "6efef584-d405-41f7-92a0-a66625496c97"
    managed = true

    rule {
        action       = null
        cidr_list    = [
            "1d6aae62-e5f5-4a6a-ad17-dd5a4aee3e8c",
        ]
        description  = null
        icmp_code    = 0
        icmp_type    = 0
        ports        = []
        protocol     = "1d6aae62-e5f5-4a6a-ad17-dd5a4aee3e8c"
        rule_number  = 0
        traffic_type = null
        uuids        = {
            "1d6aae62-e5f5-4a6a-ad17-dd5a4aee3e8c" = "1d6aae62-e5f5-4a6a-ad17-dd5a4aee3e8c"
        }
    }
}

Logs that the resource is successfully imported:

cloudstack_network_acl_rule.customAclRules: Importing from ID "6efef584-d405-41f7-92a0-a66625496c97"...
2025-09-17T16:54:37.971-0400 [DEBUG] ReferenceTransformer: "data.cloudstack_template.centos" references: []
2025-09-17T16:54:37.972-0400 [DEBUG] provider.terraform-provider-cloudstack: 2025/09/17 16:54:37 [DEBUG] Attempting to import with ID: 6efef584-d405-41f7-92a0-a66625496c97, project: 
2025-09-17T16:54:37.972-0400 [DEBUG] provider.terraform-provider-cloudstack: 2025/09/17 16:54:37 [DEBUG] Checking if ACL list exists: 6efef584-d405-41f7-92a0-a66625496c97, project: 
data.cloudstack_template.centos: Reading...
2025-09-17T16:54:38.287-0400 [DEBUG] provider.terraform-provider-cloudstack: 2025/09/17 16:54:38 [DEBUG] ACL list check result: count=1
2025-09-17T16:54:38.287-0400 [DEBUG] provider.terraform-provider-cloudstack: 2025/09/17 16:54:38 [DEBUG] Found ACL list with ID: 6efef584-d405-41f7-92a0-a66625496c97
2025-09-17T16:54:38.287-0400 [DEBUG] provider.terraform-provider-cloudstack: 2025/09/17 16:54:38 [DEBUG] Setting managed=true for ACL list import
cloudstack_network_acl_rule.customAclRules: Import prepared!
  Prepared cloudstack_network_acl_rule for import
cloudstack_network_acl_rule.customAclRules: Refreshing state... [id=6efef584-d405-41f7-92a0-a66625496c97]
2025-09-17T16:54:38.306-0400 [DEBUG] provider.terraform-provider-cloudstack: 2025/09/17 16:54:38 [DEBUG] Selected template: CentOS 5.5(64-bit) no GUI (KVM)
2025-09-17T16:54:38.306-0400 [DEBUG] provider.terraform-provider-cloudstack: 2025/09/17 16:54:38 [ERROR] setting state: size: '' expected type 'string', got unconvertible type 'int64', value: '8589934592'
data.cloudstack_template.centos: Read complete after 0s [id=67c3a097-8416-11f0-9a72-1e001b000238]
2025-09-17T16:54:38.307-0400 [DEBUG] ReferenceTransformer: "cloudstack_instance.initial_vm" references: []
2025-09-17T16:54:38.650-0400 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2025-09-17T16:54:38.652-0400 [INFO]  provider: plugin process exited: plugin=/home/pdsilva/sb/terraform/local-providers/hashicorp.com/dev/cloudstack/1.0.0/linux_amd64/terraform-provider-cloudstack id=213630
2025-09-17T16:54:38.652-0400 [DEBUG] provider: plugin exited
2025-09-17T16:54:38.652-0400 [INFO]  Writing state output to:

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

Did the same for project level - works as expected.

@Pearl1594 Pearl1594 linked an issue Sep 17, 2025 that may be closed by this pull request
@kiranchavala kiranchavala added this to the v0.6.0 milestone Sep 19, 2025
Copy link
Copy Markdown
Member

@kiranchavala kiranchavala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Tested manually


TF_LOG=DEBUG terraform import cloudstack_network_acl_rule.default 44d043fa-3a87-4c20-8462-28099ba1920e
2025-09-22T12:56:31.776+0530 [INFO]  Terraform version: 1.12.1
2025-09-22T12:56:31.777+0530 [DEBUG] using github.com/hashicorp/go-tfe v1.74.1
2025-09-22T12:56:31.777+0530 [DEBUG] using github.com/hashicorp/hcl/v2 v2.23.1-0.20250203194505-ba0759438da2
2025-09-22T12:56:31.777+0530 [DEBUG] using github.com/hashicorp/terraform-svchost v0.1.1
2025-09-22T12:56:31.777+0530 [DEBUG] using github.com/zclconf/go-cty v1.16.2
2025-09-22T12:56:31.777+0530 [INFO]  Go runtime version: go1.24.2
2025-09-22T12:56:31.777+0530 [INFO]  CLI args: []string{"terraform", "import", "cloudstack_network_acl_rule.default", "44d043fa-3a87-4c20-8462-28099ba1920e"}
2025-09-22T12:56:31.777+0530 [DEBUG] Attempting to open CLI config file: /Users/kiranchavala/.terraformrc
2025-09-22T12:56:31.777+0530 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2025-09-22T12:56:31.777+0530 [DEBUG] checking for credentials in "/Users/kiranchavala/.terraform.d/plugins"
2025-09-22T12:56:31.777+0530 [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
2025-09-22T12:56:31.777+0530 [DEBUG] will search for provider plugins in /Users/kiranchavala/.terraform.d/plugins
2025-09-22T12:56:31.778+0530 [DEBUG] ignoring non-existing provider search directory /Users/kiranchavala/Library/Application Support/io.terraform/plugins
2025-09-22T12:56:31.778+0530 [DEBUG] ignoring non-existing provider search directory /Library/Application Support/io.terraform/plugins
2025-09-22T12:56:31.780+0530 [INFO]  CLI command args: []string{"import", "cloudstack_network_acl_rule.default", "44d043fa-3a87-4c20-8462-28099ba1920e"}
2025-09-22T12:56:31.845+0530 [DEBUG] checking for provisioner in "."
2025-09-22T12:56:31.848+0530 [DEBUG] checking for provisioner in "/opt/homebrew/bin"
2025-09-22T12:56:31.848+0530 [DEBUG] checking for provisioner in "/Users/kiranchavala/.terraform.d/plugins"
2025-09-22T12:56:31.856+0530 [DEBUG] Building and walking import graph
2025-09-22T12:56:31.858+0530 [DEBUG] Not attaching any node states: overall state is nil
2025-09-22T12:56:31.858+0530 [DEBUG] No state, no orphan outputs
2025-09-22T12:56:31.858+0530 [DEBUG] ProviderTransformer: "cloudstack_network_acl_rule.default (expand)" (*terraform.nodeExpandPlannableResource) needs provider["localdomain/provider/cloudstack"]
2025-09-22T12:56:31.859+0530 [DEBUG] created provider logger: level=debug
2025-09-22T12:56:31.859+0530 [INFO]  provider: configuring client automatic mTLS
2025-09-22T12:56:31.874+0530 [DEBUG] provider: starting plugin: path=.terraform/providers/localdomain/provider/cloudstack/0.4.0/darwin_arm64/terraform-provider-cloudstack args=[".terraform/providers/localdomain/provider/cloudstack/0.4.0/darwin_arm64/terraform-provider-cloudstack"]
2025-09-22T12:56:31.876+0530 [DEBUG] provider: plugin started: path=.terraform/providers/localdomain/provider/cloudstack/0.4.0/darwin_arm64/terraform-provider-cloudstack pid=73179
2025-09-22T12:56:31.876+0530 [DEBUG] provider: waiting for RPC address: plugin=.terraform/providers/localdomain/provider/cloudstack/0.4.0/darwin_arm64/terraform-provider-cloudstack
2025-09-22T12:56:31.898+0530 [INFO]  provider.terraform-provider-cloudstack: configuring server automatic mTLS: timestamp="2025-09-22T12:56:31.897+0530"
2025-09-22T12:56:31.907+0530 [DEBUG] provider.terraform-provider-cloudstack: plugin address: address=/var/folders/2f/6r19_y2s5p92vdzq4l29n0lr0000gn/T/plugin3546309284 network=unix timestamp="2025-09-22T12:56:31.907+0530"
2025-09-22T12:56:31.907+0530 [DEBUG] provider: using plugin: version=6
2025-09-22T12:56:31.931+0530 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2025-09-22T12:56:31.931+0530 [INFO]  provider: plugin process exited: plugin=.terraform/providers/localdomain/provider/cloudstack/0.4.0/darwin_arm64/terraform-provider-cloudstack id=73179
2025-09-22T12:56:31.932+0530 [DEBUG] provider: plugin exited
2025-09-22T12:56:31.932+0530 [DEBUG] ReferenceTransformer: "var.cloudstack_secret_key" references: []
2025-09-22T12:56:31.932+0530 [DEBUG] ReferenceTransformer: "var.cloudstack_api_url" references: []
2025-09-22T12:56:31.932+0530 [DEBUG] ReferenceTransformer: "provider[\"localdomain/provider/cloudstack\"]" references: [var.cloudstack_secret_key var.cloudstack_api_key var.cloudstack_api_url]
2025-09-22T12:56:31.932+0530 [DEBUG] ReferenceTransformer: "cloudstack_network_acl_rule.default (expand)" references: []
2025-09-22T12:56:31.932+0530 [DEBUG] ReferenceTransformer: "var.cloudstack_api_key" references: []
2025-09-22T12:56:31.933+0530 [DEBUG] Starting graph walk: walkImport
2025-09-22T12:56:31.937+0530 [DEBUG] created provider logger: level=debug
2025-09-22T12:56:31.937+0530 [INFO]  provider: configuring client automatic mTLS
2025-09-22T12:56:31.942+0530 [DEBUG] provider: starting plugin: path=.terraform/providers/localdomain/provider/cloudstack/0.4.0/darwin_arm64/terraform-provider-cloudstack args=[".terraform/providers/localdomain/provider/cloudstack/0.4.0/darwin_arm64/terraform-provider-cloudstack"]
2025-09-22T12:56:31.944+0530 [DEBUG] provider: plugin started: path=.terraform/providers/localdomain/provider/cloudstack/0.4.0/darwin_arm64/terraform-provider-cloudstack pid=73180
2025-09-22T12:56:31.944+0530 [DEBUG] provider: waiting for RPC address: plugin=.terraform/providers/localdomain/provider/cloudstack/0.4.0/darwin_arm64/terraform-provider-cloudstack
2025-09-22T12:56:31.954+0530 [INFO]  provider.terraform-provider-cloudstack: configuring server automatic mTLS: timestamp="2025-09-22T12:56:31.954+0530"
2025-09-22T12:56:31.964+0530 [DEBUG] provider: using plugin: version=6
2025-09-22T12:56:31.964+0530 [DEBUG] provider.terraform-provider-cloudstack: plugin address: address=/var/folders/2f/6r19_y2s5p92vdzq4l29n0lr0000gn/T/plugin2909772851 network=unix timestamp="2025-09-22T12:56:31.964+0530"
2025-09-22T12:56:31.979+0530 [DEBUG] ReferenceTransformer: "cloudstack_network_acl_rule.default (import id \"44d043fa-3a87-4c20-8462-28099ba1920e\")" references: []
cloudstack_network_acl_rule.default: Importing from ID "44d043fa-3a87-4c20-8462-28099ba1920e"...
2025-09-22T12:56:31.980+0530 [DEBUG] provider.terraform-provider-cloudstack: 2025/09/22 12:56:31 [DEBUG] Attempting to import ACL list with ID: 44d043fa-3a87-4c20-8462-28099ba1920e
2025-09-22T12:56:31.980+0530 [DEBUG] provider.terraform-provider-cloudstack: 2025/09/22 12:56:31 [DEBUG] Checking if ACL list exists: 44d043fa-3a87-4c20-8462-28099ba1920e
2025-09-22T12:56:32.523+0530 [DEBUG] provider.terraform-provider-cloudstack: 2025/09/22 12:56:32 [DEBUG] ACL list check result: count=1
2025-09-22T12:56:32.523+0530 [DEBUG] provider.terraform-provider-cloudstack: 2025/09/22 12:56:32 [DEBUG] Found ACL list with ID: 44d043fa-3a87-4c20-8462-28099ba1920e
2025-09-22T12:56:32.523+0530 [DEBUG] provider.terraform-provider-cloudstack: 2025/09/22 12:56:32 [DEBUG] Setting managed=true for ACL list import
cloudstack_network_acl_rule.default: Import prepared!
  Prepared cloudstack_network_acl_rule for import
cloudstack_network_acl_rule.default: Refreshing state... [id=44d043fa-3a87-4c20-8462-28099ba1920e]
2025-09-22T12:56:33.075+0530 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2025-09-22T12:56:33.077+0530 [INFO]  provider: plugin process exited: plugin=.terraform/providers/localdomain/provider/cloudstack/0.4.0/darwin_arm64/terraform-provider-cloudstack id=73180
2025-09-22T12:56:33.077+0530 [DEBUG] provider: plugin exited
2025-09-22T12:56:33.077+0530 [INFO]  Writing state output to:

@kiranchavala
Copy link
Copy Markdown
Member

Copy link
Copy Markdown
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm, but add some unit-test

@kiranchavala kiranchavala merged commit 3bebccd into main Sep 23, 2025
87 of 91 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Import Network ACL Rule

3 participants