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 - add support for large_file_share_enabled #8789

Merged
merged 2 commits into from
Oct 8, 2020
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
40 changes: 40 additions & 0 deletions azurerm/internal/services/storage/resource_arm_storage_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,11 @@ func resourceArmStorageAccount() *schema.Resource {
},
},

"large_file_share_enabled": {
Type: schema.TypeBool,
Optional: true,
},

"primary_location": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -575,6 +580,13 @@ func resourceArmStorageAccount() *schema.Resource {
}
}

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` cannot be disabled once it's been enabled")
}
}

return nil
},
}
Expand Down Expand Up @@ -700,6 +712,14 @@ func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) e
}
}

// nolint staticcheck
if v, ok := d.GetOkExists("large_file_share_enabled"); ok {
parameters.LargeFileSharesState = storage.LargeFileSharesStateDisabled
if v.(bool) {
parameters.LargeFileSharesState = storage.LargeFileSharesStateEnabled
}
}

// Create
future, err := client.Create(ctx, resourceGroupName, storageAccountName, parameters)
if err != nil {
Expand Down Expand Up @@ -961,6 +981,22 @@ func resourceArmStorageAccountUpdate(d *schema.ResourceData, meta interface{}) e
}
}

if d.HasChange("large_file_share_enabled") {
isEnabled := storage.LargeFileSharesStateDisabled
if v := d.Get("large_file_share_enabled").(bool); v {
isEnabled = storage.LargeFileSharesStateEnabled
}
opts := storage.AccountUpdateParameters{
AccountPropertiesUpdateParameters: &storage.AccountPropertiesUpdateParameters{
LargeFileSharesState: isEnabled,
},
}

if _, err := client.Update(ctx, resourceGroupName, storageAccountName, opts); err != nil {
return fmt.Errorf("Error updating Azure Storage Account network_rules %q: %+v", storageAccountName, err)
}
}

if d.HasChange("blob_properties") {
// FileStorage does not support blob settings
if accountKind != string(storage.FileStorage) {
Expand Down Expand Up @@ -1160,6 +1196,10 @@ func resourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) err
if err := d.Set("network_rules", flattenStorageAccountNetworkRules(props.NetworkRuleSet)); err != nil {
return fmt.Errorf("Error setting `network_rules`: %+v", err)
}

if props.LargeFileSharesState != "" {
d.Set("large_file_share_enabled", props.LargeFileSharesState == storage.LargeFileSharesStateEnabled)
}
}

if accessKeys := keys.Keys; accessKeys != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,43 @@ func TestAccAzureRMStorageAccount_replicationTypeGZRS(t *testing.T) {
})
}

func TestAccAzureRMStorageAccount_largeFileShare(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_account", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMStorageAccountDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMStorageAccount_basic(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStorageAccountExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: testAccAzureRMStorageAccount_largeFileShareDisabled(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStorageAccountExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: testAccAzureRMStorageAccount_largeFileShareEnabled(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStorageAccountExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: testAccAzureRMStorageAccount_largeFileShareDisabled(data),
ExpectError: regexp.MustCompile("`large_file_share` cannot be disabled once it's been enabled"),
},
},
})
}

func testCheckAzureRMStorageAccountExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
// Ensure resource group exists in API
Expand Down Expand Up @@ -1995,3 +2032,57 @@ resource "azurerm_storage_account" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString)
}

func testAccAzureRMStorageAccount_largeFileShareDisabled(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-storage-%d"
location = "%s"
}

resource "azurerm_storage_account" "test" {
name = "unlikely23exst2acct%s"
resource_group_name = azurerm_resource_group.test.name

location = azurerm_resource_group.test.location
account_tier = "Standard"
account_replication_type = "LRS"
large_file_share_enabled = false

tags = {
environment = "production"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString)
}

func testAccAzureRMStorageAccount_largeFileShareEnabled(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-storage-%d"
location = "%s"
}

resource "azurerm_storage_account" "test" {
name = "unlikely23exst2acct%s"
resource_group_name = azurerm_resource_group.test.name

location = azurerm_resource_group.test.location
account_tier = "Standard"
account_replication_type = "LRS"
large_file_share_enabled = true

tags = {
environment = "production"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString)
}
2 changes: 2 additions & 0 deletions website/docs/r/storage_account.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ The following arguments are supported:

* `network_rules` - (Optional) A `network_rules` block as documented below.

* `large_file_share_enabled` - (Optional) Is Large File Share Enabled?

* `tags` - (Optional) A mapping of tags to assign to the resource.

---
Expand Down