@@ -104,7 +104,7 @@ func (r StorageContainerImmutabilityPolicyResource) CustomizeDiff() sdk.Resource
104
104
105
105
if lockedOld .(bool ) {
106
106
if diff .HasChange ("immutability_period_in_days" ) {
107
- if periodOld , periodNew := diff .GetChange ("immutability_period_in_days" ); periodOld .(int ) < periodNew .(int ) {
107
+ if periodOld , periodNew := diff .GetChange ("immutability_period_in_days" ); periodOld .(int ) > periodNew .(int ) {
108
108
return fmt .Errorf ("`immutability_period_in_days` cannot be decreased once an immutability policy has been locked" )
109
109
}
110
110
}
@@ -228,28 +228,37 @@ func (r StorageContainerImmutabilityPolicyResource) Update() sdk.ResourceFunc {
228
228
},
229
229
}
230
230
231
- options := blobcontainers.CreateOrUpdateImmutabilityPolicyOperationOptions {
232
- IfMatch : resp .Model .Etag ,
233
- }
234
-
235
- updateResp , err := client .CreateOrUpdateImmutabilityPolicy (ctx , * containerId , input , options )
236
- if err != nil {
237
- return fmt .Errorf ("updating %s: %+v" , id , err )
238
- }
239
-
240
- // Lock the policy if requested - note that this is a one-way operation that prevents subsequent changes or
241
- // deletion to the policy, the container it applies to, and the storage account where it resides.
242
- if model .Locked {
243
- if updateResp .Model == nil {
244
- return fmt .Errorf ("preparing to lock %s: model was nil" , id )
231
+ if * resp .Model .Properties .State == blobcontainers .ImmutabilityPolicyStateLocked {
232
+ // Only extending the immutability policy is allowed when the policy is locked
233
+ options := blobcontainers.ExtendImmutabilityPolicyOperationOptions {
234
+ IfMatch : resp .Model .Etag ,
245
235
}
246
-
247
- lockOptions := blobcontainers.LockImmutabilityPolicyOperationOptions {
248
- IfMatch : updateResp .Model .Etag ,
236
+ if _ , err := client .ExtendImmutabilityPolicy (ctx , * containerId , input , options ); err != nil {
237
+ return fmt .Errorf ("extending %s: %+v" , id , err )
238
+ }
239
+ } else {
240
+ options := blobcontainers.CreateOrUpdateImmutabilityPolicyOperationOptions {
241
+ IfMatch : resp .Model .Etag ,
242
+ }
243
+ updateResp , err := client .CreateOrUpdateImmutabilityPolicy (ctx , * containerId , input , options )
244
+ if err != nil {
245
+ return fmt .Errorf ("updating %s: %+v" , id , err )
249
246
}
250
247
251
- if _ , err = client .LockImmutabilityPolicy (ctx , * containerId , lockOptions ); err != nil {
252
- return fmt .Errorf ("locking %s: %+v" , id , err )
248
+ // Lock the policy if requested - note that this is a one-way operation that prevents subsequent changes or
249
+ // deletion to the policy, the container it applies to, and the storage account where it resides.
250
+ if model .Locked {
251
+ if updateResp .Model == nil {
252
+ return fmt .Errorf ("preparing to lock %s: model was nil" , id )
253
+ }
254
+
255
+ lockOptions := blobcontainers.LockImmutabilityPolicyOperationOptions {
256
+ IfMatch : updateResp .Model .Etag ,
257
+ }
258
+
259
+ if _ , err = client .LockImmutabilityPolicy (ctx , * containerId , lockOptions ); err != nil {
260
+ return fmt .Errorf ("locking %s: %+v" , id , err )
261
+ }
253
262
}
254
263
}
255
264
0 commit comments