Skip to content

Commit

Permalink
HCPCP-1928 Update Vault testacc to use unique hvn names
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonpilz committed Dec 11, 2024
1 parent 3aaf4b3 commit 2affe4d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

var (
// using unique names for AWS resource to make debugging easier
hvnPeeringUniqueAWSName = testAccPlatformUniqueName()
hvnPeeringUniqueAWSName = testAccUniqueNameWithPrefix("platform-hvn-peer")
testAccAwsPeeringConfig = fmt.Sprintf(`
provider "aws" {
region = "us-west-2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (

var (
// using unique names for AWS resource to make debugging easier
tgwAttUniqueAWSName = testAccPlatformUniqueName()
tgwAttUniqueHvnName = testAccPlatformUniqueName()
tgwAttUniqueAWSName = testAccUniqueNameWithPrefix("platform-tgw")
tgwAttUniqueHvnName = testAccUniqueNameWithPrefix("platform-hvn")
testAccTGWAttachmentConfig = fmt.Sprintf(`
provider "aws" {
region = "us-west-2"
Expand Down
12 changes: 2 additions & 10 deletions internal/providersdkv2/resource_hvn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ import (
"fmt"
"testing"

"github.com/google/uuid"

sharedmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/hashicorp/terraform-provider-hcp/internal/clients"
)

var (
hvnUniqueIDAws = testAccPlatformUniqueName()
hvnUniqueIDAzure = testAccPlatformUniqueName()
hvnUniqueIDAws = testAccUniqueNameWithPrefix("platform-hvn")
hvnUniqueIDAzure = testAccUniqueNameWithPrefix("platform-hvn")
)

var testAccAwsHvnConfig = fmt.Sprintf(`
Expand Down Expand Up @@ -46,12 +44,6 @@ data "hcp_hvn" "test" {
}
`, hvnUniqueIDAzure)

func testAccPlatformUniqueName() string {
shortUUID := uuid.New().String()[0:8]

return fmt.Sprintf("testacc-platform-%s", shortUUID)
}

// This includes tests against both the resource and the corresponding datasource
// to shorten testing time.
func TestAcc_Platform_Hvn_Aws(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/providersdkv2/resource_vault_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestAcc_Vault_ClusterAzure(t *testing.T) {
func TestAcc_Vault_ClusterAWS(t *testing.T) {
awsTestInput := inputT{
VaultClusterName: addTimestampSuffix("test-vault-aws-"),
HvnName: addTimestampSuffix("test-hvn-aws-"),
HvnName: testAccUniqueNameWithPrefix("vault-hvn-aws-"),
VaultClusterResourceName: vaultClusterResourceName,
VaultClusterDataSourceName: vaultClusterDataSourceName,
AdminTokenResourceName: adminTokenResourceName,
Expand Down
2 changes: 1 addition & 1 deletion internal/providersdkv2/resource_vault_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ resource "hcp_vault_plugin" "venafi_plugin" {
plugin_name = "venafi-pki-backend"
plugin_type = "SECRET"
}
`, addTimestampSuffix("test-hvn-aws-"), addTimestampSuffix("test-cluster-"))
`, testAccUniqueNameWithPrefix("vault-hvn-aws-"), addTimestampSuffix("test-cluster-"))

testAccVaultPluginDataSourceConfig = fmt.Sprintf(`%s
data "hcp_vault_plugin" "test" {
Expand Down
8 changes: 8 additions & 0 deletions internal/providersdkv2/test_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"strings"
"time"

"github.com/google/uuid"

sharedmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand All @@ -17,6 +19,12 @@ import (
"github.com/hashicorp/terraform-provider-hcp/internal/clients"
)

func testAccUniqueNameWithPrefix(prefix string) string {
shortUUID := uuid.New().String()[0:8]

return fmt.Sprintf("testacc-%s-%s", prefix, shortUUID)
}

func testAccCheckFullURL(name, key, port string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
Expand Down

0 comments on commit 2affe4d

Please sign in to comment.