Skip to content

Commit 178754e

Browse files
fix(vpc): reverse issue (scaleway#887)
* 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]>
1 parent 198bbf8 commit 178754e

8 files changed

Lines changed: 1290 additions & 690 deletions

scaleway/resource_vpc_public_gateway.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,12 @@ func resourceScalewayVPCPublicGatewayDelete(ctx context.Context, d *schema.Resou
183183
return diag.FromErr(err)
184184
}
185185

186+
retryInterval := 30 * time.Second
186187
_, err = vpcgwAPI.WaitForGateway(&vpcgw.WaitForGatewayRequest{
187188
GatewayID: ID,
188189
Zone: zone,
189190
Timeout: scw.TimeDurationPtr(gatewayWaitForTimeout),
190-
RetryInterval: DefaultWaitRetryInterval,
191+
RetryInterval: &retryInterval,
191192
}, scw.WithContext(ctx))
192193

193194
if err != nil && !is404Error(err) {

scaleway/resource_vpc_public_gateway_ip.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@ func resourceScalewayVPCPublicGatewayIP() *schema.Resource {
3434
Type: schema.TypeString,
3535
},
3636
},
37+
"project_id": projectIDSchema(),
38+
"zone": zoneSchema(),
39+
// Computed elements
40+
"organization_id": organizationIDSchema(),
3741
"reverse": {
3842
Type: schema.TypeString,
3943
Optional: true,
44+
Computed: true,
4045
Description: "reverse domain name for the IP address",
4146
},
42-
"project_id": projectIDSchema(),
43-
"zone": zoneSchema(),
44-
// Computed elements
45-
"organization_id": organizationIDSchema(),
4647
"created_at": {
4748
Type: schema.TypeString,
4849
Computed: true,
@@ -74,6 +75,20 @@ func resourceScalewayVPCPublicGatewayIPCreate(ctx context.Context, d *schema.Res
7475
return diag.FromErr(err)
7576
}
7677

78+
reverse := d.Get("reverse")
79+
if len(reverse.(string)) > 0 {
80+
updateRequest := &vpcgw.UpdateIPRequest{
81+
IPID: res.ID,
82+
Zone: zone,
83+
Tags: scw.StringsPtr(expandStrings(d.Get("tags"))),
84+
Reverse: expandStringPtr(reverse.(string)),
85+
}
86+
_, err = vpcgwAPI.UpdateIP(updateRequest, scw.WithContext(ctx))
87+
if err != nil {
88+
return diag.FromErr(err)
89+
}
90+
}
91+
7792
d.SetId(newZonedIDString(zone, res.ID))
7893

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

100115
_ = d.Set("organization_id", ip.OrganizationID)
116+
_ = d.Set("address", ip.Address.String())
101117
_ = d.Set("project_id", ip.ProjectID)
102118
_ = d.Set("created_at", ip.CreatedAt.Format(time.RFC3339))
103119
_ = d.Set("updated_at", ip.UpdatedAt.Format(time.RFC3339))

scaleway/resource_vpc_public_gateway_ip_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ func TestAccScalewayVPCPublicGatewayIP_Basic(t *testing.T) {
5858
`,
5959
Check: resource.ComposeTestCheckFunc(
6060
testAccCheckScalewayVPCPublicGatewayIPExists(tt, "scaleway_vpc_public_gateway_ip.main"),
61+
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_ip.main", "reverse"),
62+
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_ip.main", "address"),
63+
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_ip.main", "created_at"),
64+
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_ip.main", "updated_at"),
6165
),
6266
},
6367
{
@@ -72,6 +76,25 @@ func TestAccScalewayVPCPublicGatewayIP_Basic(t *testing.T) {
7276
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway_ip.main", "tags.0", "tag0"),
7377
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway_ip.main", "tags.1", "tag1"),
7478
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway_ip.main", "reverse", "example.com"),
79+
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_ip.main", "address"),
80+
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_ip.main", "created_at"),
81+
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_ip.main", "updated_at"),
82+
),
83+
},
84+
{
85+
Config: `
86+
resource scaleway_vpc_public_gateway_ip main {
87+
tags = ["tag2", "tag3"]
88+
}
89+
`,
90+
Check: resource.ComposeTestCheckFunc(
91+
testAccCheckScalewayVPCPublicGatewayIPExists(tt, "scaleway_vpc_public_gateway_ip.main"),
92+
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway_ip.main", "tags.0", "tag2"),
93+
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway_ip.main", "tags.1", "tag3"),
94+
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_ip.main", "reverse"),
95+
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_ip.main", "address"),
96+
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_ip.main", "created_at"),
97+
resource.TestCheckResourceAttrSet("scaleway_vpc_public_gateway_ip.main", "updated_at"),
7598
),
7699
},
77100
},

scaleway/testdata/data-source-baremetal-offer-basic.cassette.yaml

Lines changed: 648 additions & 288 deletions
Large diffs are not rendered by default.

scaleway/testdata/data-source-vpc-public-gateway-basic.cassette.yaml

Lines changed: 179 additions & 152 deletions
Large diffs are not rendered by default.

scaleway/testdata/vpc-public-gateway-attach-to-ip.cassette.yaml

Lines changed: 91 additions & 77 deletions
Large diffs are not rendered by default.

scaleway/testdata/vpc-public-gateway-basic.cassette.yaml

Lines changed: 86 additions & 105 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)