@@ -48,20 +48,27 @@ type vpcFirewallRulesResourceModel struct {
48
48
Rules []vpcFirewallRulesResourceRuleModel `tfsdk:"rules"`
49
49
Timeouts timeouts.Value `tfsdk:"timeouts"`
50
50
VPCID types.String `tfsdk:"vpc_id"`
51
+
52
+ // Populated from the same fields within [vpcFirewallRulesResourceRuleModel].
53
+ TimeCreated types.String `tfsdk:"time_created"`
54
+ TimeModified types.String `tfsdk:"time_modified"`
51
55
}
52
56
53
57
type vpcFirewallRulesResourceRuleModel struct {
54
- Action types.String `tfsdk:"action"`
55
- Description types.String `tfsdk:"description"`
56
- Direction types.String `tfsdk:"direction"`
57
- Filters * vpcFirewallRulesResourceRuleFiltersModel `tfsdk:"filters"`
58
- ID types.String `tfsdk:"id"`
59
- Name types.String `tfsdk:"name"`
60
- Priority types.Int64 `tfsdk:"priority"`
61
- Status types.String `tfsdk:"status"`
62
- Targets []vpcFirewallRulesResourceRuleTargetModel `tfsdk:"targets"`
63
- TimeCreated types.String `tfsdk:"time_created"`
64
- TimeModified types.String `tfsdk:"time_modified"`
58
+ Action types.String `tfsdk:"action"`
59
+ Description types.String `tfsdk:"description"`
60
+ Direction types.String `tfsdk:"direction"`
61
+ Filters * vpcFirewallRulesResourceRuleFiltersModel `tfsdk:"filters"`
62
+ Name types.String `tfsdk:"name"`
63
+ Priority types.Int64 `tfsdk:"priority"`
64
+ Status types.String `tfsdk:"status"`
65
+ Targets []vpcFirewallRulesResourceRuleTargetModel `tfsdk:"targets"`
66
+
67
+ // Used to retrieve the timestamps from the API and populate the same fields
68
+ // within [vpcFirewallRulesResourceModel]. The `tfsdk:"-"` struct field tag is used
69
+ // to tell Terraform not to populate these values in the schema.
70
+ TimeCreated types.String `tfsdk:"-"`
71
+ TimeModified types.String `tfsdk:"-"`
65
72
}
66
73
67
74
type vpcFirewallRulesResourceRuleTargetModel struct {
@@ -110,6 +117,10 @@ func (r *vpcFirewallRulesResource) Schema(ctx context.Context, _ resource.Schema
110
117
stringplanmodifier .RequiresReplace (),
111
118
},
112
119
},
120
+ // The rules attribute cannot contain computed attributes since the upstream API
121
+ // returns updated attributes for every rule, irrespective of which rules actually
122
+ // change. See https://github.com/oxidecomputer/terraform-provider-oxide/issues/453
123
+ // for more information.
113
124
"rules" : schema.SetNestedAttribute {
114
125
Required : true ,
115
126
Description : "Associated firewall rules." ,
@@ -202,10 +213,6 @@ func (r *vpcFirewallRulesResource) Schema(ctx context.Context, _ resource.Schema
202
213
},
203
214
},
204
215
},
205
- "id" : schema.StringAttribute {
206
- Computed : true ,
207
- Description : "Unique, immutable, system-controlled identifier of the firewall rule." ,
208
- },
209
216
"name" : schema.StringAttribute {
210
217
Required : true ,
211
218
Description : "Name of the VPC firewall rule." ,
@@ -255,14 +262,6 @@ func (r *vpcFirewallRulesResource) Schema(ctx context.Context, _ resource.Schema
255
262
},
256
263
},
257
264
},
258
- "time_created" : schema.StringAttribute {
259
- Computed : true ,
260
- Description : "Timestamp of when this VPC firewall rule was created." ,
261
- },
262
- "time_modified" : schema.StringAttribute {
263
- Computed : true ,
264
- Description : "Timestamp of when this VPC firewall rule was last modified." ,
265
- },
266
265
},
267
266
},
268
267
},
@@ -276,6 +275,14 @@ func (r *vpcFirewallRulesResource) Schema(ctx context.Context, _ resource.Schema
276
275
Computed : true ,
277
276
Description : "Unique, immutable, system-controlled identifier of the firewall rules. Specific only to Terraform." ,
278
277
},
278
+ "time_created" : schema.StringAttribute {
279
+ Computed : true ,
280
+ Description : "Timestamp of when the VPC firewall rules were last created." ,
281
+ },
282
+ "time_modified" : schema.StringAttribute {
283
+ Computed : true ,
284
+ Description : "Timestamp of when the VPC firewall rules were last modified." ,
285
+ },
279
286
},
280
287
}
281
288
}
@@ -327,6 +334,13 @@ func (r *vpcFirewallRulesResource) Create(ctx context.Context, req resource.Crea
327
334
return
328
335
}
329
336
337
+ plan .TimeCreated = types .StringNull ()
338
+ plan .TimeModified = types .StringNull ()
339
+ if len (plan .Rules ) > 0 {
340
+ plan .TimeCreated = plan .Rules [0 ].TimeCreated
341
+ plan .TimeModified = plan .Rules [0 ].TimeModified
342
+ }
343
+
330
344
// Save plan into Terraform state
331
345
resp .Diagnostics .Append (resp .State .Set (ctx , & plan )... )
332
346
if resp .Diagnostics .HasError () {
@@ -384,6 +398,13 @@ func (r *vpcFirewallRulesResource) Read(ctx context.Context, req resource.ReadRe
384
398
385
399
state .Rules = rules
386
400
401
+ state .TimeCreated = types .StringNull ()
402
+ state .TimeModified = types .StringNull ()
403
+ if len (state .Rules ) > 0 {
404
+ state .TimeCreated = state .Rules [0 ].TimeCreated
405
+ state .TimeModified = state .Rules [0 ].TimeModified
406
+ }
407
+
387
408
// Save updated data into Terraform state
388
409
resp .Diagnostics .Append (resp .State .Set (ctx , & state )... )
389
410
if resp .Diagnostics .HasError () {
@@ -447,6 +468,13 @@ func (r *vpcFirewallRulesResource) Update(ctx context.Context, req resource.Upda
447
468
return
448
469
}
449
470
471
+ plan .TimeCreated = types .StringNull ()
472
+ plan .TimeModified = types .StringNull ()
473
+ if len (plan .Rules ) > 0 {
474
+ plan .TimeCreated = plan .Rules [0 ].TimeCreated
475
+ plan .TimeModified = plan .Rules [0 ].TimeModified
476
+ }
477
+
450
478
// Save plan into Terraform state
451
479
resp .Diagnostics .Append (resp .State .Set (ctx , & plan )... )
452
480
if resp .Diagnostics .HasError () {
@@ -536,7 +564,6 @@ func newVPCFirewallRulesModel(rules []oxide.VpcFirewallRule) ([]vpcFirewallRules
536
564
Action : types .StringValue (string (rule .Action )),
537
565
Description : types .StringValue (rule .Description ),
538
566
Direction : types .StringValue (string (rule .Direction )),
539
- ID : types .StringValue (rule .Id ),
540
567
Name : types .StringValue (string (rule .Name )),
541
568
// We can safely dereference rule.Priority as it's a required field
542
569
Priority : types .Int64Value (int64 (* rule .Priority )),
0 commit comments