Skip to content

Commit 915f877

Browse files
committed
feat(pat-rules): add new test and gateway_network
1 parent eadce3a commit 915f877

5 files changed

+442
-297
lines changed

scaleway/data_source_vpc_public_gateway.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func dataSourceScalewayVPCPublicGatewayRead(ctx context.Context, d *schema.Resou
3838
return diag.FromErr(err)
3939
}
4040

41-
publicGatewayID, ok := d.GetOk("public_gateway_id")
41+
publicGatewayID, ok := d.GetOk("public_gateway_id")
4242
if !ok {
4343
res, err := vpcgwAPI.ListGateways(
4444
&vpcgw.ListGatewaysRequest{

scaleway/resource_vpc_public_gateway_pat_rule.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,22 @@ func resourceScalewayVPCPublicGatewayPATRuleCreate(ctx context.Context, d *schem
8484
return diag.FromErr(err)
8585
}
8686

87+
gatewayID := expandZonedID(d.Get("gateway_id").(string)).ID
88+
retryInterval := retryIntervalVPCPublicGatewayNetwork
89+
//check gateway is in stable state.
90+
_, err = vpcgwAPI.WaitForGateway(&vpcgw.WaitForGatewayRequest{
91+
GatewayID: gatewayID,
92+
Zone: zone,
93+
Timeout: scw.TimeDurationPtr(gatewayWaitForTimeout),
94+
RetryInterval: &retryInterval,
95+
}, scw.WithContext(ctx))
96+
if err != nil {
97+
return diag.FromErr(err)
98+
}
99+
87100
req := &vpcgw.CreatePATRuleRequest{
88101
Zone: zone,
89-
GatewayID: expandZonedID(d.Get("gateway_id").(string)).ID,
102+
GatewayID: gatewayID,
90103
PublicPort: uint32(d.Get("public_port").(int)),
91104
PrivateIP: net.ParseIP(d.Get("private_ip").(string)),
92105
PrivatePort: uint32(d.Get("private_port").(int)),
@@ -121,9 +134,10 @@ func resourceScalewayVPCPublicGatewayPATRuleRead(ctx context.Context, d *schema.
121134
return diag.FromErr(err)
122135
}
123136

137+
gatewayID := newZonedID(zone, patRules.GatewayID).String()
124138
_ = d.Set("created_at", patRules.CreatedAt.Format(time.RFC3339))
125139
_ = d.Set("updated_at", patRules.UpdatedAt.Format(time.RFC3339))
126-
_ = d.Set("gateway_id", patRules.GatewayID)
140+
_ = d.Set("gateway_id", gatewayID)
127141
_ = d.Set("private_ip", patRules.PrivateIP.String())
128142
_ = d.Set("private_port", patRules.PrivatePort)
129143
_ = d.Set("public_port", patRules.PublicPort)
@@ -151,14 +165,15 @@ func resourceScalewayVPCPublicGatewayPATRuleUpdate(ctx context.Context, d *schem
151165
PrivatePort: &privatePort,
152166
Protocol: vpcgw.PATRuleProtocol(d.Get("protocol").(string)),
153167
}, scw.WithContext(ctx))
168+
154169
if err != nil {
155170
if is404Error(err) {
156171
d.SetId("")
157172
return nil
158173
}
159174
return diag.FromErr(err)
160175
}
161-
}
176+
}
162177

163178
return resourceScalewayVPCPublicGatewayPATRuleRead(ctx, d, meta)
164179
}

scaleway/resource_vpc_public_gateway_pat_rule_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func TestAccScalewayVPCPublicGatewayPATRule_Basic(t *testing.T) {
4343
gateway_id = scaleway_vpc_public_gateway.pg01.id
4444
private_network_id = scaleway_vpc_private_network.pn01.id
4545
dhcp_id = scaleway_vpc_public_gateway_dhcp.dhcp01.id
46+
depends_on = [scaleway_vpc_private_network.pn01]
4647
}
4748
4849
resource scaleway_vpc_public_gateway_pat_rule main {
@@ -51,7 +52,7 @@ func TestAccScalewayVPCPublicGatewayPATRule_Basic(t *testing.T) {
5152
private_port = 42
5253
public_port = 42
5354
protocol = "both"
54-
depends_on = [scaleway_vpc_gateway_network.gn01]
55+
depends_on = [scaleway_vpc_gateway_network.gn01, scaleway_vpc_private_network.pn01]
5556
}
5657
`,
5758
Check: resource.ComposeTestCheckFunc(

0 commit comments

Comments
 (0)