Skip to content

Commit

Permalink
Merge pull request #33 from arjunrajshekhar/feature/fix-vpc-peering-i…
Browse files Browse the repository at this point in the history
…nfinite-loop

Fix VPC Peering hanging issue
  • Loading branch information
jordanbraiuka authored Jun 22, 2020
2 parents eec1ab4 + d525780 commit a26485f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BIN_NAME="terraform-provider-instaclustr"
VERSION=v1.2.0
VERSION=v1.2.1

.PHONY: install clean all build test testacc

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ resource "instaclustr_firewall_rule" "example" {
```

### Resource: `instaclustr_vpc_peering`
A resource for managing VPC peering connections on Instaclustr Managed Platform. This is only avaliable for clusters hosted with the AWS provider.
A resource for managing VPC peering connections on Instaclustr Managed Platform. This is only avaliable for clusters hosted with the AWS provider.

When creating this resource, the process will wait for target cluster to be in the `PROVISIONED` or `RUNNING` status. The process will time out after 60 seconds of waiting.

#### Properties
Property | Description | Default
Expand Down
13 changes: 11 additions & 2 deletions instaclustr/resource_vpc_peering.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,26 @@ func resourceVpcPeeringCreate(d *schema.ResourceData, meta interface{}) error {
log.Printf("[INFO] Creating VPC peering request.")
client := meta.(*Config).Client

const ClusterReadInterval = 5
const WaitForClusterTimeout = 60
var cdcID string
var latestStatus string
timePassed := 0
for {
cluster, err := client.ReadCluster(d.Get("cluster_id").(string))
if err != nil {
return fmt.Errorf("[Error] Error retrieving cluster info: %s", err)
}
if cluster.ClusterStatus == "PROVISIONED" {
latestStatus = cluster.ClusterStatus
if cluster.ClusterStatus == "PROVISIONED" || cluster.ClusterStatus == "RUNNING" {
cdcID = cluster.DataCentres[0].ID
break
}
time.Sleep(5 * time.Second)
if timePassed > WaitForClusterTimeout {
return fmt.Errorf("[Error] Timed out waiting for cluster to have the status 'PROVISIONED' or 'RUNNING'. Current cluster status is '%s'", latestStatus)
}
time.Sleep(ClusterReadInterval * time.Second)
timePassed += ClusterReadInterval
}

createData := CreateVPCPeeringRequest{
Expand Down

0 comments on commit a26485f

Please sign in to comment.