@@ -2,7 +2,10 @@ package test
22
33import (
44 "fmt"
5+ "math/rand"
6+ "strconv"
57 "testing"
8+ "time"
69
710 "github.com/gruntwork-io/terratest/modules/terraform"
811 "github.com/stretchr/testify/assert"
@@ -12,13 +15,21 @@ import (
1215func TestExamplesComplete (t * testing.T ) {
1316 t .Parallel ()
1417
18+ rand .Seed (time .Now ().UnixNano ())
19+
20+ randId := strconv .Itoa (rand .Intn (100000 ))
21+ attributes := []string {randId }
22+
1523 // We need to create the ALB first because terraform does not wwait for it to be in the ready state before creating ECS target group
1624 terraformOptions := & terraform.Options {
1725 // The path to where our Terraform code is located
1826 TerraformDir : "../../examples/complete" ,
1927 Upgrade : true ,
2028 // Variables to pass to our Terraform code using -var-file options
2129 VarFiles : []string {"fixtures.us-east-2.tfvars" },
30+ Vars : map [string ]interface {}{
31+ "attributes" : attributes ,
32+ },
2233 }
2334
2435 // At the end of the test, run `terraform destroy` to clean up any resources that were created
@@ -52,20 +63,20 @@ func TestExamplesComplete(t *testing.T) {
5263 // Run `terraform output` to get the value of an output variable
5364 securityGroupName := terraform .Output (t , terraformOptions , "security_group_name" )
5465 // Verify we're getting back the outputs we expect
55- assert .Equal (t , "eg-test-documentdb-cluster" , securityGroupName )
66+ assert .Equal (t , "eg-test-documentdb-cluster-" + randId , securityGroupName )
5667
5768 // Run `terraform output` to get the value of an output variable
5869 clusterName := terraform .Output (t , terraformOptions , "cluster_name" )
5970 // Verify we're getting back the outputs we expect
60- assert .Equal (t , "eg-test-documentdb-cluster" , clusterName )
71+ assert .Equal (t , "eg-test-documentdb-cluster-" + randId , clusterName )
6172
6273 // Run `terraform output` to get the value of an output variable
6374 endpoint := terraform .Output (t , terraformOptions , "endpoint" )
6475 // Verify we're getting back the outputs we expect
65- assert .Contains (t , endpoint , "eg-test-documentdb-cluster.cluster" )
76+ assert .Contains (t , endpoint , "eg-test-documentdb-cluster-" + randId + " .cluster" )
6677
6778 // Run `terraform output` to get the value of an output variable
6879 readerEndpoint := terraform .Output (t , terraformOptions , "reader_endpoint" )
6980 // Verify we're getting back the outputs we expect
70- assert .Contains (t , readerEndpoint , "eg-test-documentdb-cluster.cluster-ro" )
81+ assert .Contains (t , readerEndpoint , "eg-test-documentdb-cluster-" + randId + " .cluster-ro" )
7182}
0 commit comments