From 29ce2df8731485f051e7ca584935f99dde6fe435 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Fri, 8 Jul 2016 17:16:35 +0200 Subject: [PATCH] Fix refresing ACL rules when the ACL is deleted --- .../cloudstack/resource_cloudstack_disk.go | 1 + .../resource_cloudstack_instance.go | 1 + .../resource_cloudstack_ipaddress.go | 1 + .../cloudstack/resource_cloudstack_network.go | 1 + .../resource_cloudstack_network_acl.go | 8 ++++++- .../resource_cloudstack_network_acl_rule.go | 23 +++++++++++++++++++ .../resource_cloudstack_template.go | 1 + .../cloudstack/resource_cloudstack_vpc.go | 1 + .../providers/cloudstack/r/disk.html.markdown | 4 ++-- .../cloudstack/r/network_acl.html.markdown | 3 +++ .../r/network_acl_rule.html.markdown | 3 +++ 11 files changed, 44 insertions(+), 3 deletions(-) diff --git a/builtin/providers/cloudstack/resource_cloudstack_disk.go b/builtin/providers/cloudstack/resource_cloudstack_disk.go index f0fb1d651..f9d472e30 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_disk.go +++ b/builtin/providers/cloudstack/resource_cloudstack_disk.go @@ -59,6 +59,7 @@ func resourceCloudStackDisk() *schema.Resource { "project": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, ForceNew: true, }, diff --git a/builtin/providers/cloudstack/resource_cloudstack_instance.go b/builtin/providers/cloudstack/resource_cloudstack_instance.go index 550647f4e..ef19c9848 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_instance.go +++ b/builtin/providers/cloudstack/resource_cloudstack_instance.go @@ -105,6 +105,7 @@ func resourceCloudStackInstance() *schema.Resource { "project": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, ForceNew: true, }, diff --git a/builtin/providers/cloudstack/resource_cloudstack_ipaddress.go b/builtin/providers/cloudstack/resource_cloudstack_ipaddress.go index 81211cd95..ffee80f4a 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_ipaddress.go +++ b/builtin/providers/cloudstack/resource_cloudstack_ipaddress.go @@ -31,6 +31,7 @@ func resourceCloudStackIPAddress() *schema.Resource { "project": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, ForceNew: true, }, diff --git a/builtin/providers/cloudstack/resource_cloudstack_network.go b/builtin/providers/cloudstack/resource_cloudstack_network.go index 646897c15..1fccdfd55 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_network.go +++ b/builtin/providers/cloudstack/resource_cloudstack_network.go @@ -97,6 +97,7 @@ func resourceCloudStackNetwork() *schema.Resource { "project": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, ForceNew: true, }, diff --git a/builtin/providers/cloudstack/resource_cloudstack_network_acl.go b/builtin/providers/cloudstack/resource_cloudstack_network_acl.go index 19302f2d2..cf19a511f 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_network_acl.go +++ b/builtin/providers/cloudstack/resource_cloudstack_network_acl.go @@ -29,6 +29,12 @@ func resourceCloudStackNetworkACL() *schema.Resource { ForceNew: true, }, + "project": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "vpc_id": &schema.Schema{ Type: schema.TypeString, Required: true, @@ -70,7 +76,7 @@ func resourceCloudStackNetworkACLRead(d *schema.ResourceData, meta interface{}) // Get the network ACL list details f, count, err := cs.NetworkACL.GetNetworkACLListByID( d.Id(), - cloudstack.WithVPCID(d.Get("vpc_id").(string)), + cloudstack.WithProject(d.Get("project").(string)), ) if err != nil { if count == 0 { diff --git a/builtin/providers/cloudstack/resource_cloudstack_network_acl_rule.go b/builtin/providers/cloudstack/resource_cloudstack_network_acl_rule.go index 8c4200873..0bc86d392 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_network_acl_rule.go +++ b/builtin/providers/cloudstack/resource_cloudstack_network_acl_rule.go @@ -2,6 +2,7 @@ package cloudstack import ( "fmt" + "log" "strconv" "strings" "sync" @@ -88,6 +89,12 @@ func resourceCloudStackNetworkACLRule() *schema.Resource { }, }, + "project": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "parallelism": &schema.Schema{ Type: schema.TypeInt, Optional: true, @@ -265,6 +272,22 @@ func createNetworkACLRule(d *schema.ResourceData, meta interface{}, rule map[str func resourceCloudStackNetworkACLRuleRead(d *schema.ResourceData, meta interface{}) error { cs := meta.(*cloudstack.CloudStackClient) + // First check if the ACL itself still exists + _, count, err := cs.NetworkACL.GetNetworkACLListByID( + d.Id(), + cloudstack.WithProject(d.Get("project").(string)), + ) + if err != nil { + if count == 0 { + log.Printf( + "[DEBUG] Network ACL list %s does no longer exist", d.Id()) + d.SetId("") + return nil + } + + return err + } + // Get all the rules from the running environment p := cs.NetworkACL.NewListNetworkACLsParams() p.SetAclid(d.Id()) diff --git a/builtin/providers/cloudstack/resource_cloudstack_template.go b/builtin/providers/cloudstack/resource_cloudstack_template.go index b3b3a4518..a7591d558 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_template.go +++ b/builtin/providers/cloudstack/resource_cloudstack_template.go @@ -54,6 +54,7 @@ func resourceCloudStackTemplate() *schema.Resource { "project": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, ForceNew: true, }, diff --git a/builtin/providers/cloudstack/resource_cloudstack_vpc.go b/builtin/providers/cloudstack/resource_cloudstack_vpc.go index 424d58ce4..44ce69212 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_vpc.go +++ b/builtin/providers/cloudstack/resource_cloudstack_vpc.go @@ -50,6 +50,7 @@ func resourceCloudStackVPC() *schema.Resource { "project": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, ForceNew: true, }, diff --git a/website/source/docs/providers/cloudstack/r/disk.html.markdown b/website/source/docs/providers/cloudstack/r/disk.html.markdown index 8a59a6bcc..3b62e99cf 100644 --- a/website/source/docs/providers/cloudstack/r/disk.html.markdown +++ b/website/source/docs/providers/cloudstack/r/disk.html.markdown @@ -34,7 +34,7 @@ The following arguments are supported: * `attach` - (Optional) Determines whether or not to attach the disk volume to a virtual machine (defaults false). -* `device` - (Optional) The device to map the disk volume to within the guest OS. +* `device_id` - (Optional) The device ID to map the disk volume to within the guest OS. * `disk_offering` - (Required) The name or ID of the disk offering to use for this disk volume. @@ -58,4 +58,4 @@ The following arguments are supported: The following attributes are exported: * `id` - The ID of the disk volume. -* `device` - The device the disk volume is mapped to within the guest OS. +* `device_id` - The device ID the disk volume is mapped to within the guest OS. diff --git a/website/source/docs/providers/cloudstack/r/network_acl.html.markdown b/website/source/docs/providers/cloudstack/r/network_acl.html.markdown index e8a010cfc..3f91170b6 100644 --- a/website/source/docs/providers/cloudstack/r/network_acl.html.markdown +++ b/website/source/docs/providers/cloudstack/r/network_acl.html.markdown @@ -29,6 +29,9 @@ The following arguments are supported: * `description` - (Optional) The description of the ACL. Changing this forces a new resource to be created. +* `project` - (Optional) The name or ID of the project to deploy this + instance to. Changing this forces a new resource to be created. + * `vpc_id` - (Required) The ID of the VPC to create this ACL for. Changing this forces a new resource to be created. diff --git a/website/source/docs/providers/cloudstack/r/network_acl_rule.html.markdown b/website/source/docs/providers/cloudstack/r/network_acl_rule.html.markdown index 0a61bc769..23b3158d4 100644 --- a/website/source/docs/providers/cloudstack/r/network_acl_rule.html.markdown +++ b/website/source/docs/providers/cloudstack/r/network_acl_rule.html.markdown @@ -40,6 +40,9 @@ The following arguments are supported: * `rule` - (Optional) Can be specified multiple times. Each rule block supports fields documented below. If `managed = false` at least one rule is required! +* `project` - (Optional) The name or ID of the project to deploy this + instance to. Changing this forces a new resource to be created. + * `parallelism` (Optional) Specifies how much rules will be created or deleted concurrently. (defaults 2)