Skip to content

Commit

Permalink
Add interconnect attachment state waiting (#2999)
Browse files Browse the repository at this point in the history
Merged PR #2999.
  • Loading branch information
rileykarson authored and modular-magician committed Jan 21, 2020
1 parent 29617d8 commit 4e9cbb2
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
2 changes: 1 addition & 1 deletion build/terraform-mapper
3 changes: 3 additions & 0 deletions products/compute/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6602,6 +6602,9 @@ objects:
path: 'name'
base_url: 'projects/{{project}}/regions/{{region}}/operations/{{op_id}}'
wait_ms: 1000
timeouts: !ruby/object:Api::Timeouts
insert_minutes: 10
delete_minutes: 10
result: !ruby/object:Api::OpAsync::Result
path: 'targetLink'
status: !ruby/object:Api::OpAsync::Status
Expand Down
20 changes: 12 additions & 8 deletions products/compute/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,14 @@ overrides: !ruby/object:Overrides::ResourceOverrides
InstanceTemplate: !ruby/object:Overrides::Terraform::ResourceOverride
exclude: true
InterconnectAttachment: !ruby/object:Overrides::Terraform::ResourceOverride
examples:
- !ruby/object:Provider::Terraform::Examples
name: "interconnect_attachment_basic"
primary_resource_id: "on_prem"
skip_test: true
vars:
interconnect_attachment_name: "on-prem-attachment"
router_name: "router"
properties:
id: !ruby/object:Overrides::Terraform::PropertyOverride
exclude: true
Expand All @@ -939,14 +947,10 @@ overrides: !ruby/object:Overrides::ResourceOverrides
default_from_api: true
vlanTag8021q: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
examples:
- !ruby/object:Provider::Terraform::Examples
name: "interconnect_attachment_basic"
primary_resource_id: "on_prem"
skip_test: true
vars:
interconnect_attachment_name: "on-prem-attachment"
router_name: "router"
custom_code: !ruby/object:Provider::Terraform::CustomCode
constants: templates/terraform/constants/interconnect_attachment.go.erb
post_create: templates/terraform/post_create/interconnect_attachment.go.erb
pre_delete: templates/terraform/pre_delete/interconnect_attachment.go.erb
License: !ruby/object:Overrides::Terraform::ResourceOverride
exclude: true
MachineType: !ruby/object:Overrides::Terraform::ResourceOverride
Expand Down
18 changes: 18 additions & 0 deletions templates/terraform/constants/interconnect_attachment.go.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
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)
}
3 changes: 3 additions & 0 deletions templates/terraform/pre_delete/interconnect_attachment.go.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
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)
}

0 comments on commit 4e9cbb2

Please sign in to comment.