Skip to content

Commit

Permalink
Use HVNs with different names for different tests
Browse files Browse the repository at this point in the history
Without this tests will fail if they try to create HVNs with the same
name while running in parallel.
  • Loading branch information
tobias-hashicorp committed Feb 13, 2024
1 parent cbbf18a commit 8f0ede8
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 13 deletions.
3 changes: 1 addition & 2 deletions internal/providersdkv2/resource_aws_network_peering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"fmt"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import (
"fmt"
"os"
"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 (
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")
)
Expand Down
3 changes: 1 addition & 2 deletions internal/providersdkv2/resource_boundary_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ 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 (
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(`
Expand Down
3 changes: 1 addition & 2 deletions internal/providersdkv2/resource_hvn_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"
"regexp"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
Expand All @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions internal/providersdkv2/resource_hvn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -16,7 +15,7 @@ import (
)

var (
hvnUniqueID = fmt.Sprintf("hcp-provider-test-%s", time.Now().Format("200601021504"))
hvnUniqueID = uniqueName()
)

var testAccAwsHvnConfig = fmt.Sprintf(`
Expand Down
13 changes: 13 additions & 0 deletions internal/providersdkv2/unique_name.go
Original file line number Diff line number Diff line change
@@ -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))
}

0 comments on commit 8f0ede8

Please sign in to comment.