From 718ed55bee30c84f8fd7a611a356d81acd00a782 Mon Sep 17 00:00:00 2001 From: Paras Prajapati Date: Thu, 12 Jan 2023 16:30:46 -0500 Subject: [PATCH 1/5] add more unique names --- go.mod | 6 +++--- go.sum | 11 +++++++---- internal/provider/provider.go | 4 ++-- .../provider/resource_consul_cluster_test.go | 9 +++++---- .../provider/resource_consul_snapshot_test.go | 18 +++++++++++------- 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/go.mod b/go.mod index 53e51f981..786beca05 100644 --- a/go.mod +++ b/go.mod @@ -62,8 +62,8 @@ require ( github.com/imdario/mergo v0.3.13 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/mailru/easyjson v0.7.7 // indirect - github.com/mattn/go-colorable v0.1.12 // indirect - github.com/mattn/go-isatty v0.0.14 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.16 // indirect github.com/mitchellh/cli v1.1.4 // indirect github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect github.com/mitchellh/copystructure v1.2.0 // indirect @@ -90,7 +90,7 @@ require ( golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58 // indirect - golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect + golang.org/x/sys v0.1.0 // indirect golang.org/x/text v0.4.0 // indirect google.golang.org/appengine v1.6.6 // indirect google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d // indirect diff --git a/go.sum b/go.sum index 089cab69b..3dbab2737 100644 --- a/go.sum +++ b/go.sum @@ -320,12 +320,14 @@ github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kN github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mitchellh/cli v1.1.4 h1:qj8czE26AU4PbiaPXK5uVmMSM+V5BYsFBiM9HhGRLUA= github.com/mitchellh/cli v1.1.4/go.mod h1:vTLESy5mRhKOs9KDp0/RATawxP1UqBmdrpVRMnpcvKQ= github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= @@ -583,8 +585,9 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 h1:h+EGohizhe9XlX18rfpa8k8RAc5XyaeamM+0VHRd4lc= -golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 1a32cc397..e081a18e7 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "os" @@ -205,7 +205,7 @@ func isHCPOperational() (diags diag.Diagnostics) { } defer resp.Body.Close() - jsBytes, err := ioutil.ReadAll(resp.Body) + jsBytes, err := io.ReadAll(resp.Body) if err != nil { diags = append(diags, diag.Diagnostic{ Severity: diag.Warning, diff --git a/internal/provider/resource_consul_cluster_test.go b/internal/provider/resource_consul_cluster_test.go index 07a575602..7b3838665 100644 --- a/internal/provider/resource_consul_cluster_test.go +++ b/internal/provider/resource_consul_cluster_test.go @@ -12,6 +12,7 @@ import ( ) var consulClusterUniqueID = fmt.Sprintf("test-%s", time.Now().Format("200601021504")) +var consulClusterHVNUniqueID = fmt.Sprintf("test-hvn-%s", time.Now().Format("200601021504")) var consulCluster = fmt.Sprintf(` resource "hcp_consul_cluster" "test" { @@ -34,7 +35,7 @@ resource "hcp_consul_cluster" "test" { func setTestAccConsulClusterConfig(consulCluster string) string { return fmt.Sprintf(` resource "hcp_hvn" "test" { - hvn_id = "test-hvn" + hvn_id = "%s" cloud_provider = "aws" region = "us-west-2" } @@ -50,7 +51,7 @@ func setTestAccConsulClusterConfig(consulCluster string) string { resource "hcp_consul_cluster_root_token" "test" { cluster_id = hcp_consul_cluster.test.cluster_id } -`, consulCluster) +`, consulClusterHVNUniqueID, consulCluster) } // This includes tests against both the resource, the corresponding datasource, @@ -73,7 +74,7 @@ func TestAccConsulCluster(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckConsulClusterExists(resourceName), resource.TestCheckResourceAttr(resourceName, "cluster_id", consulClusterUniqueID), - resource.TestCheckResourceAttr(resourceName, "hvn_id", "test-hvn"), + resource.TestCheckResourceAttr(resourceName, "hvn_id", consulClusterHVNUniqueID), resource.TestCheckResourceAttr(resourceName, "tier", "DEVELOPMENT"), resource.TestCheckResourceAttr(resourceName, "cloud_provider", "aws"), resource.TestCheckResourceAttr(resourceName, "region", "us-west-2"), @@ -121,7 +122,7 @@ func TestAccConsulCluster(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckConsulClusterExists(resourceName), resource.TestCheckResourceAttr(resourceName, "cluster_id", consulClusterUniqueID), - resource.TestCheckResourceAttr(resourceName, "hvn_id", "test-hvn"), + resource.TestCheckResourceAttr(resourceName, "hvn_id", consulClusterHVNUniqueID), resource.TestCheckResourceAttr(resourceName, "tier", "DEVELOPMENT"), resource.TestCheckResourceAttr(resourceName, "cloud_provider", "aws"), resource.TestCheckResourceAttr(resourceName, "region", "us-west-2"), diff --git a/internal/provider/resource_consul_snapshot_test.go b/internal/provider/resource_consul_snapshot_test.go index b71335153..87a09a1ca 100644 --- a/internal/provider/resource_consul_snapshot_test.go +++ b/internal/provider/resource_consul_snapshot_test.go @@ -4,29 +4,33 @@ import ( "context" "fmt" "testing" + "time" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/hashicorp/terraform-provider-hcp/internal/clients" ) -var testAccConsulSnapshotConfig = ` +var consulClusterSnapshotUniqueID = fmt.Sprintf("test-snapshot-%s", time.Now().Format("200601021504")) +var consulClusterSnapshotHVNUniqueID = fmt.Sprintf("test-snapshot-hvn-%s", time.Now().Format("200601021504")) + +var testAccConsulSnapshotConfig = fmt.Sprintf(` resource "hcp_hvn" "test" { - hvn_id = "test-hvn" + hvn_id = "%s" cloud_provider = "aws" region = "us-west-2" } resource "hcp_consul_cluster" "test" { - cluster_id = "test-consul-cluster" + cluster_id = "%s" hvn_id = hcp_hvn.test.hvn_id tier = "development" } resource "hcp_consul_snapshot" "test" { cluster_id = hcp_consul_cluster.test.cluster_id - snapshot_name = "test" -}` + snapshot_name = "%[1]s" +}`, consulClusterSnapshotHVNUniqueID, consulClusterSnapshotUniqueID) func TestAccConsulSnapshot(t *testing.T) { resourceName := "hcp_consul_snapshot.test" @@ -40,7 +44,7 @@ func TestAccConsulSnapshot(t *testing.T) { Config: testConfig(testAccConsulSnapshotConfig), Check: resource.ComposeTestCheckFunc( testAccCheckConsulSnapshotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "cluster_id", "test-consul-cluster"), + resource.TestCheckResourceAttr(resourceName, "cluster_id", consulClusterSnapshotUniqueID), resource.TestCheckResourceAttr(resourceName, "snapshot_name", "test"), resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttrSet(resourceName, "snapshot_id"), @@ -55,7 +59,7 @@ func TestAccConsulSnapshot(t *testing.T) { Config: testConfig(testAccConsulSnapshotConfig), Check: resource.ComposeTestCheckFunc( testAccCheckConsulSnapshotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "cluster_id", "test-consul-cluster"), + resource.TestCheckResourceAttr(resourceName, "cluster_id", consulClusterSnapshotUniqueID), resource.TestCheckResourceAttr(resourceName, "snapshot_name", "test"), resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttrSet(resourceName, "snapshot_id"), From 740756b779b6238815dc11da3480f5b84cb2d694 Mon Sep 17 00:00:00 2001 From: Paras Prajapati Date: Thu, 12 Jan 2023 17:27:06 -0500 Subject: [PATCH 2/5] fix assertion for snapshot_name --- internal/provider/resource_consul_snapshot_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/provider/resource_consul_snapshot_test.go b/internal/provider/resource_consul_snapshot_test.go index 87a09a1ca..05575d5d0 100644 --- a/internal/provider/resource_consul_snapshot_test.go +++ b/internal/provider/resource_consul_snapshot_test.go @@ -45,7 +45,7 @@ func TestAccConsulSnapshot(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckConsulSnapshotExists(resourceName), resource.TestCheckResourceAttr(resourceName, "cluster_id", consulClusterSnapshotUniqueID), - resource.TestCheckResourceAttr(resourceName, "snapshot_name", "test"), + resource.TestCheckResourceAttr(resourceName, "snapshot_name", consulClusterSnapshotUniqueID), resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttrSet(resourceName, "snapshot_id"), resource.TestCheckResourceAttrSet(resourceName, "organization_id"), @@ -60,7 +60,7 @@ func TestAccConsulSnapshot(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckConsulSnapshotExists(resourceName), resource.TestCheckResourceAttr(resourceName, "cluster_id", consulClusterSnapshotUniqueID), - resource.TestCheckResourceAttr(resourceName, "snapshot_name", "test"), + resource.TestCheckResourceAttr(resourceName, "snapshot_name", consulClusterSnapshotUniqueID), resource.TestCheckResourceAttrSet(resourceName, "project_id"), resource.TestCheckResourceAttrSet(resourceName, "snapshot_id"), resource.TestCheckResourceAttrSet(resourceName, "organization_id"), From bff552fb8d77c6e776d1104157a3cf05d341f043 Mon Sep 17 00:00:00 2001 From: Paras Prajapati Date: Fri, 13 Jan 2023 15:37:37 -0500 Subject: [PATCH 3/5] correct names --- internal/provider/resource_consul_snapshot_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/provider/resource_consul_snapshot_test.go b/internal/provider/resource_consul_snapshot_test.go index 05575d5d0..739c40ad3 100644 --- a/internal/provider/resource_consul_snapshot_test.go +++ b/internal/provider/resource_consul_snapshot_test.go @@ -16,20 +16,20 @@ var consulClusterSnapshotHVNUniqueID = fmt.Sprintf("test-snapshot-hvn-%s", time. var testAccConsulSnapshotConfig = fmt.Sprintf(` resource "hcp_hvn" "test" { - hvn_id = "%s" + hvn_id = "%[1]s" cloud_provider = "aws" region = "us-west-2" } resource "hcp_consul_cluster" "test" { - cluster_id = "%s" + cluster_id = "%[2]s" hvn_id = hcp_hvn.test.hvn_id tier = "development" } resource "hcp_consul_snapshot" "test" { cluster_id = hcp_consul_cluster.test.cluster_id - snapshot_name = "%[1]s" + snapshot_name = "%[2]s" }`, consulClusterSnapshotHVNUniqueID, consulClusterSnapshotUniqueID) func TestAccConsulSnapshot(t *testing.T) { From ab792c4a365238b184740eafa368e566f9f74df2 Mon Sep 17 00:00:00 2001 From: Paras Prajapati Date: Mon, 16 Jan 2023 15:37:50 -0500 Subject: [PATCH 4/5] fix TestAccTGWAttachment --- .../resource_aws_transit_gateway_attachment_test.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/internal/provider/resource_aws_transit_gateway_attachment_test.go b/internal/provider/resource_aws_transit_gateway_attachment_test.go index dfdd17f85..7083afef4 100644 --- a/internal/provider/resource_aws_transit_gateway_attachment_test.go +++ b/internal/provider/resource_aws_transit_gateway_attachment_test.go @@ -14,14 +14,15 @@ import ( var ( // using unique names for AWS resource to make debugging easier - tgwAttUniqueAWSName = fmt.Sprintf("hcp-provider-test-%s", time.Now().Format("200601021504")) + tgwAttUniqueAWSName = fmt.Sprintf("hcp-att-unique-test-%s", time.Now().Format("200601021504")) + tgwAttUniqueHvnName = fmt.Sprintf("att-hvn-name-%s", time.Now().Format("200601021504")) testAccTGWAttachmentConfig = fmt.Sprintf(` provider "aws" { region = "us-west-2" } resource "hcp_hvn" "test" { - hvn_id = "%[1]s" + hvn_id = "%[2]s" cloud_provider = "aws" region = "us-west-2" cidr_block = "172.25.16.0/20" @@ -99,7 +100,7 @@ resource "aws_ec2_transit_gateway_vpc_attachment_accepter" "example" { tgw_attachment_id = hcp_aws_transit_gateway_attachment.example.transit_gateway_attachment_id } } -`, tgwAttUniqueAWSName) +`, tgwAttUniqueAWSName, tgwAttUniqueHvnName) ) func TestAccTGWAttachment(t *testing.T) { @@ -120,7 +121,7 @@ func TestAccTGWAttachment(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckTGWAttachmentExists(resourceName), resource.TestCheckResourceAttr(resourceName, "transit_gateway_attachment_id", tgwAttUniqueAWSName), - resource.TestCheckResourceAttr(resourceName, "hvn_id", tgwAttUniqueAWSName), + resource.TestCheckResourceAttr(resourceName, "hvn_id", tgwAttUniqueHvnName), resource.TestCheckResourceAttrSet(resourceName, "transit_gateway_id"), resource.TestCheckResourceAttrSet(resourceName, "provider_transit_gateway_attachment_id"), resource.TestCheckResourceAttrSet(resourceName, "state"), @@ -142,7 +143,7 @@ func TestAccTGWAttachment(t *testing.T) { return "", fmt.Errorf("not found: aws_ram_resource_share.example") } - return fmt.Sprintf("test-hvn:example-tgw-attachment:%s", resourceShare.Primary.Attributes["arn"]), nil + return fmt.Sprintf("%s:%s:%s", tgwAttUniqueHvnName, tgwAttUniqueAWSName, resourceShare.Primary.Attributes["arn"]), nil }, ImportStateVerify: true, }, @@ -152,7 +153,7 @@ func TestAccTGWAttachment(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckTGWAttachmentExists(resourceName), resource.TestCheckResourceAttr(resourceName, "transit_gateway_attachment_id", tgwAttUniqueAWSName), - resource.TestCheckResourceAttr(resourceName, "hvn_id", tgwAttUniqueAWSName), + resource.TestCheckResourceAttr(resourceName, "hvn_id", tgwAttUniqueHvnName), resource.TestCheckResourceAttrSet(resourceName, "transit_gateway_id"), resource.TestCheckResourceAttrSet(resourceName, "provider_transit_gateway_attachment_id"), resource.TestCheckResourceAttrSet(resourceName, "state"), From 235ae4791c34463cb2e66171a1b12bf478b22642 Mon Sep 17 00:00:00 2001 From: Paras Prajapati Date: Thu, 19 Jan 2023 10:53:42 -0500 Subject: [PATCH 5/5] changelog --- .changelog/440.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/440.txt diff --git a/.changelog/440.txt b/.changelog/440.txt new file mode 100644 index 000000000..797caa054 --- /dev/null +++ b/.changelog/440.txt @@ -0,0 +1,3 @@ +```release-note:bug +Fix issue with E2E tests failing +```