@@ -83,7 +83,7 @@ func (r *pcuGroupResource) Schema(_ context.Context, _ resource.SchemaRequest, r
8383 PcuAttrCacheType : schema.StringAttribute {
8484 Optional : true ,
8585 Computed : true ,
86- Default : stringdefault .StaticString (string (astra .InstanceTypeStandard )), // TODO do we validate the enum? Or let any string go?
86+ Default : stringdefault .StaticString (string (astra .PcuInstanceTypeStandard )), // TODO do we validate the enum? Or let any string go?
8787 PlanModifiers : []planmodifier.String {
8888 stringplanmodifier .UseStateForUnknown (),
8989 stringplanmodifier .RequiresReplace (),
@@ -92,7 +92,7 @@ func (r *pcuGroupResource) Schema(_ context.Context, _ resource.SchemaRequest, r
9292 PcuAttrProvisionType : schema.StringAttribute {
9393 Optional : true ,
9494 Computed : true ,
95- Default : stringdefault .StaticString (string (astra .Shared )), // TODO do we validate the enum? Or let any string go?
95+ Default : stringdefault .StaticString (string (astra .PcuProvisionTypeShared )), // TODO do we validate the enum? Or let any string go?
9696 PlanModifiers : []planmodifier.String {
9797 stringplanmodifier .UseStateForUnknown (),
9898 stringplanmodifier .RequiresReplace (),
@@ -136,7 +136,7 @@ func (r *pcuGroupResource) Schema(_ context.Context, _ resource.SchemaRequest, r
136136 PcuAttrStatus : schema.StringAttribute {
137137 Computed : true ,
138138 PlanModifiers : []planmodifier.String {
139- mkPcuStatusOnlyActiveOrParkedPlanModifier (),
139+ inferPcuGroupStatusPlanModifier (),
140140 },
141141 },
142142 "park" : schema.BoolAttribute { // This should technically be a WriteOnly param but that requires TF 1.12+
@@ -148,7 +148,7 @@ func (r *pcuGroupResource) Schema(_ context.Context, _ resource.SchemaRequest, r
148148 },
149149 },
150150 },
151- MkPcuResourceCreatedUpdatedAttributes (mkPcuUpdateFieldsOnlyUnknownWhenChangesOccurPlanModifier ()),
151+ MkPcuResourceCreatedUpdatedAttributes (mkPcuUpdateFieldsKnownIfNoChangesOccurPlanModifier ()),
152152 MkPcuResourceProtectionAttribute ("deletion" ),
153153 MkPcuResourceProtectionAttribute ("rcu" ),
154154 ),
@@ -175,9 +175,11 @@ func (r *pcuGroupResource) Create(ctx context.Context, req resource.CreateReques
175175 }
176176 }
177177
178- plan .updateGroupModel (created )
179-
180- res .Diagnostics .Append (res .State .Set (ctx , & plan )... )
178+ res .Diagnostics .Append (res .State .Set (ctx , mkPcuGroupResourceModel (
179+ * created ,
180+ plan .DeletionProtection ,
181+ plan .RCUProtection ,
182+ ))... )
181183}
182184
183185func (r * pcuGroupResource ) Read (ctx context.Context , req resource.ReadRequest , res * resource.ReadResponse ) {
@@ -198,12 +200,11 @@ func (r *pcuGroupResource) Read(ctx context.Context, req resource.ReadRequest, r
198200 return
199201 }
200202
201- state .updateGroupModel (group )
202-
203- state .DeletionProtection = ElvisTF (& state .DeletionProtection , types .BoolValue (true ))
204- state .RCUProtection = ElvisTF (& state .RCUProtection , types .BoolValue (true ))
205-
206- res .Diagnostics .Append (res .State .Set (ctx , & state )... )
203+ res .Diagnostics .Append (res .State .Set (ctx , mkPcuGroupResourceModel (
204+ * group ,
205+ state .DeletionProtection ,
206+ state .RCUProtection ,
207+ ))... )
207208}
208209
209210func (r * pcuGroupResource ) Update (ctx context.Context , req resource.UpdateRequest , res * resource.UpdateResponse ) {
@@ -221,11 +222,11 @@ func (r *pcuGroupResource) Update(ctx context.Context, req resource.UpdateReques
221222 return
222223 }
223224
224- updated := & plan .PcuGroupModel
225+ updated := & state .PcuGroupModel
225226 diags := diag.Diagnostics {}
226227
227228 if shouldUpdatePcuGroup (state , plan ) {
228- updated , diags = r .groups .Update (ctx , plan .PcuGroupSpecModel )
229+ updated , diags = r .groups .Update (ctx , plan .Id , plan . PcuGroupSpecModel )
229230
230231 if res .Diagnostics .Append (diags ... ); res .Diagnostics .HasError () {
231232 return
@@ -244,9 +245,11 @@ func (r *pcuGroupResource) Update(ctx context.Context, req resource.UpdateReques
244245 }
245246 }
246247
247- plan .updateGroupModel (updated )
248-
249- res .Diagnostics .Append (res .State .Set (ctx , plan )... )
248+ res .Diagnostics .Append (res .State .Set (ctx , mkPcuGroupResourceModel (
249+ * updated ,
250+ plan .DeletionProtection ,
251+ plan .RCUProtection ,
252+ ))... )
250253}
251254
252255func (r * pcuGroupResource ) Delete (ctx context.Context , req resource.DeleteRequest , res * resource.DeleteResponse ) {
@@ -270,31 +273,29 @@ func (r *pcuGroupResource) ImportState(ctx context.Context, req resource.ImportS
270273 resource .ImportStatePassthroughID (ctx , path .Root ("id" ), req , res )
271274}
272275
273- func mkPcuStatusOnlyActiveOrParkedPlanModifier () planmodifier.String {
276+ func inferPcuGroupStatusPlanModifier () planmodifier.String {
274277 return MkStringPlanModifier (
275278 "The status will always be 'ACTIVE' or 'PARKED', given no major errors occurred during provisioning/unprovisioning." ,
276279 func (ctx context.Context , req planmodifier.StringRequest , res * planmodifier.StringResponse ) {
277- //var data *pcuGroupResourceModel
278- //
279- //diags := req.Plan.Get(ctx, &data)
280- //if res.Diagnostics.Append(diags...); res.Diagnostics.HasError() {
281- // return
282- //}
283- //
284- //if data == nil {
285- // return
286- //}
287- //
288- //if data.Parked.ValueBool() {
289- // res.PlanValue = types.StringValue(string(astra.PCUGroupStatusPARKED))
290- //} else {
291- // res.PlanValue = types.StringValue(string(astra.PCUGroupStatusACTIVE))
292- //}
280+ var curr , plan * pcuGroupResourceModel
281+
282+ res .Diagnostics .Append (req .State .Get (ctx , & curr )... )
283+ res .Diagnostics .Append (req .Plan .Get (ctx , & plan )... )
284+
285+ if res .Diagnostics .HasError () {
286+ return
287+ }
288+
289+ if curr != nil && ! shouldUpdatePcuGroup (* curr , * plan ) {
290+ res .PlanValue = req .StateValue
291+ } else if plan .Parked .ValueBool () {
292+ res .PlanValue = types .StringValue (string (astra .PCUGroupStatusPARKED ))
293+ }
293294 },
294295 )
295296}
296297
297- func mkPcuUpdateFieldsOnlyUnknownWhenChangesOccurPlanModifier () planmodifier.String {
298+ func mkPcuUpdateFieldsKnownIfNoChangesOccurPlanModifier () planmodifier.String {
298299 return MkStringPlanModifier (
299300 "The updated_[by|at] fields only change when properties of the PCU do." ,
300301 func (ctx context.Context , req planmodifier.StringRequest , res * planmodifier.StringResponse ) {
@@ -322,7 +323,11 @@ func shouldUpdatePcuGroup(curr, plan pcuGroupResourceModel) bool {
322323 ! curr .Description .Equal (plan .Description )
323324}
324325
325- func (model * pcuGroupResourceModel ) updateGroupModel (group * PcuGroupModel ) {
326- model .PcuGroupModel = * group
327- model .Parked = types .BoolValue (group .Status .ValueString () == string (astra .PCUGroupStatusPARKED ))
326+ func mkPcuGroupResourceModel (group PcuGroupModel , deletionProt , rcuProt types.Bool ) pcuGroupResourceModel {
327+ return pcuGroupResourceModel {
328+ PcuGroupModel : group ,
329+ Parked : types .BoolValue (group .Status .ValueString () == string (astra .PCUGroupStatusPARKED )),
330+ DeletionProtection : ElvisTF (& deletionProt , types .BoolValue (true )),
331+ RCUProtection : ElvisTF (& rcuProt , types .BoolValue (true )),
332+ }
328333}
0 commit comments