Skip to content

Commit

Permalink
Add interconnect attachment state waiting (#5459)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>

Co-authored-by: Riley Karson <[email protected]>
  • Loading branch information
modular-magician and rileykarson committed Jan 21, 2020
1 parent 9861323 commit 6f86730
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 123 deletions.
31 changes: 29 additions & 2 deletions google/resource_compute_interconnect_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,30 @@ import (
"strconv"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
)

// waitForAttachmentToBeProvisioned waits for an attachment to leave the
// "UNPROVISIONED" state, to indicate that it's either ready or awaiting partner
// activity.
func waitForAttachmentToBeProvisioned(d *schema.ResourceData, config *Config, timeout time.Duration) error {
return resource.Retry(timeout, func() *resource.RetryError {
if err := resourceComputeInterconnectAttachmentRead(d, config); err != nil {
return resource.NonRetryableError(err)
}

name := d.Get("name").(string)
state := d.Get("state").(string)
if state == "UNPROVISIONED" {
return resource.RetryableError(fmt.Errorf("InterconnectAttachment %q has state %q.", name, state))
}
log.Printf("InterconnectAttachment %q has state %q.", name, state)
return nil
})
}

func resourceComputeInterconnectAttachment() *schema.Resource {
return &schema.Resource{
Create: resourceComputeInterconnectAttachmentCreate,
Expand All @@ -36,8 +56,8 @@ func resourceComputeInterconnectAttachment() *schema.Resource {
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(4 * time.Minute),
Delete: schema.DefaultTimeout(4 * time.Minute),
Create: schema.DefaultTimeout(10 * time.Minute),
Delete: schema.DefaultTimeout(10 * time.Minute),
},

Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -326,6 +346,10 @@ func resourceComputeInterconnectAttachmentCreate(d *schema.ResourceData, meta in

log.Printf("[DEBUG] Finished creating InterconnectAttachment %q: %#v", d.Id(), res)

if err := waitForAttachmentToBeProvisioned(d, config, d.Timeout(schema.TimeoutCreate)); err != nil {
return fmt.Errorf("Error waiting for InterconnectAttachment %q to be provisioned: %q", d.Get("name").(string), err)
}

return resourceComputeInterconnectAttachmentRead(d, meta)
}

Expand Down Expand Up @@ -428,6 +452,9 @@ func resourceComputeInterconnectAttachmentDelete(d *schema.ResourceData, meta in
}

var obj map[string]interface{}
if err := waitForAttachmentToBeProvisioned(d, config, d.Timeout(schema.TimeoutCreate)); err != nil {
return fmt.Errorf("Error waiting for InterconnectAttachment %q to be provisioned: %q", d.Get("name").(string), err)
}
log.Printf("[DEBUG] Deleting InterconnectAttachment %q", d.Id())

res, err := sendRequestWithTimeout(config, "DELETE", project, url, obj, d.Timeout(schema.TimeoutDelete))
Expand Down
119 changes: 0 additions & 119 deletions google/resource_compute_interconnect_attachment_sweeper_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions website/docs/r/compute_interconnect_attachment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ The `private_interconnect_info` block contains:
This resource provides the following
[Timeouts](/docs/configuration/resources.html#timeouts) configuration options:

- `create` - Default is 4 minutes.
- `delete` - Default is 4 minutes.
- `create` - Default is 10 minutes.
- `delete` - Default is 10 minutes.

## Import

Expand Down

0 comments on commit 6f86730

Please sign in to comment.