From 74d276d4320cc29e52ae129b4434279e10fb1e55 Mon Sep 17 00:00:00 2001 From: Fred Park Date: Wed, 10 May 2023 19:47:37 +0000 Subject: [PATCH] Requested review changes - Remove unnecessary ${} - Use `versionless_id` proeprty instead of manual key URL construction - Use numbered string formats - Applied these fixes to the prior "versioned key" test cases as well --- .../batch/batch_account_data_source_test.go | 74 +++++++++---------- .../batch/batch_account_resource_test.go | 66 ++++++++--------- website/docs/d/batch_account.html.markdown | 6 +- website/docs/r/batch_account.html.markdown | 2 +- 4 files changed, 74 insertions(+), 74 deletions(-) diff --git a/internal/services/batch/batch_account_data_source_test.go b/internal/services/batch/batch_account_data_source_test.go index 39a8a6dc3bd0..1a2ea2ddb243 100644 --- a/internal/services/batch/batch_account_data_source_test.go +++ b/internal/services/batch/batch_account_data_source_test.go @@ -245,12 +245,12 @@ data "azurerm_client_config" "current" { } resource "azurerm_resource_group" "test" { - name = "testaccRG-batch-%d" - location = "%s" + name = "testaccRG-batch-%[1]d" + location = "%[2]s" } resource "azurerm_storage_account" "test" { - name = "testaccsa%s" + name = "testaccsa%[3]s" resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location account_tier = "Standard" @@ -258,13 +258,13 @@ resource "azurerm_storage_account" "test" { } resource "azurerm_user_assigned_identity" "test" { - name = "acctest%s" + name = "acctest%[3]s" resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location } resource "azurerm_batch_account" "test" { - name = "testaccbatch%s" + name = "testaccbatch%[3]s" resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location pool_allocation_mode = "BatchService" @@ -281,20 +281,20 @@ resource "azurerm_batch_account" "test" { } resource "azurerm_key_vault" "test" { - name = "batchkv%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = "batchkv%[3]s" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name enabled_for_disk_encryption = true enabled_for_deployment = true enabled_for_template_deployment = true purge_protection_enabled = true - tenant_id = "%s" + tenant_id = "%[4]s" sku_name = "standard" access_policy { - tenant_id = "%s" - object_id = "${data.azurerm_client_config.current.object_id}" + tenant_id = "%[4]s" + object_id = data.azurerm_client_config.current.object_id key_permissions = [ "Get", @@ -308,8 +308,8 @@ resource "azurerm_key_vault" "test" { } access_policy { - tenant_id = "%s" - object_id = "${azurerm_user_assigned_identity.test.principal_id}" + tenant_id = "%[4]s" + object_id = azurerm_user_assigned_identity.test.principal_id key_permissions = [ "Get", @@ -320,8 +320,8 @@ resource "azurerm_key_vault" "test" { } resource "azurerm_key_vault_key" "test" { - name = "enckey%d" - key_vault_id = "${azurerm_key_vault.test.id}" + name = "enckey%[1]d" + key_vault_id = azurerm_key_vault.test.id key_type = "RSA" key_size = 2048 @@ -336,11 +336,11 @@ resource "azurerm_key_vault_key" "test" { } data "azurerm_batch_account" "test" { - name = "${azurerm_batch_account.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_batch_account.test.name + resource_group_name = azurerm_resource_group.test.name } -`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomString, data.RandomString, tenantID, tenantID, tenantID, data.RandomInteger) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, tenantID) } func (BatchAccountDataSource) cmkVersionlessKeyData(data acceptance.TestData, tenantID string) string { @@ -358,12 +358,12 @@ data "azurerm_client_config" "current" { } resource "azurerm_resource_group" "test" { - name = "testaccRG-batch-%d" - location = "%s" + name = "testaccRG-batch-%[1]d" + location = "%[2]s" } resource "azurerm_storage_account" "test" { - name = "testaccsa%s" + name = "testaccsa%[3]s" resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location account_tier = "Standard" @@ -371,13 +371,13 @@ resource "azurerm_storage_account" "test" { } resource "azurerm_user_assigned_identity" "test" { - name = "acctest%s" + name = "acctest%[3]s" resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location } resource "azurerm_batch_account" "test" { - name = "testaccbatch%s" + name = "testaccbatch%[3]s" resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location pool_allocation_mode = "BatchService" @@ -389,25 +389,25 @@ resource "azurerm_batch_account" "test" { } encryption { - key_vault_key_id = "${azurerm_key_vault.test.vault_uri}keys/${azurerm_key_vault_key.test.name}" + key_vault_key_id = azurerm_key_vault_key.test.versionless_id } } resource "azurerm_key_vault" "test" { - name = "batchkv%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = "batchkv%[3]s" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name enabled_for_disk_encryption = true enabled_for_deployment = true enabled_for_template_deployment = true purge_protection_enabled = true - tenant_id = "%s" + tenant_id = "%[4]s" sku_name = "standard" access_policy { - tenant_id = "%s" - object_id = "${data.azurerm_client_config.current.object_id}" + tenant_id = "%[4]s" + object_id = data.azurerm_client_config.current.object_id key_permissions = [ "Get", @@ -421,8 +421,8 @@ resource "azurerm_key_vault" "test" { } access_policy { - tenant_id = "%s" - object_id = "${azurerm_user_assigned_identity.test.principal_id}" + tenant_id = "%[4]s" + object_id = azurerm_user_assigned_identity.test.principal_id key_permissions = [ "Get", @@ -433,8 +433,8 @@ resource "azurerm_key_vault" "test" { } resource "azurerm_key_vault_key" "test" { - name = "enckey%d" - key_vault_id = "${azurerm_key_vault.test.id}" + name = "enckey%[1]d" + key_vault_id = azurerm_key_vault.test.id key_type = "RSA" key_size = 2048 @@ -449,9 +449,9 @@ resource "azurerm_key_vault_key" "test" { } data "azurerm_batch_account" "test" { - name = "${azurerm_batch_account.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_batch_account.test.name + resource_group_name = azurerm_resource_group.test.name } -`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomString, data.RandomString, tenantID, tenantID, tenantID, data.RandomInteger) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, tenantID) } diff --git a/internal/services/batch/batch_account_resource_test.go b/internal/services/batch/batch_account_resource_test.go index 6dcac6e65087..39ab61e733ca 100644 --- a/internal/services/batch/batch_account_resource_test.go +++ b/internal/services/batch/batch_account_resource_test.go @@ -574,12 +574,12 @@ data "azurerm_client_config" "current" { } resource "azurerm_resource_group" "test" { - name = "testaccRG-batch-%d" - location = "%s" + name = "testaccRG-batch-%[1]d" + location = "%[2]s" } resource "azurerm_storage_account" "test" { - name = "testaccsa%s" + name = "testaccsa%[3]s" resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location account_tier = "Standard" @@ -587,13 +587,13 @@ resource "azurerm_storage_account" "test" { } resource "azurerm_user_assigned_identity" "test" { - name = "acctest%s" + name = "acctest%[3]s" resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location } resource "azurerm_batch_account" "test" { - name = "testaccbatch%s" + name = "testaccbatch%[3]s" resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location pool_allocation_mode = "BatchService" @@ -610,20 +610,20 @@ resource "azurerm_batch_account" "test" { } resource "azurerm_key_vault" "test" { - name = "batchkv%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = "batchkv%[3]s" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name enabled_for_disk_encryption = true enabled_for_deployment = true enabled_for_template_deployment = true purge_protection_enabled = true - tenant_id = "%s" + tenant_id = "%[4]s" sku_name = "standard" access_policy { - tenant_id = "%s" - object_id = "${data.azurerm_client_config.current.object_id}" + tenant_id = "%[4]s" + object_id = data.azurerm_client_config.current.object_id key_permissions = [ "Get", @@ -637,8 +637,8 @@ resource "azurerm_key_vault" "test" { } access_policy { - tenant_id = "%s" - object_id = "${azurerm_user_assigned_identity.test.principal_id}" + tenant_id = "%[4]s" + object_id = azurerm_user_assigned_identity.test.principal_id key_permissions = [ "Get", @@ -649,8 +649,8 @@ resource "azurerm_key_vault" "test" { } resource "azurerm_key_vault_key" "test" { - name = "enckey%d" - key_vault_id = "${azurerm_key_vault.test.id}" + name = "enckey%[1]d" + key_vault_id = azurerm_key_vault.test.id key_type = "RSA" key_size = 2048 @@ -664,7 +664,7 @@ resource "azurerm_key_vault_key" "test" { ] } -`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomString, data.RandomString, tenantID, tenantID, tenantID, data.RandomInteger) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, tenantID) } func (BatchAccountResource) cmkVersionlessKey(data acceptance.TestData, tenantID string) string { @@ -682,12 +682,12 @@ data "azurerm_client_config" "current" { } resource "azurerm_resource_group" "test" { - name = "testaccRG-batch-%d" - location = "%s" + name = "testaccRG-batch-%[1]d" + location = "%[2]s" } resource "azurerm_storage_account" "test" { - name = "testaccsa%s" + name = "testaccsa%[3]s" resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location account_tier = "Standard" @@ -695,13 +695,13 @@ resource "azurerm_storage_account" "test" { } resource "azurerm_user_assigned_identity" "test" { - name = "acctest%s" + name = "acctest%[3]s" resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location } resource "azurerm_batch_account" "test" { - name = "testaccbatch%s" + name = "testaccbatch%[3]s" resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location pool_allocation_mode = "BatchService" @@ -713,25 +713,25 @@ resource "azurerm_batch_account" "test" { } encryption { - key_vault_key_id = "${azurerm_key_vault.test.vault_uri}keys/${azurerm_key_vault_key.test.name}" + key_vault_key_id = azurerm_key_vault_key.test.versionless_id } } resource "azurerm_key_vault" "test" { - name = "batchkv%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = "batchkv%[3]s" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name enabled_for_disk_encryption = true enabled_for_deployment = true enabled_for_template_deployment = true purge_protection_enabled = true - tenant_id = "%s" + tenant_id = "%[4]s" sku_name = "standard" access_policy { - tenant_id = "%s" - object_id = "${data.azurerm_client_config.current.object_id}" + tenant_id = "%[4]s" + object_id = data.azurerm_client_config.current.object_id key_permissions = [ "Get", @@ -745,8 +745,8 @@ resource "azurerm_key_vault" "test" { } access_policy { - tenant_id = "%s" - object_id = "${azurerm_user_assigned_identity.test.principal_id}" + tenant_id = "%[4]s" + object_id = azurerm_user_assigned_identity.test.principal_id key_permissions = [ "Get", @@ -757,8 +757,8 @@ resource "azurerm_key_vault" "test" { } resource "azurerm_key_vault_key" "test" { - name = "enckey%d" - key_vault_id = "${azurerm_key_vault.test.id}" + name = "enckey%[1]d" + key_vault_id = azurerm_key_vault.test.id key_type = "RSA" key_size = 2048 @@ -772,7 +772,7 @@ resource "azurerm_key_vault_key" "test" { ] } -`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomString, data.RandomString, tenantID, tenantID, tenantID, data.RandomInteger) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, tenantID) } func (BatchAccountResource) removeStorageAccount(data acceptance.TestData) string { diff --git a/website/docs/d/batch_account.html.markdown b/website/docs/d/batch_account.html.markdown index 190d5233c7a7..4fe6fc8c4663 100644 --- a/website/docs/d/batch_account.html.markdown +++ b/website/docs/d/batch_account.html.markdown @@ -60,7 +60,7 @@ The following attributes are exported: --- -A `key_vault_reference` block has the following properties: +A `key_vault_reference` block exports the following: * `id` - The Azure identifier of the Azure KeyVault reference. @@ -68,9 +68,9 @@ A `key_vault_reference` block has the following properties: --- -An `encryption` block has the following properties: +An `encryption` block exports the following: -* `key_vault_key_id` - The Azure identifier of the Azure KeyVault key reference. +* `key_vault_key_id` - The full URL path of the Key Vault Key used to encrypt data for this Batch account. --- diff --git a/website/docs/r/batch_account.html.markdown b/website/docs/r/batch_account.html.markdown index aec71915805c..63c8d566be92 100644 --- a/website/docs/r/batch_account.html.markdown +++ b/website/docs/r/batch_account.html.markdown @@ -103,7 +103,7 @@ A `key_vault_reference` block supports the following: A `encryption` block supports the following: -* `key_vault_key_id` - (Required) The Azure key vault reference id that should be used to encrypt data, as documented [here](https://docs.microsoft.com/azure/batch/batch-customer-managed-key). Both versioned and versionless keys are supported. +* `key_vault_key_id` - (Required) The full URL path to the Azure key vault key id that should be used to encrypt data, as documented [here](https://docs.microsoft.com/azure/batch/batch-customer-managed-key). Both versioned and versionless keys are supported. ## Attributes Reference