From 0ec84999b2a9f3c26d3280a3b3329175fcf7dcac Mon Sep 17 00:00:00 2001 From: jayctran Date: Tue, 18 Jun 2024 19:33:13 +1000 Subject: [PATCH] Fixed gradually deprecated functions --- ...rnetes_flux_configuration_resource_test.go | 50 ++++++++++++++----- ...rnetes_flux_configuration_resource_test.go | 50 ++++++++++++++----- 2 files changed, 74 insertions(+), 26 deletions(-) diff --git a/internal/services/arckubernetes/arc_kubernetes_flux_configuration_resource_test.go b/internal/services/arckubernetes/arc_kubernetes_flux_configuration_resource_test.go index 7db4da1a79c65..3dac7219cc5fb 100644 --- a/internal/services/arckubernetes/arc_kubernetes_flux_configuration_resource_test.go +++ b/internal/services/arckubernetes/arc_kubernetes_flux_configuration_resource_test.go @@ -517,6 +517,20 @@ func (r ArcKubernetesFluxConfigurationResource) azureBlobWithServicePrincipalSec return fmt.Sprintf(` %[1]s +provider "azuread" {} + +resource "azuread_application" "test" { + display_name = "acctestspa-%[2]d" +} + +resource "azuread_service_principal" "test" { + application_id = azuread_application.test.application_id +} + +resource "azuread_service_principal_password" "test" { + service_principal_id = azuread_service_principal.test.object_id +} + resource "azurerm_storage_account" "test" { name = "sa%[2]d" resource_group_name = azurerm_resource_group.test.name @@ -537,13 +551,13 @@ data "azurerm_client_config" "test" { resource "azurerm_role_assignment" "test_queue" { scope = azurerm_storage_account.test.id role_definition_name = "Storage Queue Data Contributor" - principal_id = data.azurerm_client_config.test.object_id + principal_id = azuread_service_principal.test.object_id } resource "azurerm_role_assignment" "test_blob" { scope = azurerm_storage_account.test.id role_definition_name = "Storage Blob Data Contributor" - principal_id = data.azurerm_client_config.test.object_id + principal_id = azuread_service_principal.test.object_id } resource "azurerm_arc_kubernetes_flux_configuration" "test" { @@ -554,9 +568,9 @@ resource "azurerm_arc_kubernetes_flux_configuration" "test" { blob_storage { container_id = azurerm_storage_container.test.id service_principal { - client_id = "%[3]s" - tenant_id = "%[4]s" - client_secret = "%[5]s" + client_id = azuread_service_principal.test.client_id + tenant_id = data.azurerm_client_config.test.tenant_id + client_secret = azuread_service_principal_password.test.value } } @@ -570,13 +584,23 @@ resource "azurerm_arc_kubernetes_flux_configuration" "test" { azurerm_role_assignment.test_blob ] } -`, r.template(data, credential, privateKey, publicKey), data.RandomInteger, os.Getenv("ARM_CLIENT_ID"), os.Getenv("ARM_TENANT_ID"), os.Getenv("ARM_CLIENT_SECRET")) +`, r.template(data, credential, privateKey, publicKey), data.RandomInteger) } func (r ArcKubernetesFluxConfigurationResource) azureBlobWithServicePrincipalCertificate(data acceptance.TestData, credential string, privateKey string, publicKey string) string { return fmt.Sprintf(` %[1]s +provider "azuread" {} + +resource "azuread_application" "test" { + display_name = "acctestspa-%[2]d" +} + +resource "azuread_service_principal" "test" { + application_id = azuread_application.test.application_id +} + resource "azurerm_storage_account" "test" { name = "sa%[2]d" resource_group_name = azurerm_resource_group.test.name @@ -597,13 +621,13 @@ data "azurerm_client_config" "test" { resource "azurerm_role_assignment" "test_queue" { scope = azurerm_storage_account.test.id role_definition_name = "Storage Queue Data Contributor" - principal_id = data.azurerm_client_config.test.object_id + principal_id = azuread_service_principal.test.object_id } resource "azurerm_role_assignment" "test_blob" { scope = azurerm_storage_account.test.id role_definition_name = "Storage Blob Data Contributor" - principal_id = data.azurerm_client_config.test.object_id + principal_id = azuread_service_principal.test.object_id } resource "azurerm_arc_kubernetes_flux_configuration" "test" { @@ -614,10 +638,10 @@ resource "azurerm_arc_kubernetes_flux_configuration" "test" { blob_storage { container_id = azurerm_storage_container.test.id service_principal { - client_id = "%[3]s" - tenant_id = "%[4]s" - client_certificate_base64 = "%[5]s" - client_certificate_password = "%[6]s" + client_id = azuread_service_principal.test.client_id + tenant_id = data.azurerm_client_config.test.tenant_id + client_certificate_base64 = "%[3]s" + client_certificate_password = "%[4]s" client_certificate_send_chain = true } } @@ -632,7 +656,7 @@ resource "azurerm_arc_kubernetes_flux_configuration" "test" { azurerm_role_assignment.test_blob ] } -`, r.template(data, credential, privateKey, publicKey), data.RandomInteger, os.Getenv("ARM_CLIENT_ID"), os.Getenv("ARM_TENANT_ID"), os.Getenv("ARM_CLIENT_CERTIFICATE"), os.Getenv("ARM_CLIENT_CERTIFICATE_PASSWORD")) +`, r.template(data, credential, privateKey, publicKey), data.RandomInteger, os.Getenv("ARM_CLIENT_CERTIFICATE"), os.Getenv("ARM_CLIENT_CERTIFICATE_PASSWORD")) } func (r ArcKubernetesFluxConfigurationResource) kustomizationNameDuplicated(data acceptance.TestData, credential string, privateKey string, publicKey string) string { diff --git a/internal/services/containers/kubernetes_flux_configuration_resource_test.go b/internal/services/containers/kubernetes_flux_configuration_resource_test.go index 449a5a1e41f66..db47480462e17 100644 --- a/internal/services/containers/kubernetes_flux_configuration_resource_test.go +++ b/internal/services/containers/kubernetes_flux_configuration_resource_test.go @@ -580,6 +580,20 @@ func (r KubernetesFluxConfigurationResource) azureBlobWithServicePrincipalSecret return fmt.Sprintf(` %[1]s +provider "azuread" {} + +resource "azuread_application" "test" { + display_name = "acctestspa-%[2]d" +} + +resource "azuread_service_principal" "test" { + application_id = azuread_application.test.application_id +} + +resource "azuread_service_principal_password" "test" { + service_principal_id = azuread_service_principal.test.object_id +} + resource "azurerm_storage_account" "test" { name = "sa%[2]d" resource_group_name = azurerm_resource_group.test.name @@ -600,13 +614,13 @@ data "azurerm_client_config" "test" { resource "azurerm_role_assignment" "test_queue" { scope = azurerm_storage_account.test.id role_definition_name = "Storage Queue Data Contributor" - principal_id = data.azurerm_client_config.test.object_id + principal_id = azuread_service_principal.test.object_id } resource "azurerm_role_assignment" "test_blob" { scope = azurerm_storage_account.test.id role_definition_name = "Storage Blob Data Contributor" - principal_id = data.azurerm_client_config.test.object_id + principal_id = azuread_service_principal.test.object_id } resource "azurerm_kubernetes_flux_configuration" "test" { @@ -617,9 +631,9 @@ resource "azurerm_kubernetes_flux_configuration" "test" { blob_storage { container_id = azurerm_storage_container.test.id service_principal { - client_id = "%[3]s" - tenant_id = "%[4]s" - client_secret = "%[5]s" + client_id = azuread_service_principal.test.client_id + tenant_id = data.azurerm_client_config.test.tenant_id + client_secret = azuread_service_principal_password.test.value } } @@ -633,13 +647,23 @@ resource "azurerm_kubernetes_flux_configuration" "test" { azurerm_role_assignment.test_blob ] } -`, r.template(data), data.RandomInteger, os.Getenv("ARM_CLIENT_ID"), os.Getenv("ARM_TENANT_ID"), os.Getenv("ARM_CLIENT_SECRET")) +`, r.template(data), data.RandomInteger) } func (r KubernetesFluxConfigurationResource) azureBlobWithServicePrincipalCertificate(data acceptance.TestData) string { return fmt.Sprintf(` %[1]s +provider "azuread" {} + +resource "azuread_application" "test" { + display_name = "acctestspa-%[2]d" +} + +resource "azuread_service_principal" "test" { + application_id = azuread_application.test.application_id +} + resource "azurerm_storage_account" "test" { name = "sa%[2]d" resource_group_name = azurerm_resource_group.test.name @@ -660,13 +684,13 @@ data "azurerm_client_config" "test" { resource "azurerm_role_assignment" "test_queue" { scope = azurerm_storage_account.test.id role_definition_name = "Storage Queue Data Contributor" - principal_id = data.azurerm_client_config.test.object_id + principal_id = azuread_service_principal.test.object_id } resource "azurerm_role_assignment" "test_blob" { scope = azurerm_storage_account.test.id role_definition_name = "Storage Blob Data Contributor" - principal_id = data.azurerm_client_config.test.object_id + principal_id = azuread_service_principal.test.object_id } resource "azurerm_kubernetes_flux_configuration" "test" { @@ -677,10 +701,10 @@ resource "azurerm_kubernetes_flux_configuration" "test" { blob_storage { container_id = azurerm_storage_container.test.id service_principal { - client_id = "%[3]s" - tenant_id = "%[4]s" - client_certificate_base64 = "%[5]s" - client_certificate_password = "%[6]s" + client_id = azuread_service_principal.test.client_id + tenant_id = data.azurerm_client_config.test.tenant_id + client_certificate_base64 = "%[3]s" + client_certificate_password = "%[4]s" client_certificate_send_chain = true } } @@ -695,7 +719,7 @@ resource "azurerm_kubernetes_flux_configuration" "test" { azurerm_role_assignment.test_blob ] } -`, r.template(data), data.RandomInteger, os.Getenv("ARM_CLIENT_ID"), os.Getenv("ARM_TENANT_ID"), os.Getenv("ARM_CLIENT_CERTIFICATE"), os.Getenv("ARM_CLIENT_CERTIFICATE_PASSWORD")) +`, r.template(data), data.RandomInteger, os.Getenv("ARM_CLIENT_CERTIFICATE"), os.Getenv("ARM_CLIENT_CERTIFICATE_PASSWORD")) } func (r KubernetesFluxConfigurationResource) kustomizationNameDuplicated(data acceptance.TestData) string {