Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_storage_account - improve validation around the immutability_policy being used with blob_properties #24938

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions internal/services/storage/storage_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -1560,9 +1560,20 @@ func resourceStorageAccountCreate(d *pluginsdk.ResourceData, meta interface{}) e
return fmt.Errorf("`versioning_enabled` can't be true when `is_hns_enabled` is true")
}

if (blobProperties.IsVersioningEnabled != nil && !*blobProperties.IsVersioningEnabled) && (blobProperties.RestorePolicy != nil && blobProperties.RestorePolicy.Enabled != nil && *blobProperties.RestorePolicy.Enabled) {
// Otherwise, API returns: "Conflicting feature 'restorePolicy' is enabled. Please disable it and retry."
return fmt.Errorf("`blob_properties.restore_policy` can't be set when `versioning_enabled` is false")
if blobProperties.IsVersioningEnabled != nil && !*blobProperties.IsVersioningEnabled {
if blobProperties.RestorePolicy != nil && blobProperties.RestorePolicy.Enabled != nil && *blobProperties.RestorePolicy.Enabled {
// Otherwise, API returns: "Conflicting feature 'restorePolicy' is enabled. Please disable it and retry."
return fmt.Errorf("`blob_properties.restore_policy` can't be set when `versioning_enabled` is false")
}
if account.AccountProperties != nil &&
account.AccountProperties.ImmutableStorageWithVersioning != nil &&
account.AccountProperties.ImmutableStorageWithVersioning.ImmutabilityPolicy != nil &&
account.AccountProperties.ImmutableStorageWithVersioning.Enabled != nil &&
*account.AccountProperties.ImmutableStorageWithVersioning.Enabled {
// Otherwise, API returns: "Conflicting feature 'Account level WORM' is enabled. Please disable it and retry."
// See: https://learn.microsoft.com/en-us/azure/storage/blobs/immutable-policy-configure-version-scope?tabs=azure-portal#prerequisites
return fmt.Errorf("`immutability_policy` can't be set when `versioning_enabled` is false")
}
}

if _, err = blobClient.SetServiceProperties(ctx, id.ResourceGroupName, id.StorageAccountName, *blobProperties); err != nil {
Expand Down
Loading