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

Add interconnect attachment state waiting #5459

Merged
merged 1 commit into from
Jan 21, 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
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