Skip to content

Commit

Permalink
DNS Zone: requiring imports/timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff committed Aug 14, 2018
1 parent 50b52a0 commit 85c99df
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions azurerm/resource_arm_dns_zone.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package azurerm

import (
"context"
"fmt"
"time"

"github.com/Azure/azure-sdk-for-go/services/preview/dns/mgmt/2018-03-01-preview/dns"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

Expand All @@ -19,6 +22,11 @@ func resourceArmDnsZone() *schema.Resource {
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(time.Minute * 30),
Update: schema.DefaultTimeout(time.Minute * 30),
Delete: schema.DefaultTimeout(time.Minute * 30),
},

Schema: map[string]*schema.Schema{
"name": {
Expand Down Expand Up @@ -79,6 +87,21 @@ func resourceArmDnsZoneCreateUpdate(d *schema.ResourceData, meta interface{}) er

name := d.Get("name").(string)
resGroup := d.Get("resource_group_name").(string)

if d.IsNewResource() {
// first check if there's one in this subscription requiring import
resp, err := client.Get(ctx, resGroup, name)
if err != nil {
if !utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Error checking for the existence of DNS Zone %q (Resource Group %q): %+v", name, resGroup, err)
}
}

if resp.ID != nil {
return tf.ImportAsExistsError("azurerm_dns_zone", *resp.ID)
}
}

location := "global"
zoneType := d.Get("zone_type").(string)
tags := d.Get("tags").(map[string]interface{})
Expand All @@ -98,7 +121,9 @@ func resourceArmDnsZoneCreateUpdate(d *schema.ResourceData, meta interface{}) er

etag := ""
ifNoneMatch := "" // set to empty to allow updates to records after creation
resp, err := client.CreateOrUpdate(ctx, resGroup, name, parameters, etag, ifNoneMatch)
waitCtx, cancel := context.WithTimeout(ctx, d.Timeout(tf.TimeoutForCreateUpdate(d)))
defer cancel()
resp, err := client.CreateOrUpdate(waitCtx, resGroup, name, parameters, etag, ifNoneMatch)
if err != nil {
return err
}
Expand Down Expand Up @@ -180,7 +205,9 @@ func resourceArmDnsZoneDelete(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Error deleting DNS zone %s (resource group %s): %+v", name, resGroup, err)
}

err = future.WaitForCompletionRef(ctx, client.Client)
waitCtx, cancel := context.WithTimeout(ctx, d.Timeout(schema.TimeoutDelete))
defer cancel()
err = future.WaitForCompletionRef(waitCtx, client.Client)
if err != nil {
if response.WasNotFound(future.Response()) {
return nil
Expand Down

0 comments on commit 85c99df

Please sign in to comment.