Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to disable status check in resource_openstack_dns_zone_v2 #1114

Merged
merged 1 commit into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions openstack/import_openstack_dns_zone_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ func TestAccDNSV2Zone_importBasic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"disable_status_check",
},
},
},
})
Expand Down
31 changes: 31 additions & 0 deletions openstack/resource_openstack_dns_zone_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ func resourceDNSZoneV2() *schema.Resource {
Optional: true,
ForceNew: true,
},

"disable_status_check": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
}
}
Expand Down Expand Up @@ -142,6 +148,13 @@ func resourceDNSZoneV2Create(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Error creating openstack_dns_zone_v2: %s", err)
}

if d.Get("disable_status_check").(bool) {
d.SetId(n.ID)

log.Printf("[DEBUG] Created OpenStack DNS Zone %s: %#v", n.ID, n)
return resourceDNSZoneV2Read(d, meta)
}

log.Printf("[DEBUG] Waiting for openstack_dns_zone_v2 %s to become available", n.ID)
stateConf := &resource.StateChangeConf{
Target: []string{"ACTIVE"},
Expand Down Expand Up @@ -203,21 +216,31 @@ func resourceDNSZoneV2Update(d *schema.ResourceData, meta interface{}) error {
}

var updateOpts zones.UpdateOpts
changed := false
if d.HasChange("email") {
updateOpts.Email = d.Get("email").(string)
changed = true
}

if d.HasChange("ttl") {
updateOpts.TTL = d.Get("ttl").(int)
changed = true
}

if d.HasChange("masters") {
updateOpts.Masters = expandToStringSlice(d.Get("masters").(*schema.Set).List())
changed = true
}

if d.HasChange("description") {
description := d.Get("description").(string)
updateOpts.Description = &description
changed = true
}

if !changed {
// Nothing in OpenStack fields really changed, so just return zone from OpenStack
return resourceDNSZoneV2Read(d, meta)
}

if err := dnsClientSetAuthHeader(d, dnsClient); err != nil {
Expand All @@ -231,6 +254,10 @@ func resourceDNSZoneV2Update(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Error updating openstack_dns_zone_v2 %s: %s", d.Id(), err)
}

if d.Get("disable_status_check").(bool) {
return resourceDNSZoneV2Read(d, meta)
}

stateConf := &resource.StateChangeConf{
Target: []string{"ACTIVE"},
Pending: []string{"PENDING"},
Expand Down Expand Up @@ -265,6 +292,10 @@ func resourceDNSZoneV2Delete(d *schema.ResourceData, meta interface{}) error {
return CheckDeleted(d, err, "Error deleting openstack_dns_zone_v2")
}

if d.Get("disable_status_check").(bool) {
return nil
}

stateConf := &resource.StateChangeConf{
Target: []string{"DELETED"},
Pending: []string{"ACTIVE", "PENDING"},
Expand Down
42 changes: 42 additions & 0 deletions openstack/resource_openstack_dns_zone_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,35 @@ func TestAccDNSV2Zone_basic(t *testing.T) {
})
}

func TestAccDNSV2Zone_ignoreStatusCheck(t *testing.T) {
var zone zones.Zone
var zoneName = fmt.Sprintf("ACPTTEST%s.com.", acctest.RandString(5))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckDNS(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDNSV2ZoneDestroy,
Steps: []resource.TestStep{
{
Config: testAccDNSV2ZoneDisableCheck(zoneName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDNSV2ZoneExists("openstack_dns_zone_v2.zone_1", &zone),
resource.TestCheckResourceAttr(
"openstack_dns_zone_v2.zone_1", "disable_status_check", "true"),
),
},
{
Config: testAccDNSV2ZoneBasic(zoneName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDNSV2ZoneExists("openstack_dns_zone_v2.zone_1", &zone),
resource.TestCheckResourceAttr(
"openstack_dns_zone_v2.zone_1", "disable_status_check", "false"),
),
},
},
})
}

func TestAccDNSV2Zone_readTTL(t *testing.T) {
var zone zones.Zone
var zoneName = fmt.Sprintf("ACPTTEST%s.com.", acctest.RandString(5))
Expand Down Expand Up @@ -151,3 +180,16 @@ func testAccDNSV2ZoneReadTTL(zoneName string) string {
}
`, zoneName)
}

func testAccDNSV2ZoneDisableCheck(zoneName string) string {
return fmt.Sprintf(`
resource "openstack_dns_zone_v2" "zone_1" {
name = "%s"
email = "email1@example.com"
description = "a zone"
ttl = 3000
type = "PRIMARY"
disable_status_check = true
}
`, zoneName)
}
4 changes: 4 additions & 0 deletions website/docs/r/dns_zone_v2.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ The following arguments are supported:
* `value_specs` - (Optional) Map of additional options. Changing this creates a
new zone.

* `disable_status_check` - (Optional) Disable wait for zone to reach ACTIVE
status. The check is enabled by default. If this argument is true, zone
will be considered as created/updated if OpenStack request returned success.

## Attributes Reference

The following attributes are exported:
Expand Down