diff --git a/GNUmakefile b/GNUmakefile index c96f79c85..c6efb89c3 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -65,7 +65,7 @@ testacc-ci: fmtcheck echo "See the contributing guide for more information: https://github.com/hashicorp/terraform-provider-hcp/blob/main/contributing/writing-tests.md"; \ exit 1; \ fi - TF_ACC=1 go test -short -coverprofile=coverage-e2e.out $(TEST) -v $(TESTARGS) -timeout $(TIMEOUT) -parallel=10 + TF_ACC=1 go test -short -coverprofile=coverage-e2e.out $(TEST) -v $(TESTARGS) -timeout $(TIMEOUT) -parallel=100 go tool cover -html=coverage-e2e.out -o coverage-e2e.html depscheck: diff --git a/contributing/writing-tests.md b/contributing/writing-tests.md index 0b92a855e..fd79c133c 100644 --- a/contributing/writing-tests.md +++ b/contributing/writing-tests.md @@ -75,7 +75,7 @@ export TF_LOG=... Terraform has a framework for writing acceptance tests which minimizes the amount of boilerplate code necessary to use common testing patterns. The entry -point to the framework is the `resource.Test()` function. +point to the framework is the `resource.ParallelTest()` function. Tests are divided into `TestStep`s. Each `TestStep` proceeds by applying some Terraform configuration using the provider under test, and then verifying that @@ -88,7 +88,7 @@ to a single resource. Most tests follow a similar structure. to running acceptance tests. This is common to all tests exercising a single provider. -Each `TestStep` is defined in the call to `resource.Test()`. Most assertion +Each `TestStep` is defined in the call to `resource.ParallelTest()`. Most assertion functions are defined out of band with the tests. This keeps the tests readable, and allows reuse of assertion functions across different tests of the same type of resource. The definition of a complete test looks like this: @@ -97,7 +97,7 @@ same type of resource. The definition of a complete test looks like this: func TestAccConsulCluster(t *testing.T) { resourceName := "hcp_consul_cluster.test" - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProviderFactories: providerFactories, CheckDestroy: testAccCheckConsulClusterDestroy, diff --git a/internal/provider/iam/data_service_principal_test.go b/internal/provider/iam/data_service_principal_test.go index 380ae4dbf..e748d2be3 100644 --- a/internal/provider/iam/data_service_principal_test.go +++ b/internal/provider/iam/data_service_principal_test.go @@ -14,7 +14,7 @@ import ( func TestAccServicePrincipalDataSource(t *testing.T) { name := acctest.RandString(16) - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, PreCheck: func() { acctest.PreCheck(t) }, Steps: []resource.TestStep{ diff --git a/internal/provider/iam/resource_service_principal_key_test.go b/internal/provider/iam/resource_service_principal_key_test.go index 29f2b13bc..830ffbc3f 100644 --- a/internal/provider/iam/resource_service_principal_key_test.go +++ b/internal/provider/iam/resource_service_principal_key_test.go @@ -18,7 +18,7 @@ func TestAccServicePrincipalKeyResource(t *testing.T) { spName := acctest.RandString(16) var spk, spk2, spk3 models.HashicorpCloudIamServicePrincipalKey - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, PreCheck: func() { acctest.PreCheck(t) }, Steps: []resource.TestStep{ diff --git a/internal/provider/iam/resource_service_principal_test.go b/internal/provider/iam/resource_service_principal_test.go index a067760c1..9b95bcc2f 100644 --- a/internal/provider/iam/resource_service_principal_test.go +++ b/internal/provider/iam/resource_service_principal_test.go @@ -20,7 +20,7 @@ func TestAccServicePrincipalResource_Project(t *testing.T) { var sp models.HashicorpCloudIamServicePrincipal var sp2 models.HashicorpCloudIamServicePrincipal - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, PreCheck: func() { acctest.PreCheck(t) }, Steps: []resource.TestStep{ @@ -67,7 +67,7 @@ func TestAccServicePrincipalResource_ExplicitProject(t *testing.T) { spName := acctest.RandString(16) var sp models.HashicorpCloudIamServicePrincipal - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, PreCheck: func() { acctest.PreCheck(t) }, Steps: []resource.TestStep{ @@ -90,7 +90,7 @@ func TestAccServicePrincipalResource_Organization(t *testing.T) { spName := acctest.RandString(16) var sp models.HashicorpCloudIamServicePrincipal - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, PreCheck: func() { acctest.PreCheck(t) }, Steps: []resource.TestStep{ diff --git a/internal/provider/logstreaming/resource_hcp_log_streaming_destination_test.go b/internal/provider/logstreaming/resource_hcp_log_streaming_destination_test.go index 0f93596c5..b1a5ed773 100644 --- a/internal/provider/logstreaming/resource_hcp_log_streaming_destination_test.go +++ b/internal/provider/logstreaming/resource_hcp_log_streaming_destination_test.go @@ -26,7 +26,7 @@ func TestAccHCPLogStreamingDestinationSplunk(t *testing.T) { var sp models.LogService20210330Destination var sp2 models.LogService20210330Destination - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, CheckDestroy: func(s *terraform.State) error { diff --git a/internal/provider/resourcemanager/data_source_iam_policy_test.go b/internal/provider/resourcemanager/data_source_iam_policy_test.go index fddd74d4b..6022fd352 100644 --- a/internal/provider/resourcemanager/data_source_iam_policy_test.go +++ b/internal/provider/resourcemanager/data_source_iam_policy_test.go @@ -20,7 +20,7 @@ func TestAccIAMPolicyDataSource(t *testing.T) { role1, role2 := "roles/viewer", "roles/admin" var p1, p2 models.HashicorpCloudResourcemanagerPolicy - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, PreCheck: func() { acctest.PreCheck(t) }, Steps: []resource.TestStep{ @@ -80,7 +80,7 @@ func TestAccIAMPolicyDataSource_Validation(t *testing.T) { principals[i] = fmt.Sprintf("%d", i) } - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ IsUnitTest: true, ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, Steps: []resource.TestStep{ diff --git a/internal/provider/resourcemanager/data_source_organization_test.go b/internal/provider/resourcemanager/data_source_organization_test.go index 4022a5dbd..a4c37a7bc 100644 --- a/internal/provider/resourcemanager/data_source_organization_test.go +++ b/internal/provider/resourcemanager/data_source_organization_test.go @@ -12,7 +12,7 @@ import ( func TestAccOrganizationDataSource(t *testing.T) { dataSourceAddress := "data.hcp_organization.org" - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, PreCheck: func() { acctest.PreCheck(t) }, Steps: []resource.TestStep{ diff --git a/internal/provider/resourcemanager/data_source_project_test.go b/internal/provider/resourcemanager/data_source_project_test.go index 5e3367c05..c910d15bc 100644 --- a/internal/provider/resourcemanager/data_source_project_test.go +++ b/internal/provider/resourcemanager/data_source_project_test.go @@ -15,7 +15,7 @@ func TestAccProjectDataSource(t *testing.T) { project := acctest.RandString(16) description := acctest.RandString(64) - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, PreCheck: func() { acctest.PreCheck(t) }, Steps: []resource.TestStep{ diff --git a/internal/provider/resourcemanager/resource_organization_iam_policy_test.go b/internal/provider/resourcemanager/resource_organization_iam_policy_test.go index ac688d6bb..ac819e714 100644 --- a/internal/provider/resourcemanager/resource_organization_iam_policy_test.go +++ b/internal/provider/resourcemanager/resource_organization_iam_policy_test.go @@ -15,7 +15,7 @@ func TestAccOrganizationIamBindingResource(t *testing.T) { roleName := "roles/contributor" roleName2 := "roles/viewer" - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, PreCheck: func() { acctest.PreCheck(t) }, Steps: []resource.TestStep{ diff --git a/internal/provider/resourcemanager/resource_project_iam_policy_test.go b/internal/provider/resourcemanager/resource_project_iam_policy_test.go index 1ce27b9f1..255241ce4 100644 --- a/internal/provider/resourcemanager/resource_project_iam_policy_test.go +++ b/internal/provider/resourcemanager/resource_project_iam_policy_test.go @@ -16,7 +16,7 @@ func TestAccProjectIamPolicyResource(t *testing.T) { roleName := "roles/contributor" roleName2 := "roles/viewer" - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, PreCheck: func() { acctest.PreCheck(t) }, Steps: []resource.TestStep{ @@ -54,7 +54,7 @@ func TestAccProjectIamBindingResource(t *testing.T) { roleName := "roles/contributor" roleName2 := "roles/viewer" - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, PreCheck: func() { acctest.PreCheck(t) }, Steps: []resource.TestStep{ diff --git a/internal/provider/resourcemanager/resource_project_test.go b/internal/provider/resourcemanager/resource_project_test.go index 5d0972fca..8b8f9fead 100644 --- a/internal/provider/resourcemanager/resource_project_test.go +++ b/internal/provider/resourcemanager/resource_project_test.go @@ -21,7 +21,7 @@ func TestAccProjectResource(t *testing.T) { projectNameUpdated := acctest.RandString(16) descriptionUpdated := acctest.RandString(200) - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, PreCheck: func() { acctest.PreCheck(t) }, Steps: []resource.TestStep{ diff --git a/internal/provider/vaultsecrets/data_source_vault_secrets_app_test.go b/internal/provider/vaultsecrets/data_source_vault_secrets_app_test.go index 95a4954b0..e8daba8f0 100644 --- a/internal/provider/vaultsecrets/data_source_vault_secrets_app_test.go +++ b/internal/provider/vaultsecrets/data_source_vault_secrets_app_test.go @@ -26,7 +26,7 @@ func TestAcc_dataSourceVaultSecretsAppMigration(t *testing.T) { firstSecretValue := "hey, this is version 1!" secondSecretValue := "hey, this is version 2!" - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, Steps: []resource.TestStep{ // Create two secrets, one with an additional version and check the latest secrets from data source @@ -82,7 +82,7 @@ func TestAcc_dataSourceVaultSecretsApp(t *testing.T) { firstSecretValue := "hey, this is version 1!" secondSecretValue := "hey, this is version 2!" - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, Steps: []resource.TestStep{ diff --git a/internal/provider/vaultsecrets/data_source_vault_secrets_secret_test.go b/internal/provider/vaultsecrets/data_source_vault_secrets_secret_test.go index 5d696fa30..26447ce7c 100644 --- a/internal/provider/vaultsecrets/data_source_vault_secrets_secret_test.go +++ b/internal/provider/vaultsecrets/data_source_vault_secrets_secret_test.go @@ -18,7 +18,7 @@ func TestAcc_dataSourceVaultSecretsSecret(t *testing.T) { testSecretName := "secret_one" testSecretValue := "some value" - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, Steps: []resource.TestStep{ diff --git a/internal/provider/vaultsecrets/resource_vault_secrets_app_test.go b/internal/provider/vaultsecrets/resource_vault_secrets_app_test.go index 67b10f7cb..e65cbcaa9 100644 --- a/internal/provider/vaultsecrets/resource_vault_secrets_app_test.go +++ b/internal/provider/vaultsecrets/resource_vault_secrets_app_test.go @@ -13,7 +13,7 @@ import ( func TestAccVaultSecretsResourceApp(t *testing.T) { testAppName := generateRandomSlug() - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/provider/vaultsecrets/resource_vault_secrets_secret_test.go b/internal/provider/vaultsecrets/resource_vault_secrets_secret_test.go index 3926a6fe6..9b4059181 100644 --- a/internal/provider/vaultsecrets/resource_vault_secrets_secret_test.go +++ b/internal/provider/vaultsecrets/resource_vault_secrets_secret_test.go @@ -13,7 +13,7 @@ import ( func TestAccVaultSecretsResourceSecret(t *testing.T) { testAppName := generateRandomSlug() - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/providersdkv2/data_source_packer_image_test.go b/internal/providersdkv2/data_source_packer_image_test.go index 51cd40e37..ff2af416b 100644 --- a/internal/providersdkv2/data_source_packer_image_test.go +++ b/internal/providersdkv2/data_source_packer_image_test.go @@ -55,7 +55,7 @@ func TestAcc_dataSourcePackerImage_Simple(t *testing.T) { var iteration *models.HashicorpCloudPackerIteration var build *models.HashicorpCloudPackerBuild - resource.ParallelTest(t, resource.TestCase{ + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": false}) upsertRegistry(t) diff --git a/internal/providersdkv2/data_source_packer_iteration_test.go b/internal/providersdkv2/data_source_packer_iteration_test.go index d3b1e6d96..ac564c777 100644 --- a/internal/providersdkv2/data_source_packer_iteration_test.go +++ b/internal/providersdkv2/data_source_packer_iteration_test.go @@ -22,7 +22,7 @@ func TestAcc_dataSourcePackerIteration_Simple(t *testing.T) { var iteration *models.HashicorpCloudPackerIteration - resource.ParallelTest(t, resource.TestCase{ + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": false}) upsertRegistry(t) diff --git a/internal/providersdkv2/location_test.go b/internal/providersdkv2/location_test.go index 96c4b3c83..048c68109 100644 --- a/internal/providersdkv2/location_test.go +++ b/internal/providersdkv2/location_test.go @@ -111,7 +111,7 @@ func TestDetermineOldestProject(t *testing.T) { var projectID = "prov-project-id-invalid" func TestAccMultiProject(t *testing.T) { - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": false}) }, ProtoV6ProviderFactories: testProtoV6ProviderFactories, CheckDestroy: func(t *terraform.State) error { @@ -139,7 +139,7 @@ func TestAccMultiProject(t *testing.T) { } func TestAccMultiProjectResource(t *testing.T) { - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": false}) }, ProtoV6ProviderFactories: testProtoV6ProviderFactories, CheckDestroy: func(t *terraform.State) error { diff --git a/internal/providersdkv2/resource_aws_network_peering_test.go b/internal/providersdkv2/resource_aws_network_peering_test.go index a435d3e58..120a3ec0c 100644 --- a/internal/providersdkv2/resource_aws_network_peering_test.go +++ b/internal/providersdkv2/resource_aws_network_peering_test.go @@ -1,13 +1,14 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 +//go:build slow_tests + package providersdkv2 import ( "context" "fmt" "testing" - "time" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -16,7 +17,7 @@ import ( var ( // using unique names for AWS resource to make debugging easier - hvnPeeringUniqueAWSName = fmt.Sprintf("hcp-provider-test-%s", time.Now().Format("200601021504")) + hvnPeeringUniqueAWSName = uniqueName() testAccAwsPeeringConfig = fmt.Sprintf(` provider "aws" { region = "us-west-2" @@ -82,7 +83,7 @@ var ( func TestAccAwsPeering(t *testing.T) { resourceName := "hcp_aws_network_peering.peering" - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": true, "azure": false}) }, ProtoV6ProviderFactories: testProtoV6ProviderFactories, ExternalProviders: map[string]resource.ExternalProvider{ diff --git a/internal/providersdkv2/resource_aws_transit_gateway_attachment_test.go b/internal/providersdkv2/resource_aws_transit_gateway_attachment_test.go index 2ef59e711..4c0b6ed77 100644 --- a/internal/providersdkv2/resource_aws_transit_gateway_attachment_test.go +++ b/internal/providersdkv2/resource_aws_transit_gateway_attachment_test.go @@ -1,6 +1,8 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 +//go:build slow_tests + package providersdkv2 import ( @@ -108,7 +110,7 @@ var ( func TestAccTGWAttachment(t *testing.T) { resourceName := "hcp_aws_transit_gateway_attachment.example" - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": true, "azure": false}) }, ProtoV6ProviderFactories: testProtoV6ProviderFactories, ExternalProviders: map[string]resource.ExternalProvider{ diff --git a/internal/providersdkv2/resource_azure_peering_connection_test.go b/internal/providersdkv2/resource_azure_peering_connection_test.go index c5523bd82..ac9495387 100644 --- a/internal/providersdkv2/resource_azure_peering_connection_test.go +++ b/internal/providersdkv2/resource_azure_peering_connection_test.go @@ -1,6 +1,8 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 +//go:build slow_tests + package providersdkv2 import ( @@ -8,7 +10,6 @@ import ( "fmt" "os" "testing" - "time" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -16,7 +17,7 @@ import ( ) var ( - uniqueAzurePeeringTestID = fmt.Sprintf("hcp-provider-test-%s", time.Now().Format("200601021504")) + uniqueAzurePeeringTestID = uniqueName() subscriptionID = os.Getenv("ARM_SUBSCRIPTION_ID") tenantID = os.Getenv("ARM_TENANT_ID") ) @@ -188,7 +189,7 @@ func testAccAzurePeeringConnection(t *testing.T, adConfig string) { resourceName := "hcp_azure_peering_connection.peering" tfConfig := baseConfig("", adConfig) - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": true}) }, ProtoV6ProviderFactories: testProtoV6ProviderFactories, ExternalProviders: map[string]resource.ExternalProvider{ @@ -279,7 +280,7 @@ func testAccAzurePeeringConnectionNVA(t *testing.T, adConfig string) { resourceName := "hcp_azure_peering_connection.peering" tfConfig := baseConfig(peeringHubSpokeNVAConfig, adConfig) - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": true}) }, ProtoV6ProviderFactories: testProtoV6ProviderFactories, ExternalProviders: map[string]resource.ExternalProvider{ @@ -367,7 +368,7 @@ func testAccAzurePeeringConnectionGateway(t *testing.T, adConfig string) { resourceName := "hcp_azure_peering_connection.peering" tfConfig := baseConfig(peeringHubSpokeGatewayConfig, gatewayConfig(adConfig)) - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": true}) }, ProtoV6ProviderFactories: testProtoV6ProviderFactories, ExternalProviders: map[string]resource.ExternalProvider{ @@ -455,7 +456,7 @@ func testAccAzurePeeringConnectionNVAandGateway(t *testing.T, adConfig string) { resourceName := "hcp_azure_peering_connection.peering" tfConfig := baseConfig(peeringHubSpokeNVAandGatewayConfig, gatewayConfig(adConfig)) - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": true}) }, ProtoV6ProviderFactories: testProtoV6ProviderFactories, ExternalProviders: map[string]resource.ExternalProvider{ diff --git a/internal/providersdkv2/resource_boundary_cluster_test.go b/internal/providersdkv2/resource_boundary_cluster_test.go index 951f50888..13e5cac63 100644 --- a/internal/providersdkv2/resource_boundary_cluster_test.go +++ b/internal/providersdkv2/resource_boundary_cluster_test.go @@ -1,20 +1,21 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 +//go:build slow_tests + package providersdkv2 import ( "context" "fmt" "testing" - "time" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-hcp/internal/clients" ) -var boundaryUniqueID = fmt.Sprintf("hcp-provider-test-%s", time.Now().Format("200601021504")) +var boundaryUniqueID = uniqueName() var boundaryClusterResourceTemplate = fmt.Sprintf(` resource hcp_boundary_cluster "test" { @@ -52,7 +53,7 @@ func TestAccBoundaryCluster(t *testing.T) { boundaryClusterResourceName := "hcp_boundary_cluster.test" boundaryClusterDataSourceName := "data.hcp_boundary_cluster.test" - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": false}) }, ProtoV6ProviderFactories: testProtoV6ProviderFactories, CheckDestroy: testAccCheckBoundaryClusterDestroy, diff --git a/internal/providersdkv2/resource_consul_cluster_test.go b/internal/providersdkv2/resource_consul_cluster_test.go index 3b5877499..1629c4138 100644 --- a/internal/providersdkv2/resource_consul_cluster_test.go +++ b/internal/providersdkv2/resource_consul_cluster_test.go @@ -1,6 +1,8 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 +//go:build slow_tests + package providersdkv2 import ( @@ -101,7 +103,7 @@ func TestAccConsulCluster(t *testing.T) { dataSourceVersionName := "data.hcp_consul_versions.test" rootTokenResourceName := "hcp_consul_cluster_root_token.test" - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": false}) }, ProtoV6ProviderFactories: testProtoV6ProviderFactories, CheckDestroy: testAccCheckConsulClusterDestroy, diff --git a/internal/providersdkv2/resource_consul_snapshot_test.go b/internal/providersdkv2/resource_consul_snapshot_test.go index 1ec59ed51..fa84efa30 100644 --- a/internal/providersdkv2/resource_consul_snapshot_test.go +++ b/internal/providersdkv2/resource_consul_snapshot_test.go @@ -1,6 +1,8 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 +//go:build slow_tests + package providersdkv2 import ( @@ -38,7 +40,7 @@ resource "hcp_consul_snapshot" "test" { func TestAccConsulSnapshot(t *testing.T) { resourceName := "hcp_consul_snapshot.test" - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": false}) }, ProtoV6ProviderFactories: testProtoV6ProviderFactories, CheckDestroy: testAccCheckConsulSnapshotDestroy, diff --git a/internal/providersdkv2/resource_hvn_peering_connection_test.go b/internal/providersdkv2/resource_hvn_peering_connection_test.go index 211c8e9b5..d7f69485f 100644 --- a/internal/providersdkv2/resource_hvn_peering_connection_test.go +++ b/internal/providersdkv2/resource_hvn_peering_connection_test.go @@ -1,13 +1,14 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 +//go:build slow_tests + package providersdkv2 import ( "context" "fmt" "testing" - "time" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -15,8 +16,8 @@ import ( ) var ( - hvn1UniqueID = fmt.Sprintf("hcp-provider-test-%s-1", time.Now().Format("200601021504")) - hvn2UniqueID = fmt.Sprintf("hcp-provider-test-%s-2", time.Now().Format("200601021504")) + hvn1UniqueID = uniqueName() + hvn2UniqueID = uniqueName() ) var testAccHvnPeeringConnectionConfig = fmt.Sprintf(` @@ -51,7 +52,7 @@ func TestAccHvnPeeringConnection(t *testing.T) { resourceName := "hcp_hvn_peering_connection.test" dataSourceName := "data.hcp_hvn_peering_connection.test" - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": false}) }, ProtoV6ProviderFactories: testProtoV6ProviderFactories, CheckDestroy: testAccCheckHvnPeeringConnectionDestroy, diff --git a/internal/providersdkv2/resource_hvn_route_test.go b/internal/providersdkv2/resource_hvn_route_test.go index 71c051f88..367856862 100644 --- a/internal/providersdkv2/resource_hvn_route_test.go +++ b/internal/providersdkv2/resource_hvn_route_test.go @@ -1,14 +1,16 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 +//go:build slow_tests + package providersdkv2 import ( "context" "fmt" + "os" "regexp" "testing" - "time" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -17,7 +19,7 @@ import ( var ( // using unique names for resources to make debugging easier - hvnRouteUniqueName = fmt.Sprintf("hcp-provider-test-%s", time.Now().Format("200601021504")) + hvnRouteUniqueName = uniqueName() testAccHvnRouteConfigAws = fmt.Sprintf(` provider "aws" { region = "us-west-2" @@ -81,6 +83,9 @@ var ( // Azure config func testAccHvnRouteConfigAzure(azConfig, optConfig string) string { + subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") + tenantID := os.Getenv("ARM_TENANT_ID") + return fmt.Sprintf(` provider "azurerm" { features {} @@ -359,7 +364,7 @@ var azConfigNVA = ` func TestAccHvnRouteAws(t *testing.T) { resourceName := "hcp_hvn_route.route" - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": true, "azure": false}) }, ProtoV6ProviderFactories: testProtoV6ProviderFactories, ExternalProviders: map[string]resource.ExternalProvider{ @@ -429,7 +434,7 @@ func TestAccHvnRouteAzureGatewayInternal(t *testing.T) { func testHvnRouteGateway(t *testing.T, adConfig string) { resourceName := "hcp_hvn_route.route" - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": true}) }, ProtoV6ProviderFactories: testProtoV6ProviderFactories, ExternalProviders: map[string]resource.ExternalProvider{ @@ -498,7 +503,7 @@ func TestAccHvnRouteAzureInvalidConfigInternal(t *testing.T) { } func testHvnRouteInvalidConfig(t *testing.T, adConfig string) { - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": true}) }, ProtoV6ProviderFactories: testProtoV6ProviderFactories, ExternalProviders: map[string]resource.ExternalProvider{ @@ -530,7 +535,7 @@ func TestAccHvnRouteAzureNVAInternal(t *testing.T) { func testHvnRouteNVA(t *testing.T, adConfig string) { resourceName := "hcp_hvn_route.route" - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": true}) }, ProtoV6ProviderFactories: testProtoV6ProviderFactories, ExternalProviders: map[string]resource.ExternalProvider{ diff --git a/internal/providersdkv2/resource_hvn_test.go b/internal/providersdkv2/resource_hvn_test.go index 8b9c9c935..a5e7e3af6 100644 --- a/internal/providersdkv2/resource_hvn_test.go +++ b/internal/providersdkv2/resource_hvn_test.go @@ -1,13 +1,14 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 +//go:build slow_tests + package providersdkv2 import ( "context" "fmt" "testing" - "time" sharedmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -16,7 +17,8 @@ import ( ) var ( - hvnUniqueID = fmt.Sprintf("hcp-provider-test-%s", time.Now().Format("200601021504")) + awsHVNUniqueID = uniqueName() + azureHVNUniqueID = uniqueName() ) var testAccAwsHvnConfig = fmt.Sprintf(` @@ -29,7 +31,7 @@ resource "hcp_hvn" "test" { data "hcp_hvn" "test" { hvn_id = hcp_hvn.test.hvn_id } -`, hvnUniqueID) +`, awsHVNUniqueID) // Currently in public beta var testAccAzureHvnConfig = fmt.Sprintf(` @@ -42,7 +44,7 @@ resource "hcp_hvn" "test" { data "hcp_hvn" "test" { hvn_id = hcp_hvn.test.hvn_id } -`, hvnUniqueID) +`, azureHVNUniqueID) // This includes tests against both the resource and the corresponding datasource // to shorten testing time. @@ -50,7 +52,7 @@ func TestAccAwsHvnOnly(t *testing.T) { resourceName := "hcp_hvn.test" dataSourceName := "data.hcp_hvn.test" - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": false}) }, ProtoV6ProviderFactories: testProtoV6ProviderFactories, CheckDestroy: testAccCheckHvnDestroy, @@ -60,7 +62,7 @@ func TestAccAwsHvnOnly(t *testing.T) { Config: testConfig(testAccAwsHvnConfig), Check: resource.ComposeTestCheckFunc( testAccCheckHvnExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "hvn_id", hvnUniqueID), + resource.TestCheckResourceAttr(resourceName, "hvn_id", awsHVNUniqueID), resource.TestCheckResourceAttr(resourceName, "cloud_provider", "aws"), resource.TestCheckResourceAttr(resourceName, "region", "us-west-2"), resource.TestCheckResourceAttrSet(resourceName, "cidr_block"), @@ -69,7 +71,7 @@ func TestAccAwsHvnOnly(t *testing.T) { resource.TestCheckResourceAttrSet(resourceName, "created_at"), resource.TestCheckResourceAttrSet(resourceName, "provider_account_id"), resource.TestCheckResourceAttrSet(resourceName, "state"), - testLink(resourceName, "self_link", hvnUniqueID, HvnResourceType, resourceName), + testLink(resourceName, "self_link", awsHVNUniqueID, HvnResourceType, resourceName), ), }, // Tests import @@ -91,7 +93,7 @@ func TestAccAwsHvnOnly(t *testing.T) { Config: testConfig(testAccAwsHvnConfig), Check: resource.ComposeTestCheckFunc( testAccCheckHvnExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "hvn_id", hvnUniqueID), + resource.TestCheckResourceAttr(resourceName, "hvn_id", awsHVNUniqueID), resource.TestCheckResourceAttr(resourceName, "cloud_provider", "aws"), resource.TestCheckResourceAttr(resourceName, "region", "us-west-2"), resource.TestCheckResourceAttrSet(resourceName, "cidr_block"), @@ -100,7 +102,7 @@ func TestAccAwsHvnOnly(t *testing.T) { resource.TestCheckResourceAttrSet(resourceName, "created_at"), resource.TestCheckResourceAttrSet(resourceName, "provider_account_id"), resource.TestCheckResourceAttrSet(resourceName, "state"), - testLink(resourceName, "self_link", hvnUniqueID, HvnResourceType, resourceName), + testLink(resourceName, "self_link", awsHVNUniqueID, HvnResourceType, resourceName), ), }, // Tests datasource @@ -127,7 +129,7 @@ func TestAccAzureHvnOnly(t *testing.T) { resourceName := "hcp_hvn.test" dataSourceName := "data.hcp_hvn.test" - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": false}) }, ProtoV6ProviderFactories: testProtoV6ProviderFactories, CheckDestroy: testAccCheckHvnDestroy, @@ -137,7 +139,7 @@ func TestAccAzureHvnOnly(t *testing.T) { Config: testConfig(testAccAzureHvnConfig), Check: resource.ComposeTestCheckFunc( testAccCheckHvnExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "hvn_id", hvnUniqueID), + resource.TestCheckResourceAttr(resourceName, "hvn_id", azureHVNUniqueID), resource.TestCheckResourceAttr(resourceName, "cloud_provider", "azure"), resource.TestCheckResourceAttr(resourceName, "region", "eastus"), resource.TestCheckResourceAttrSet(resourceName, "cidr_block"), @@ -145,7 +147,7 @@ func TestAccAzureHvnOnly(t *testing.T) { resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttrSet(resourceName, "created_at"), resource.TestCheckResourceAttrSet(resourceName, "state"), - testLink(resourceName, "self_link", hvnUniqueID, HvnResourceType, resourceName), + testLink(resourceName, "self_link", azureHVNUniqueID, HvnResourceType, resourceName), ), }, // Tests import @@ -167,7 +169,7 @@ func TestAccAzureHvnOnly(t *testing.T) { Config: testConfig(testAccAzureHvnConfig), Check: resource.ComposeTestCheckFunc( testAccCheckHvnExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "hvn_id", hvnUniqueID), + resource.TestCheckResourceAttr(resourceName, "hvn_id", azureHVNUniqueID), resource.TestCheckResourceAttr(resourceName, "cloud_provider", "azure"), resource.TestCheckResourceAttr(resourceName, "region", "eastus"), resource.TestCheckResourceAttrSet(resourceName, "cidr_block"), @@ -175,7 +177,7 @@ func TestAccAzureHvnOnly(t *testing.T) { resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttrSet(resourceName, "created_at"), resource.TestCheckResourceAttrSet(resourceName, "state"), - testLink(resourceName, "self_link", hvnUniqueID, HvnResourceType, resourceName), + testLink(resourceName, "self_link", azureHVNUniqueID, HvnResourceType, resourceName), ), }, // Tests datasource diff --git a/internal/providersdkv2/resource_packer_channel_assignment_test.go b/internal/providersdkv2/resource_packer_channel_assignment_test.go index 78f2210f0..a0b1535c2 100644 --- a/internal/providersdkv2/resource_packer_channel_assignment_test.go +++ b/internal/providersdkv2/resource_packer_channel_assignment_test.go @@ -24,7 +24,7 @@ func TestAccPackerChannelAssignment_SimpleSetUnset(t *testing.T) { baseAssignment := testAccPackerAssignmentBuilderBase("SimpleSetUnset", fmt.Sprintf("%q", bucketSlug), fmt.Sprintf("%q", channelSlug)) - resource.ParallelTest(t, resource.TestCase{ + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": false}) upsertRegistry(t) diff --git a/internal/providersdkv2/resource_packer_channel_test.go b/internal/providersdkv2/resource_packer_channel_test.go index 7f3a844bc..fa34caa34 100644 --- a/internal/providersdkv2/resource_packer_channel_test.go +++ b/internal/providersdkv2/resource_packer_channel_test.go @@ -18,7 +18,7 @@ func TestAccPackerChannel(t *testing.T) { unrestrictedChannelConfig := testAccPackerChannelBuilderFromChannel(channelConfig, "false") restrictedChannelConfig := testAccPackerChannelBuilderFromChannel(channelConfig, "true") - resource.ParallelTest(t, resource.TestCase{ + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": false}) upsertRegistry(t) diff --git a/internal/providersdkv2/resource_vault_cluster_const_test.go b/internal/providersdkv2/resource_vault_cluster_const_test.go index 097585789..35b16a41e 100644 --- a/internal/providersdkv2/resource_vault_cluster_const_test.go +++ b/internal/providersdkv2/resource_vault_cluster_const_test.go @@ -1,6 +1,8 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 +//go:build slow_tests + package providersdkv2 import ( diff --git a/internal/providersdkv2/resource_vault_cluster_perf_replication_test.go b/internal/providersdkv2/resource_vault_cluster_perf_replication_test.go index de645e138..2337b8401 100644 --- a/internal/providersdkv2/resource_vault_cluster_perf_replication_test.go +++ b/internal/providersdkv2/resource_vault_cluster_perf_replication_test.go @@ -1,6 +1,8 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 +//go:build slow_tests + package providersdkv2 import ( @@ -71,7 +73,7 @@ func TestAccPerformanceReplication_ValidationsAws(t *testing.T) { }, } - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": false}) }, ProtoV6ProviderFactories: testProtoV6ProviderFactories, CheckDestroy: testAccCheckVaultClusterDestroy, diff --git a/internal/providersdkv2/resource_vault_cluster_test.go b/internal/providersdkv2/resource_vault_cluster_test.go index 533212d51..ced80429c 100644 --- a/internal/providersdkv2/resource_vault_cluster_test.go +++ b/internal/providersdkv2/resource_vault_cluster_test.go @@ -1,6 +1,8 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 +//go:build slow_tests + package providersdkv2 import ( @@ -44,8 +46,8 @@ func (in *inputT) GetHvnCidr() string { // to shorten testing time. func TestAccVaultClusterAzure(t *testing.T) { azureTestInput := inputT{ - VaultClusterName: addTimestampSuffix("test-vault-azure-"), - HvnName: addTimestampSuffix("test-hvn-azure-"), + VaultClusterName: uniqueName(), + HvnName: uniqueName(), VaultClusterResourceName: vaultClusterResourceName, VaultClusterDataSourceName: vaultClusterDataSourceName, AdminTokenResourceName: adminTokenResourceName, @@ -72,8 +74,8 @@ func TestAccVaultClusterAzure(t *testing.T) { // to shorten testing time. func TestAccVaultClusterAWS(t *testing.T) { awsTestInput := inputT{ - VaultClusterName: addTimestampSuffix("test-vault-aws-"), - HvnName: addTimestampSuffix("test-hvn-aws-"), + VaultClusterName: uniqueName(), + HvnName: uniqueName(), VaultClusterResourceName: vaultClusterResourceName, VaultClusterDataSourceName: vaultClusterDataSourceName, AdminTokenResourceName: adminTokenResourceName, diff --git a/internal/providersdkv2/resource_vault_plugin_test.go b/internal/providersdkv2/resource_vault_plugin_test.go index a746510de..70c4e4ed3 100644 --- a/internal/providersdkv2/resource_vault_plugin_test.go +++ b/internal/providersdkv2/resource_vault_plugin_test.go @@ -1,6 +1,8 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 +//go:build slow_tests + package providersdkv2 import ( @@ -51,7 +53,7 @@ func TestAccVaultPlugin(t *testing.T) { resourceName := "hcp_vault_plugin.venafi_plugin" dataSourceName := "data.hcp_vault_plugin.test" - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": false}) }, ProtoV6ProviderFactories: testProtoV6ProviderFactories, CheckDestroy: testAccCheckVaultPluginDestroy, diff --git a/internal/providersdkv2/test_helpers_test.go b/internal/providersdkv2/test_helpers_test.go index a1feda9fc..16c2aae07 100644 --- a/internal/providersdkv2/test_helpers_test.go +++ b/internal/providersdkv2/test_helpers_test.go @@ -1,6 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 +// nolint:unused package providersdkv2 import ( diff --git a/internal/providersdkv2/unique_name.go b/internal/providersdkv2/unique_name.go new file mode 100644 index 000000000..334a25e27 --- /dev/null +++ b/internal/providersdkv2/unique_name.go @@ -0,0 +1,15 @@ +//go:build slow_tests + +package providersdkv2 + +import ( + "math/rand" + "strconv" + "time" +) + +// uniqueName will generate a unique name that is <= 36 characters long. +// E.g. hcp-provider-20060102150405-1234567 +func uniqueName() string { + return "hcp-provider-" + time.Now().Format("20060102150405") + "-" + strconv.Itoa(rand.Intn(10000000)) +}