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 - Updated account_replication_type validation #12645

Merged
merged 1 commit into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
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
53 changes: 34 additions & 19 deletions azurerm/internal/services/storage/storage_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ func resourceStorageAccount() *pluginsdk.Resource {
"account_replication_type": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
"LRS",
"ZRS",
Expand Down Expand Up @@ -839,27 +838,43 @@ func resourceStorageAccount() *pluginsdk.Resource {
},
},
},
CustomizeDiff: pluginsdk.CustomizeDiffShim(func(ctx context.Context, d *pluginsdk.ResourceDiff, v interface{}) error {
if d.HasChange("account_kind") {
accountKind, changedKind := d.GetChange("account_kind")

if accountKind != string(storage.Storage) && changedKind != string(storage.StorageV2) {
log.Printf("[DEBUG] recreate storage account, could't be migrated from %s to %s", accountKind, changedKind)
d.ForceNew("account_kind")
} else {
log.Printf("[DEBUG] storage account can be upgraded from %s to %s", accountKind, changedKind)
CustomizeDiff: pluginsdk.CustomDiffWithAll(
pluginsdk.CustomizeDiffShim(func(ctx context.Context, d *pluginsdk.ResourceDiff, v interface{}) error {
if d.HasChange("account_kind") {
accountKind, changedKind := d.GetChange("account_kind")

if accountKind != string(storage.Storage) && changedKind != string(storage.StorageV2) {
log.Printf("[DEBUG] recreate storage account, could't be migrated from %s to %s", accountKind, changedKind)
d.ForceNew("account_kind")
} else {
log.Printf("[DEBUG] storage account can be upgraded from %s to %s", accountKind, changedKind)
}
}
}

if d.HasChange("large_file_share_enabled") {
lfsEnabled, changedEnabled := d.GetChange("large_file_share_enabled")
if lfsEnabled.(bool) && !changedEnabled.(bool) {
return fmt.Errorf("`large_file_share_enabled` cannot be disabled once it's been enabled")
if d.HasChange("large_file_share_enabled") {
lfsEnabled, changedEnabled := d.GetChange("large_file_share_enabled")
if lfsEnabled.(bool) && !changedEnabled.(bool) {
return fmt.Errorf("`large_file_share_enabled` cannot be disabled once it's been enabled")
}
}
}

return nil
}),
return nil
}),
pluginsdk.ForceNewIfChange("account_replication_type", func(ctx context.Context, old, new, meta interface{}) bool {
newAccRep := strings.ToUpper(new.(string))

switch strings.ToUpper(old.(string)) {
case "LRS", "GRS", "RAGRS":
if newAccRep == "GZRS" || newAccRep == "RAGZRS" || newAccRep == "ZRS" {
return true
}
case "ZRS", "GZRS", "RAGZRS":
if newAccRep == "LRS" || newAccRep == "GRS" || newAccRep == "RAGRS" {
return true
}
}
return false
}),
),
}
}

Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/storage_account.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ The following arguments are supported:

* `account_tier` - (Required) Defines the Tier to use for this storage account. Valid options are `Standard` and `Premium`. For `BlockBlobStorage` and `FileStorage` accounts only `Premium` is valid. Changing this forces a new resource to be created.

* `account_replication_type` - (Required) Defines the type of replication to use for this storage account. Valid options are `LRS`, `GRS`, `RAGRS`, `ZRS`, `GZRS` and `RAGZRS`. Changing this forces a new resource to be created.
* `account_replication_type` - (Required) Defines the type of replication to use for this storage account. Valid options are `LRS`, `GRS`, `RAGRS`, `ZRS`, `GZRS` and `RAGZRS`. Changing this forces a new resource to be created when types `LRS`, `GRS` and `RAGRS` are changed to `ZRS`, `GZRS` or `RAGZRS` and vice versa.

* `access_tier` - (Optional) Defines the access tier for `BlobStorage`, `FileStorage` and `StorageV2` accounts. Valid options are `Hot` and `Cool`, defaults to `Hot`.

Expand Down