This is an automated email from the ASF dual-hosted git repository.
kiranchavala pushed a commit to branch main
in repository
https://gitbox.apache.org/repos/asf/cloudstack-terraform-provider.git
The following commit(s) were added to refs/heads/main by this push:
new 3bebccd Add support to import ACL rules by ACL id (#224)
3bebccd is described below
commit 3bebccd85436172678c04ecaf6b1486c635eaa91
Author: Pearl Dsilva <[email protected]>
AuthorDate: Tue Sep 23 01:46:19 2025 -0400
Add support to import ACL rules by ACL id (#224)
* Add support to import ACL rules by ACL id
* remove id being set to aclid
* remove id being set to aclid
---
cloudstack/resource_cloudstack_network_acl_rule.go | 36 ++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/cloudstack/resource_cloudstack_network_acl_rule.go
b/cloudstack/resource_cloudstack_network_acl_rule.go
index 1ac6e12..b78ca62 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,36 @@ 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)
+
+ 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
+}