This is an automated email from the ASF dual-hosted git repository. pearl11594 pushed a commit to branch support-acl-rule-import in repository https://gitbox.apache.org/repos/asf/cloudstack-terraform-provider.git
commit ddbb550651f48f0313180838140c625aa4a09a3e Author: Pearl Dsilva <[email protected]> AuthorDate: Wed Sep 17 17:26:47 2025 -0400 Add support to import ACL rules by ACL id --- cloudstack/resource_cloudstack_network_acl_rule.go | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/cloudstack/resource_cloudstack_network_acl_rule.go b/cloudstack/resource_cloudstack_network_acl_rule.go index 1ac6e12..95584c1 100644 --- a/cloudstack/resource_cloudstack_network_acl_rule.go +++ b/cloudstack/resource_cloudstack_network_acl_rule.go @@ -38,6 +38,9 @@ func resourceCloudStackNetworkACLRule() *schema.Resource { Read: resourceCloudStackNetworkACLRuleRead, Update: resourceCloudStackNetworkACLRuleUpdate, Delete: resourceCloudStackNetworkACLRuleDelete, + Importer: &schema.ResourceImporter{ + State: resourceCloudStackNetworkACLRuleImport, + }, Schema: map[string]*schema.Schema{ "acl_id": { @@ -714,3 +717,37 @@ func retryableACLCreationFunc( return r, nil } } + +func resourceCloudStackNetworkACLRuleImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + cs := meta.(*cloudstack.CloudStackClient) + + aclID := d.Id() + + log.Printf("[DEBUG] Attempting to import ACL list with ID: %s", aclID) + if aclExists, err := checkACLListExists(cs, aclID); err != nil { + return nil, fmt.Errorf("error checking ACL list existence: %v", err) + } else if !aclExists { + return nil, fmt.Errorf("ACL list with ID %s does not exist", aclID) + } + + log.Printf("[DEBUG] Found ACL list with ID: %s", aclID) + d.Set("acl_id", aclID) + d.SetId(aclID) + + log.Printf("[DEBUG] Setting managed=true for ACL list import") + d.Set("managed", true) + + return []*schema.ResourceData{d}, nil +} + +func checkACLListExists(cs *cloudstack.CloudStackClient, aclID string) (bool, error) { + log.Printf("[DEBUG] Checking if ACL list exists: %s", aclID) + _, count, err := cs.NetworkACL.GetNetworkACLListByID(aclID) + if err != nil { + log.Printf("[DEBUG] Error getting ACL list by ID: %v", err) + return false, err + } + + log.Printf("[DEBUG] ACL list check result: count=%d", count) + return count > 0, nil +}
