-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unique Consul Cluster ID #437
Conversation
|
||
data "hcp_consul_cluster" "test" { | ||
cluster_id = hcp_consul_cluster.test.cluster_id | ||
data "hcp_consul_cluster" "%[2]s" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The resource name should stay the same.
data "hcp_consul_cluster" "%[2]s" { | |
data "hcp_consul_cluster" "test" { |
cluster_id = "test-consul-cluster" | ||
var updatedConsulCluster = fmt.Sprintf(` | ||
resource "hcp_consul_cluster" "%[1]s" { | ||
cluster_id = "test-consul-cluster-updated" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want the cluster ID to be unique. The resource names should stay the same test
. The issue is not with Terraform having resource name collisions, it's with the Consul clusters having cluster ID collisions.
cluster_id = "test-consul-cluster-updated" | |
cluster_id = "%[1]s" |
resource "hcp_consul_cluster" "test" { | ||
cluster_id = "test-consul-cluster" | ||
var updatedConsulCluster = fmt.Sprintf(` | ||
resource "hcp_consul_cluster" "%[1]s" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resource "hcp_consul_cluster" "%[1]s" { | |
resource "hcp_consul_cluster" "test" { |
} | ||
`, consulCluster) | ||
`, consulCluster, consulClusterUniqueResourceName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this variable here.
`, consulCluster, consulClusterUniqueResourceName) | |
`, consulCluster) |
@@ -69,13 +72,13 @@ func TestAccConsulCluster(t *testing.T) { | |||
Config: testConfig(setTestAccConsulClusterConfig(consulCluster)), | |||
Check: resource.ComposeTestCheckFunc( | |||
testAccCheckConsulClusterExists(resourceName), | |||
resource.TestCheckResourceAttr(resourceName, "cluster_id", "test-consul-cluster"), | |||
resource.TestCheckResourceAttr(resourceName, "cluster_id", "test-consul-cluster-original"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resource.TestCheckResourceAttr(resourceName, "cluster_id", "test-consul-cluster-original"), | |
resource.TestCheckResourceAttr(resourceName, "cluster_id", consulClusterUniqueResourceName), |
} | ||
|
||
// This includes tests against both the resource, the corresponding datasource, | ||
// and creation of the Consul cluster root token resource in order to shorten | ||
// testing time. | ||
func TestAccConsulCluster(t *testing.T) { | ||
resourceName := "hcp_consul_cluster.test" | ||
dataSourceName := "data.hcp_consul_cluster.test" | ||
resourceName := fmt.Sprintf("hcp_consul_cluster.%s", consulClusterUniqueResourceName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert these two lines.
b385c7d
to
4974dff
Compare
.changelog/437.txt
Outdated
@@ -0,0 +1,3 @@ | |||
```release-note:improvement | |||
Enable unique clusterIDs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enable unique clusterIDs | |
Use unique cluster IDs in acceptance test |
@@ -38,7 +41,7 @@ func setTestAccConsulClusterConfig(consulCluster string) string { | |||
|
|||
data "hcp_consul_versions" "test" {} | |||
|
|||
%s | |||
%[1]s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%[1]s | |
%s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
🛠️ Description
This change adds unique cluster IDs to prevent reuse of identifiers and cluster name collision on test retries.
🏗️ Acceptance tests
Output from acceptance testing: