@@ -2,7 +2,10 @@ package test
2
2
3
3
import (
4
4
"fmt"
5
+ "math/rand"
6
+ "strconv"
5
7
"testing"
8
+ "time"
6
9
7
10
"github.com/gruntwork-io/terratest/modules/terraform"
8
11
"github.com/stretchr/testify/assert"
@@ -12,13 +15,21 @@ import (
12
15
func TestExamplesComplete (t * testing.T ) {
13
16
t .Parallel ()
14
17
18
+ rand .Seed (time .Now ().UnixNano ())
19
+
20
+ randId := strconv .Itoa (rand .Intn (100000 ))
21
+ attributes := []string {randId }
22
+
15
23
// 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
16
24
terraformOptions := & terraform.Options {
17
25
// The path to where our Terraform code is located
18
26
TerraformDir : "../../examples/complete" ,
19
27
Upgrade : true ,
20
28
// Variables to pass to our Terraform code using -var-file options
21
29
VarFiles : []string {"fixtures.us-east-2.tfvars" },
30
+ Vars : map [string ]interface {}{
31
+ "attributes" : attributes ,
32
+ },
22
33
}
23
34
24
35
// 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) {
52
63
// Run `terraform output` to get the value of an output variable
53
64
securityGroupName := terraform .Output (t , terraformOptions , "security_group_name" )
54
65
// 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 )
56
67
57
68
// Run `terraform output` to get the value of an output variable
58
69
clusterName := terraform .Output (t , terraformOptions , "cluster_name" )
59
70
// 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 )
61
72
62
73
// Run `terraform output` to get the value of an output variable
63
74
endpoint := terraform .Output (t , terraformOptions , "endpoint" )
64
75
// 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" )
66
77
67
78
// Run `terraform output` to get the value of an output variable
68
79
readerEndpoint := terraform .Output (t , terraformOptions , "reader_endpoint" )
69
80
// 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" )
71
82
}
0 commit comments