Skip to content

Commit

Permalink
fix(vpc): reverse issue (scaleway#887)
Browse files Browse the repository at this point in the history
* fix(vpc): reverse issue

* fix(vpc): add test to check reverse and address

* fix(vpc): double retry interval

Co-authored-by: scaleway-bot <[email protected]>
  • Loading branch information
Monitob and scaleway-bot authored Oct 6, 2021
1 parent 198bbf8 commit 178754e
Show file tree
Hide file tree
Showing 8 changed files with 1,290 additions and 690 deletions.
3 changes: 2 additions & 1 deletion scaleway/resource_vpc_public_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,12 @@ func resourceScalewayVPCPublicGatewayDelete(ctx context.Context, d *schema.Resou
return diag.FromErr(err)
}

retryInterval := 30 * time.Second
_, err = vpcgwAPI.WaitForGateway(&vpcgw.WaitForGatewayRequest{
GatewayID: ID,
Zone: zone,
Timeout: scw.TimeDurationPtr(gatewayWaitForTimeout),
RetryInterval: DefaultWaitRetryInterval,
RetryInterval: &retryInterval,
}, scw.WithContext(ctx))

if err != nil && !is404Error(err) {
Expand Down
24 changes: 20 additions & 4 deletions scaleway/resource_vpc_public_gateway_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ func resourceScalewayVPCPublicGatewayIP() *schema.Resource {
Type: schema.TypeString,
},
},
"project_id": projectIDSchema(),
"zone": zoneSchema(),
// Computed elements
"organization_id": organizationIDSchema(),
"reverse": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "reverse domain name for the IP address",
},
"project_id": projectIDSchema(),
"zone": zoneSchema(),
// Computed elements
"organization_id": organizationIDSchema(),
"created_at": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -74,6 +75,20 @@ func resourceScalewayVPCPublicGatewayIPCreate(ctx context.Context, d *schema.Res
return diag.FromErr(err)
}

reverse := d.Get("reverse")
if len(reverse.(string)) > 0 {
updateRequest := &vpcgw.UpdateIPRequest{
IPID: res.ID,
Zone: zone,
Tags: scw.StringsPtr(expandStrings(d.Get("tags"))),
Reverse: expandStringPtr(reverse.(string)),
}
_, err = vpcgwAPI.UpdateIP(updateRequest, scw.WithContext(ctx))
if err != nil {
return diag.FromErr(err)
}
}

d.SetId(newZonedIDString(zone, res.ID))

return resourceScalewayVPCPublicGatewayIPRead(ctx, d, meta)
Expand All @@ -98,6 +113,7 @@ func resourceScalewayVPCPublicGatewayIPRead(ctx context.Context, d *schema.Resou
}

_ = d.Set("organization_id", ip.OrganizationID)
_ = d.Set("address", ip.Address.String())
_ = d.Set("project_id", ip.ProjectID)
_ = d.Set("created_at", ip.CreatedAt.Format(time.RFC3339))
_ = d.Set("updated_at", ip.UpdatedAt.Format(time.RFC3339))
Expand Down
23 changes: 23 additions & 0 deletions scaleway/resource_vpc_public_gateway_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func TestAccScalewayVPCPublicGatewayIP_Basic(t *testing.T) {
`,
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewayVPCPublicGatewayIPExists(tt, "scaleway_vpc_public_gateway_ip.main"),
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_ip.main", "reverse"),
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_ip.main", "address"),
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_ip.main", "created_at"),
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_ip.main", "updated_at"),
),
},
{
Expand All @@ -72,6 +76,25 @@ func TestAccScalewayVPCPublicGatewayIP_Basic(t *testing.T) {
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway_ip.main", "tags.0", "tag0"),
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway_ip.main", "tags.1", "tag1"),
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway_ip.main", "reverse", "example.com"),
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_ip.main", "address"),
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_ip.main", "created_at"),
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_ip.main", "updated_at"),
),
},
{
Config: `
resource scaleway_vpc_public_gateway_ip main {
tags = ["tag2", "tag3"]
}
`,
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewayVPCPublicGatewayIPExists(tt, "scaleway_vpc_public_gateway_ip.main"),
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway_ip.main", "tags.0", "tag2"),
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway_ip.main", "tags.1", "tag3"),
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_ip.main", "reverse"),
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_ip.main", "address"),
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_ip.main", "created_at"),
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_ip.main", "updated_at"),
),
},
},
Expand Down
936 changes: 648 additions & 288 deletions scaleway/testdata/data-source-baremetal-offer-basic.cassette.yaml

Large diffs are not rendered by default.

331 changes: 179 additions & 152 deletions scaleway/testdata/data-source-vpc-public-gateway-basic.cassette.yaml

Large diffs are not rendered by default.

168 changes: 91 additions & 77 deletions scaleway/testdata/vpc-public-gateway-attach-to-ip.cassette.yaml

Large diffs are not rendered by default.

191 changes: 86 additions & 105 deletions scaleway/testdata/vpc-public-gateway-basic.cassette.yaml

Large diffs are not rendered by default.

Loading

0 comments on commit 178754e

Please sign in to comment.