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 - Extend the support level of (blob|queue|share)_properties for Storage kind #25427

Merged
merged 7 commits into from Apr 8, 2024
6 changes: 3 additions & 3 deletions internal/services/storage/storage_account_resource.go
Expand Up @@ -70,14 +70,14 @@ func resolveStorageAccountServiceSupportLevel(kind storage.Kind, tier storage.Sk
supportBlob := kind != storage.KindFileStorage

// Queue is only supported for Storage and StorageV2, in Standard sku tier.
supportQueue := tier == storage.SkuTierStandard && kind == storage.KindStorageV2
supportQueue := tier == storage.SkuTierStandard && slices.Contains([]storage.Kind{storage.KindStorage, storage.KindStorageV2}, kind)

// File share is only supported for StorageV2 and FileStorage.
// See: https://docs.microsoft.com/en-us/azure/storage/files/storage-files-planning#management-concepts
// Per test, the StorageV2 with Premium sku tier also doesn't support file share.
supportShare := kind == storage.KindFileStorage || (kind == storage.KindStorageV2 && tier != storage.SkuTierPremium)
supportShare := kind == storage.KindFileStorage || (slices.Contains([]storage.Kind{storage.KindStorage, storage.KindStorageV2}, kind) && tier != storage.SkuTierPremium)

// Static Website is only supported for StorageV2 and BlockBlobStorage
// Static Website is only supported for StorageV2 (not for Storage(v1)) and BlockBlobStorage
supportStaticWebSite := kind == storage.KindStorageV2 || kind == storage.KindBlockBlobStorage

return storageAccountServiceSupportLevel{
Expand Down
181 changes: 181 additions & 0 deletions internal/services/storage/storage_account_resource_test.go
Expand Up @@ -1609,6 +1609,50 @@ func TestAccStorageAccount_invalidAccountKindForAccessTier(t *testing.T) {
})
}

func TestAccStorageAccount_StorageV1_blobProperties(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_account", "test")
r := StorageAccountResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.storageV1BlobProperties(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccStorageAccount_StorageV1_queueProperties(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_account", "test")
r := StorageAccountResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.storageV1QueueProperties(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccStorageAccount_StorageV1_shareProperties(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_account", "test")
r := StorageAccountResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.storageV1ShareProperties(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}
func (r StorageAccountResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := commonids.ParseStorageAccountID(state.ID)
if err != nil {
Expand Down Expand Up @@ -4700,3 +4744,140 @@ resource "azurerm_storage_account" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString)
}

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

resource "azurerm_resource_group" "test" {
name = "acctestAzureRMSA-%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_kind = "Storage"
account_tier = "Standard"
account_replication_type = "LRS"

blob_properties {
cors_rule {
allowed_origins = ["http://www.example.com"]
exposed_headers = ["x-tempo-*"]
allowed_headers = ["x-tempo-*"]
allowed_methods = ["GET", "PUT", "PATCH"]
max_age_in_seconds = "500"
}

delete_retention_policy {
days = 300
}
default_service_version = "2019-07-07"
container_delete_retention_policy {
days = 7
}
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString)
}

func (r StorageAccountResource) storageV1QueueProperties(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_kind = "Storage"
account_tier = "Standard"
account_replication_type = "LRS"

queue_properties {
cors_rule {
allowed_origins = ["http://www.example.com"]
exposed_headers = ["x-tempo-*"]
allowed_headers = ["x-tempo-*"]
allowed_methods = ["GET", "PUT"]
max_age_in_seconds = "500"
}

logging {
version = "1.0"
delete = true
read = true
write = true
retention_policy_days = 7
}

hour_metrics {
version = "1.0"
enabled = false
retention_policy_days = 7
}

minute_metrics {
version = "1.0"
enabled = false
retention_policy_days = 7
}
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString)
}

func (r StorageAccountResource) storageV1ShareProperties(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_kind = "Storage"
account_tier = "Standard"
account_replication_type = "LRS"

share_properties {
cors_rule {
allowed_origins = ["http://www.example.com"]
exposed_headers = ["x-tempo-*"]
allowed_headers = ["x-tempo-*"]
allowed_methods = ["GET", "PUT", "PATCH"]
max_age_in_seconds = "500"
}

retention_policy {
days = 300
}

smb {
versions = ["SMB3.0"]
authentication_types = ["NTLMv2"]
kerberos_ticket_encryption_type = ["AES-256"]
}
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString)
}
4 changes: 3 additions & 1 deletion website/docs/r/storage_account.html.markdown
Expand Up @@ -136,14 +136,16 @@ The following arguments are supported:

* `queue_properties` - (Optional) A `queue_properties` block as defined below.

~> **NOTE:** `queue_properties` cannot be set when the `account_kind` is set to `BlobStorage`
~> **NOTE:** `queue_properties` can only be configured when `account_tier` is set to `Standard` and `account_kind` is set to either `Storage` or `StorageV2`.

* `static_website` - (Optional) A `static_website` block as defined below.

~> **NOTE:** `static_website` can only be set when the `account_kind` is set to `StorageV2` or `BlockBlobStorage`.

* `share_properties` - (Optional) A `share_properties` block as defined below.

~> **NOTE:** `share_properties` can only be configured when either `account_tier` is `Standard` and `account_kind` is either `Storage` or `StorageV2` - or when `account_tier` is `Premium` and `account_kind` is `FileStorage`.

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

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