From 1a39bae1d1d7507d68ea31daee2bf6e31719b9a9 Mon Sep 17 00:00:00 2001 From: jackofallops Date: Fri, 2 Jul 2021 16:05:06 +0100 Subject: [PATCH 1/3] make additional locations not ForceNew --- .../services/apimanagement/api_management_resource.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/azurerm/internal/services/apimanagement/api_management_resource.go b/azurerm/internal/services/apimanagement/api_management_resource.go index c45e90551649..91b89137b65d 100644 --- a/azurerm/internal/services/apimanagement/api_management_resource.go +++ b/azurerm/internal/services/apimanagement/api_management_resource.go @@ -8,6 +8,8 @@ import ( "strings" "time" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/location" + "github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2020-12-01/apimanagement" "github.com/hashicorp/go-azure-helpers/response" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" @@ -180,7 +182,7 @@ func resourceApiManagementService() *pluginsdk.Resource { Optional: true, Elem: &pluginsdk.Resource{ Schema: map[string]*pluginsdk.Schema{ - "location": azure.SchemaLocation(), + "location": location.SchemaWithoutForceNew(), "virtual_network_configuration": { Type: pluginsdk.TypeList, From ed3b42f51646f3bdb5e61c5a133a6ce1bc44d709 Mon Sep 17 00:00:00 2001 From: jackofallops Date: Fri, 2 Jul 2021 16:20:46 +0100 Subject: [PATCH 2/3] add additional locations update test --- .../api_management_resource_test.go | 158 ++++++++++++++++++ 1 file changed, 158 insertions(+) diff --git a/azurerm/internal/services/apimanagement/api_management_resource_test.go b/azurerm/internal/services/apimanagement/api_management_resource_test.go index 2041499fd32d..e05779e7f903 100644 --- a/azurerm/internal/services/apimanagement/api_management_resource_test.go +++ b/azurerm/internal/services/apimanagement/api_management_resource_test.go @@ -121,6 +121,46 @@ func TestAccApiManagement_complete(t *testing.T) { }) } +func TestAccApiManagement_completeUpdateAdditionalLocations(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_api_management", "test") + r := ApiManagementResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep("certificate", // not returned from API, sensitive + "hostname_configuration.0.portal.0.certificate", // not returned from API, sensitive + "hostname_configuration.0.portal.0.certificate_password", // not returned from API, sensitive + "hostname_configuration.0.developer_portal.0.certificate", // not returned from API, sensitive + "hostname_configuration.0.developer_portal.0.certificate_password", // not returned from API, sensitive + "hostname_configuration.0.proxy.0.certificate", // not returned from API, sensitive + "hostname_configuration.0.proxy.0.certificate_password", // not returned from API, sensitive + "hostname_configuration.0.proxy.1.certificate", // not returned from API, sensitive + "hostname_configuration.0.proxy.1.certificate_password", // not returned from API, sensitive + ), + { + Config: r.completeUpdateAdditionalLocations(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep("certificate", // not returned from API, sensitive + "hostname_configuration.0.portal.0.certificate", // not returned from API, sensitive + "hostname_configuration.0.portal.0.certificate_password", // not returned from API, sensitive + "hostname_configuration.0.developer_portal.0.certificate", // not returned from API, sensitive + "hostname_configuration.0.developer_portal.0.certificate_password", // not returned from API, sensitive + "hostname_configuration.0.proxy.0.certificate", // not returned from API, sensitive + "hostname_configuration.0.proxy.0.certificate_password", // not returned from API, sensitive + "hostname_configuration.0.proxy.1.certificate", // not returned from API, sensitive + "hostname_configuration.0.proxy.1.certificate_password", // not returned from API, sensitive + ), + }) +} + func TestAccApiManagement_signInSignUpSettings(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_api_management", "test") r := ApiManagementResource{} @@ -978,6 +1018,124 @@ resource "azurerm_api_management" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Secondary, data.RandomInteger, data.Locations.Ternary, data.RandomInteger) } +func (ApiManagementResource) completeUpdateAdditionalLocations(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test1" { + name = "acctestRG-api1-%d" + location = "%s" +} + +resource "azurerm_resource_group" "test2" { + name = "acctestRG-api2-%d" + location = "%s" +} + +resource "azurerm_resource_group" "test3" { + name = "acctestRG-api3-%d" + location = "%s" +} + +resource "azurerm_api_management" "test" { + name = "acctestAM-%d" + publisher_name = "pub1" + publisher_email = "pub1@email.com" + notification_sender_email = "notification@email.com" + + additional_location { + location = azurerm_resource_group.test2.location + } + + certificate { + encoded_certificate = filebase64("testdata/api_management_api_test.pfx") + certificate_password = "terraform" + store_name = "CertificateAuthority" + } + + certificate { + encoded_certificate = filebase64("testdata/api_management_api_test.pfx") + certificate_password = "terraform" + store_name = "Root" + } + + certificate { + encoded_certificate = filebase64("testdata/api_management_api_test.cer") + store_name = "Root" + } + + certificate { + encoded_certificate = filebase64("testdata/api_management_api_test.cer") + store_name = "CertificateAuthority" + } + + protocols { + enable_http2 = true + } + + security { + enable_backend_tls11 = true + enable_backend_ssl30 = true + enable_backend_tls10 = true + enable_frontend_ssl30 = true + enable_frontend_tls10 = true + enable_frontend_tls11 = true + tls_ecdhe_ecdsa_with_aes128_cbc_sha_ciphers_enabled = true + tls_ecdhe_ecdsa_with_aes256_cbc_sha_ciphers_enabled = true + tls_ecdhe_rsa_with_aes128_cbc_sha_ciphers_enabled = true + tls_ecdhe_rsa_with_aes256_cbc_sha_ciphers_enabled = true + tls_rsa_with_aes128_cbc_sha256_ciphers_enabled = true + tls_rsa_with_aes128_cbc_sha_ciphers_enabled = true + tls_rsa_with_aes128_gcm_sha256_ciphers_enabled = true + tls_rsa_with_aes256_cbc_sha256_ciphers_enabled = true + tls_rsa_with_aes256_cbc_sha_ciphers_enabled = true + triple_des_ciphers_enabled = true + } + + hostname_configuration { + proxy { + host_name = "api.terraform.io" + certificate = filebase64("testdata/api_management_api_test.pfx") + certificate_password = "terraform" + default_ssl_binding = true + negotiate_client_certificate = false + } + + proxy { + host_name = "api2.terraform.io" + certificate = filebase64("testdata/api_management_api2_test.pfx") + certificate_password = "terraform" + negotiate_client_certificate = true + } + + portal { + host_name = "portal.terraform.io" + certificate = filebase64("testdata/api_management_portal_test.pfx") + certificate_password = "terraform" + } + + developer_portal { + host_name = "developer-portal.terraform.io" + certificate = filebase64("testdata/api_management_developer_portal_test.pfx") + } + } + + sku_name = "Premium_2" + + zones = [1, 2] + + tags = { + "Acceptance" = "Test" + } + + location = azurerm_resource_group.test1.location + resource_group_name = azurerm_resource_group.test1.name +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Secondary, data.RandomInteger, data.Locations.Ternary, data.RandomInteger) +} + func (ApiManagementResource) virtualNetworkTemplate(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { From 2c2231b4fed1f146446d2e668d1dc7db292bea8d Mon Sep 17 00:00:00 2001 From: jackofallops Date: Mon, 5 Jul 2021 06:23:47 +0100 Subject: [PATCH 3/3] goimports sorting --- .../internal/services/apimanagement/api_management_resource.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/azurerm/internal/services/apimanagement/api_management_resource.go b/azurerm/internal/services/apimanagement/api_management_resource.go index 91b89137b65d..6f096bd419ea 100644 --- a/azurerm/internal/services/apimanagement/api_management_resource.go +++ b/azurerm/internal/services/apimanagement/api_management_resource.go @@ -8,13 +8,12 @@ import ( "strings" "time" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/location" - "github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2020-12-01/apimanagement" "github.com/hashicorp/go-azure-helpers/response" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/location" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/apimanagement/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/apimanagement/schemaz" apimValidate "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/apimanagement/validate"