diff --git a/internal/providersdkv2/resource_aws_network_peering_test.go b/internal/providersdkv2/resource_aws_network_peering_test.go index 206f2061d..26f89449e 100644 --- a/internal/providersdkv2/resource_aws_network_peering_test.go +++ b/internal/providersdkv2/resource_aws_network_peering_test.go @@ -7,7 +7,6 @@ import ( "context" "fmt" "testing" - "time" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -16,7 +15,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" diff --git a/internal/providersdkv2/resource_azure_peering_connection_test.go b/internal/providersdkv2/resource_azure_peering_connection_test.go index 1e08f48c9..33ed80f0c 100644 --- a/internal/providersdkv2/resource_azure_peering_connection_test.go +++ b/internal/providersdkv2/resource_azure_peering_connection_test.go @@ -8,7 +8,6 @@ import ( "fmt" "os" "testing" - "time" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -16,7 +15,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") ) diff --git a/internal/providersdkv2/resource_boundary_cluster_test.go b/internal/providersdkv2/resource_boundary_cluster_test.go index 6c99d3290..9314715b0 100644 --- a/internal/providersdkv2/resource_boundary_cluster_test.go +++ b/internal/providersdkv2/resource_boundary_cluster_test.go @@ -7,14 +7,13 @@ 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" { diff --git a/internal/providersdkv2/resource_hvn_peering_connection_test.go b/internal/providersdkv2/resource_hvn_peering_connection_test.go index bdd7b6ea2..8ff6b3da8 100644 --- a/internal/providersdkv2/resource_hvn_peering_connection_test.go +++ b/internal/providersdkv2/resource_hvn_peering_connection_test.go @@ -7,7 +7,6 @@ import ( "context" "fmt" "testing" - "time" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -15,8 +14,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(` diff --git a/internal/providersdkv2/resource_hvn_route_test.go b/internal/providersdkv2/resource_hvn_route_test.go index 229d54ac2..6efb07a92 100644 --- a/internal/providersdkv2/resource_hvn_route_test.go +++ b/internal/providersdkv2/resource_hvn_route_test.go @@ -8,7 +8,6 @@ import ( "fmt" "regexp" "testing" - "time" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -17,7 +16,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" diff --git a/internal/providersdkv2/resource_hvn_test.go b/internal/providersdkv2/resource_hvn_test.go index 5061e0b09..107447f55 100644 --- a/internal/providersdkv2/resource_hvn_test.go +++ b/internal/providersdkv2/resource_hvn_test.go @@ -7,7 +7,6 @@ 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 +15,7 @@ import ( ) var ( - hvnUniqueID = fmt.Sprintf("hcp-provider-test-%s", time.Now().Format("200601021504")) + hvnUniqueID = uniqueName() ) var testAccAwsHvnConfig = fmt.Sprintf(` diff --git a/internal/providersdkv2/unique_name.go b/internal/providersdkv2/unique_name.go new file mode 100644 index 000000000..217416c8a --- /dev/null +++ b/internal/providersdkv2/unique_name.go @@ -0,0 +1,13 @@ +package providersdkv2 + +import ( + "math/rand" + "strconv" + "time" +) + +// uniqueName will generate a unique name that is <= 36 characters long. +// E.g. hcp-provider-test-20060102150405-123 +func uniqueName() string { + return "hcp-provider-test-" + time.Now().Format("20060102150405") + "-" + strconv.Itoa(rand.Intn(1000)) +}