@@ -84,9 +84,22 @@ func resourceScalewayVPCPublicGatewayPATRuleCreate(ctx context.Context, d *schem
84
84
return diag .FromErr (err )
85
85
}
86
86
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
+
87
100
req := & vpcgw.CreatePATRuleRequest {
88
101
Zone : zone ,
89
- GatewayID : expandZonedID ( d . Get ( "gateway_id" ).( string )). ID ,
102
+ GatewayID : gatewayID ,
90
103
PublicPort : uint32 (d .Get ("public_port" ).(int )),
91
104
PrivateIP : net .ParseIP (d .Get ("private_ip" ).(string )),
92
105
PrivatePort : uint32 (d .Get ("private_port" ).(int )),
@@ -121,9 +134,10 @@ func resourceScalewayVPCPublicGatewayPATRuleRead(ctx context.Context, d *schema.
121
134
return diag .FromErr (err )
122
135
}
123
136
137
+ gatewayID := newZonedID (zone , patRules .GatewayID ).String ()
124
138
_ = d .Set ("created_at" , patRules .CreatedAt .Format (time .RFC3339 ))
125
139
_ = d .Set ("updated_at" , patRules .UpdatedAt .Format (time .RFC3339 ))
126
- _ = d .Set ("gateway_id" , patRules . GatewayID )
140
+ _ = d .Set ("gateway_id" , gatewayID )
127
141
_ = d .Set ("private_ip" , patRules .PrivateIP .String ())
128
142
_ = d .Set ("private_port" , patRules .PrivatePort )
129
143
_ = d .Set ("public_port" , patRules .PublicPort )
@@ -151,14 +165,15 @@ func resourceScalewayVPCPublicGatewayPATRuleUpdate(ctx context.Context, d *schem
151
165
PrivatePort : & privatePort ,
152
166
Protocol : vpcgw .PATRuleProtocol (d .Get ("protocol" ).(string )),
153
167
}, scw .WithContext (ctx ))
168
+
154
169
if err != nil {
155
170
if is404Error (err ) {
156
171
d .SetId ("" )
157
172
return nil
158
173
}
159
174
return diag .FromErr (err )
160
175
}
161
- }
176
+ }
162
177
163
178
return resourceScalewayVPCPublicGatewayPATRuleRead (ctx , d , meta )
164
179
}
0 commit comments