From 68f0e301cb5ed89528822512bcbfde5ae8694057 Mon Sep 17 00:00:00 2001 From: Matt Mencel Date: Fri, 28 Jun 2019 10:07:29 -0500 Subject: [PATCH 1/5] Add FileStorage kind to Storage Account resource --- azurerm/resource_arm_storage_account.go | 1 + azurerm/resource_arm_storage_account_test.go | 81 ++++++++++++++++++++ website/docs/r/storage_account.html.markdown | 2 +- 3 files changed, 83 insertions(+), 1 deletion(-) diff --git a/azurerm/resource_arm_storage_account.go b/azurerm/resource_arm_storage_account.go index 7a659ba360f6..4ac1e6017040 100644 --- a/azurerm/resource_arm_storage_account.go +++ b/azurerm/resource_arm_storage_account.go @@ -51,6 +51,7 @@ func resourceArmStorageAccount() *schema.Resource { ValidateFunc: validation.StringInSlice([]string{ string(storage.Storage), string(storage.BlobStorage), + string(storage.FileStorage), string(storage.StorageV2), }, true), Default: string(storage.Storage), diff --git a/azurerm/resource_arm_storage_account_test.go b/azurerm/resource_arm_storage_account_test.go index 3b943c8a9948..c6dd4b6f462c 100644 --- a/azurerm/resource_arm_storage_account_test.go +++ b/azurerm/resource_arm_storage_account_test.go @@ -396,7 +396,42 @@ func TestAccAzureRMStorageAccount_blobStorageWithUpdate(t *testing.T) { }, }) } +func TestAccAzureRMStorageAccount_fileStorageWithUpdate(t *testing.T) { + resourceName := "azurerm_storage_account.testsa" + ri := tf.AccRandTimeInt() + rs := acctest.RandString(4) + location := testLocation() + preConfig := testAccAzureRMStorageAccount_fileStorage(ri, rs, location) + postConfig := testAccAzureRMStorageAccount_fileStorageUpdate(ri, rs, location) + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMStorageAccountDestroy, + Steps: []resource.TestStep{ + { + Config: preConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMStorageAccountExists(resourceName), + resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "account_kind", "FileStorage"), + resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "access_tier", "Hot"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: postConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMStorageAccountExists(resourceName), + resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "access_tier", "Cool"), + ), + }, + }, + }) +} func TestAccAzureRMStorageAccount_storageV2WithUpdate(t *testing.T) { resourceName := "azurerm_storage_account.testsa" ri := tf.AccRandTimeInt() @@ -982,6 +1017,52 @@ resource "azurerm_storage_account" "testsa" { `, rInt, location, rString) } +func testAccAzureRMStorageAccount_fileStorage(rInt int, rString string, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "testrg" { + name = "acctestAzureRMSA-%d" + location = "%s" +} + +resource "azurerm_storage_account" "testsa" { + name = "unlikely23exst2acct%s" + resource_group_name = "${azurerm_resource_group.testrg.name}" + + location = "${azurerm_resource_group.testrg.location}" + account_kind = "FileStorage" + account_tier = "Standard" + account_replication_type = "LRS" + + tags = { + environment = "production" + } +} +`, rInt, location, rString) +} + +func testAccAzureRMStorageAccount_fileStorageUpdate(rInt int, rString string, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "testrg" { + name = "acctestAzureRMSA-%d" + location = "%s" +} + +resource "azurerm_storage_account" "testsa" { + name = "unlikely23exst2acct%s" + resource_group_name = "${azurerm_resource_group.testrg.name}" + + location = "${azurerm_resource_group.testrg.location}" + account_kind = "FileStorage" + account_tier = "Standard" + account_replication_type = "LRS" + + tags = { + environment = "production2" + } +} +`, rInt, location, rString) +} + func testAccAzureRMStorageAccount_storageV2(rInt int, rString string, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { diff --git a/website/docs/r/storage_account.html.markdown b/website/docs/r/storage_account.html.markdown index 450a99a93395..87e3ed212143 100644 --- a/website/docs/r/storage_account.html.markdown +++ b/website/docs/r/storage_account.html.markdown @@ -89,7 +89,7 @@ The following arguments are supported: resource exists. Changing this forces a new resource to be created. * `account_kind` - (Optional) Defines the Kind of account. Valid options are `Storage`, - `StorageV2` and `BlobStorage`. Changing this forces a new resource to be created. + `StorageV2`, `BlobStorage`, and `FileStorage`. Changing this forces a new resource to be created. Defaults to `Storage`. * `account_tier` - (Required) Defines the Tier to use for this storage account. Valid options are `Standard` and `Premium`. Changing this forces a new resource to be created From 91a25410c58d90be2f6d04391edc7960fc798155 Mon Sep 17 00:00:00 2001 From: Matt Mencel Date: Mon, 1 Jul 2019 10:13:56 -0500 Subject: [PATCH 2/5] FileStorage accounts must be Premium --- azurerm/resource_arm_storage_account.go | 7 +++++++ azurerm/resource_arm_storage_account_test.go | 14 +++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/azurerm/resource_arm_storage_account.go b/azurerm/resource_arm_storage_account.go index 4ac1e6017040..ca4c4ce99c76 100644 --- a/azurerm/resource_arm_storage_account.go +++ b/azurerm/resource_arm_storage_account.go @@ -519,6 +519,13 @@ func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) e } } + // AccountTier must be Premium for FileStorage + if accountKind == string(storage.FileStorage) { + if string(parameters.Sku.Tier) == string(storage.StandardLRS) { + return fmt.Errorf("A `account_tier` of `Standard` is not supported for FileStorage accounts.") + } + } + // Create future, err := client.Create(ctx, resourceGroupName, storageAccountName, parameters) if err != nil { diff --git a/azurerm/resource_arm_storage_account_test.go b/azurerm/resource_arm_storage_account_test.go index c6dd4b6f462c..5fb31ef79116 100644 --- a/azurerm/resource_arm_storage_account_test.go +++ b/azurerm/resource_arm_storage_account_test.go @@ -414,6 +414,7 @@ func TestAccAzureRMStorageAccount_fileStorageWithUpdate(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMStorageAccountExists(resourceName), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "account_kind", "FileStorage"), + resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "account_tier", "Premium"), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "access_tier", "Hot"), ), }, @@ -426,6 +427,7 @@ func TestAccAzureRMStorageAccount_fileStorageWithUpdate(t *testing.T) { Config: postConfig, Check: resource.ComposeTestCheckFunc( testCheckAzureRMStorageAccountExists(resourceName), + resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "account_tier", "Premium"), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "access_tier", "Cool"), ), }, @@ -1030,8 +1032,9 @@ resource "azurerm_storage_account" "testsa" { location = "${azurerm_resource_group.testrg.location}" account_kind = "FileStorage" - account_tier = "Standard" - account_replication_type = "LRS" + account_tier = "Premium" + account_replication_type = "LRS" + access_tier = "Hot" tags = { environment = "production" @@ -1053,11 +1056,12 @@ resource "azurerm_storage_account" "testsa" { location = "${azurerm_resource_group.testrg.location}" account_kind = "FileStorage" - account_tier = "Standard" - account_replication_type = "LRS" + account_tier = "Premium" + account_replication_type = "LRS" + access_tier = "Cool" tags = { - environment = "production2" + environment = "production" } } `, rInt, location, rString) From 0eab628b694778690d83cb0e59b3f20f0e9355d4 Mon Sep 17 00:00:00 2001 From: Matt Mencel Date: Mon, 1 Jul 2019 10:19:04 -0500 Subject: [PATCH 3/5] update doc with tier requirement --- website/docs/r/storage_account.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/storage_account.html.markdown b/website/docs/r/storage_account.html.markdown index 87e3ed212143..234aace9e311 100644 --- a/website/docs/r/storage_account.html.markdown +++ b/website/docs/r/storage_account.html.markdown @@ -92,7 +92,7 @@ The following arguments are supported: `StorageV2`, `BlobStorage`, and `FileStorage`. Changing this forces a new resource to be created. Defaults to `Storage`. -* `account_tier` - (Required) Defines the Tier to use for this storage account. Valid options are `Standard` and `Premium`. Changing this forces a new resource to be created +* `account_tier` - (Required) Defines the Tier to use for this storage account. Valid options are `Standard` and `Premium`. For `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` and `ZRS`. From 69e4e4562f5dd26384b7b53f3d8aa973ff3cc34f Mon Sep 17 00:00:00 2001 From: kt Date: Tue, 2 Jul 2019 21:27:28 -0700 Subject: [PATCH 4/5] fix access_tier for FileStorage --- azurerm/resource_arm_storage_account.go | 2 +- azurerm/resource_arm_storage_account_test.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/azurerm/resource_arm_storage_account.go b/azurerm/resource_arm_storage_account.go index ca4c4ce99c76..79b13ac956c0 100644 --- a/azurerm/resource_arm_storage_account.go +++ b/azurerm/resource_arm_storage_account.go @@ -505,7 +505,7 @@ func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) e } // AccessTier is only valid for BlobStorage and StorageV2 accounts - if accountKind == string(storage.BlobStorage) || accountKind == string(storage.StorageV2) { + if accountKind == string(storage.BlobStorage) || accountKind == string(storage.StorageV2) || accountKind == string(storage.FileStorage) { accessTier, ok := d.GetOk("access_tier") if !ok { // default to "Hot" diff --git a/azurerm/resource_arm_storage_account_test.go b/azurerm/resource_arm_storage_account_test.go index 5fb31ef79116..377e842d2c30 100644 --- a/azurerm/resource_arm_storage_account_test.go +++ b/azurerm/resource_arm_storage_account_test.go @@ -1033,8 +1033,8 @@ resource "azurerm_storage_account" "testsa" { location = "${azurerm_resource_group.testrg.location}" account_kind = "FileStorage" account_tier = "Premium" - account_replication_type = "LRS" - access_tier = "Hot" + account_replication_type = "LRS" + access_tier = "Hot" tags = { environment = "production" @@ -1057,8 +1057,8 @@ resource "azurerm_storage_account" "testsa" { location = "${azurerm_resource_group.testrg.location}" account_kind = "FileStorage" account_tier = "Premium" - account_replication_type = "LRS" - access_tier = "Cool" + account_replication_type = "LRS" + access_tier = "Cool" tags = { environment = "production" From f7f9c889206d304ab96285bbf3d1979320438034 Mon Sep 17 00:00:00 2001 From: kt Date: Tue, 2 Jul 2019 21:28:38 -0700 Subject: [PATCH 5/5] udpate docs --- azurerm/resource_arm_storage_account.go | 2 +- website/docs/r/storage_account.html.markdown | 16 +++++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/azurerm/resource_arm_storage_account.go b/azurerm/resource_arm_storage_account.go index 79b13ac956c0..5d793809714f 100644 --- a/azurerm/resource_arm_storage_account.go +++ b/azurerm/resource_arm_storage_account.go @@ -504,7 +504,7 @@ func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) e } } - // AccessTier is only valid for BlobStorage and StorageV2 accounts + // AccessTier is only valid for BlobStorage, StorageV2, and FileStorage accounts if accountKind == string(storage.BlobStorage) || accountKind == string(storage.StorageV2) || accountKind == string(storage.FileStorage) { accessTier, ok := d.GetOk("access_tier") if !ok { diff --git a/website/docs/r/storage_account.html.markdown b/website/docs/r/storage_account.html.markdown index 234aace9e311..704c4fe45d51 100644 --- a/website/docs/r/storage_account.html.markdown +++ b/website/docs/r/storage_account.html.markdown @@ -78,25 +78,19 @@ resource "azurerm_storage_account" "testsa" { The following arguments are supported: -* `name` - (Required) Specifies the name of the storage account. Changing this forces a - new resource to be created. This must be unique across the entire Azure service, - not just within the resource group. +* `name` - (Required) Specifies the name of the storage account. Changing this forces a new resource to be created. This must be unique across the entire Azure service, not just within the resource group. -* `resource_group_name` - (Required) The name of the resource group in which to - create the storage account. Changing this forces a new resource to be created. +* `resource_group_name` - (Required) The name of the resource group in which to create the storage account. Changing this forces a new resource to be created. -* `location` - (Required) Specifies the supported Azure location where the - resource exists. Changing this forces a new resource to be created. +* `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. -* `account_kind` - (Optional) Defines the Kind of account. Valid options are `Storage`, - `StorageV2`, `BlobStorage`, and `FileStorage`. Changing this forces a new resource to be created. - Defaults to `Storage`. +* `account_kind` - (Optional) Defines the Kind of account. Valid options are `Storage`, `StorageV2`, `BlobStorage`, and `FileStorage`. Changing this forces a new resource to be created. Defaults to `Storage`. * `account_tier` - (Required) Defines the Tier to use for this storage account. Valid options are `Standard` and `Premium`. For `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` and `ZRS`. -* `access_tier` - (Optional) Defines the access tier for `BlobStorage` and `StorageV2` accounts. Valid options are `Hot` and `Cool`, defaults to `Hot`. +* `access_tier` - (Optional) Defines the access tier for `BlobStorage`, `FileStorage` and `StorageV2` accounts. Valid options are `Hot` and `Cool`, defaults to `Hot`. * `enable_blob_encryption` - (Optional) Boolean flag which controls if Encryption Services are enabled for Blob storage, see [here](https://azure.microsoft.com/en-us/documentation/articles/storage-service-encryption/) for more information. Defaults to `true`.