@@ -2,8 +2,10 @@ package test
2
2
3
3
import (
4
4
"encoding/json"
5
+ "strings"
5
6
"testing"
6
7
8
+ "github.com/gruntwork-io/terratest/modules/random"
7
9
"github.com/gruntwork-io/terratest/modules/terraform"
8
10
"github.com/stretchr/testify/assert"
9
11
)
@@ -12,12 +14,18 @@ import (
12
14
func TestExamplesComplete (t * testing.T ) {
13
15
t .Parallel ()
14
16
17
+ randID := strings .ToLower (random .UniqueId ())
18
+ attributes := []string {randID }
19
+
15
20
terraformOptions := & terraform.Options {
16
21
// The path to where our Terraform code is located
17
22
TerraformDir : "../../examples/complete" ,
18
23
Upgrade : true ,
19
24
// Variables to pass to our Terraform code using -var-file options
20
25
VarFiles : []string {"fixtures.us-east-2.tfvars" },
26
+ Vars : map [string ]interface {}{
27
+ "attributes" : attributes ,
28
+ },
21
29
}
22
30
23
31
// At the end of the test, run `terraform destroy` to clean up any resources that were created
@@ -58,22 +66,22 @@ func TestExamplesComplete(t *testing.T) {
58
66
// Run `terraform output` to get the value of an output variable
59
67
ecsClusterId := terraform .Output (t , terraformOptions , "ecs_cluster_id" )
60
68
// Verify we're getting back the outputs we expect
61
- assert .Equal (t , "arn:aws:ecs:us-east-2:126450723953:cluster/eg-test-ecs-cloudwatch-autoscaling" , ecsClusterId )
69
+ assert .Equal (t , "arn:aws:ecs:us-east-2:126450723953:cluster/eg-test-ecs-cloudwatch-autoscaling-" + randID , ecsClusterId )
62
70
63
71
// Run `terraform output` to get the value of an output variable
64
72
ecsClusterArn := terraform .Output (t , terraformOptions , "ecs_cluster_arn" )
65
73
// Verify we're getting back the outputs we expect
66
- assert .Equal (t , "arn:aws:ecs:us-east-2:126450723953:cluster/eg-test-ecs-cloudwatch-autoscaling" , ecsClusterArn )
74
+ assert .Equal (t , "arn:aws:ecs:us-east-2:126450723953:cluster/eg-test-ecs-cloudwatch-autoscaling-" + randID , ecsClusterArn )
67
75
68
76
// Run `terraform output` to get the value of an output variable
69
77
ecsExecRolePolicyName := terraform .Output (t , terraformOptions , "ecs_exec_role_policy_name" )
70
78
// Verify we're getting back the outputs we expect
71
- assert .Equal (t , "eg-test-ecs-cloudwatch-autoscaling-exec" , ecsExecRolePolicyName )
79
+ assert .Equal (t , "eg-test-ecs-cloudwatch-autoscaling-exec-" + randID , ecsExecRolePolicyName )
72
80
73
81
// Run `terraform output` to get the value of an output variable
74
82
serviceName := terraform .Output (t , terraformOptions , "service_name" )
75
83
// Verify we're getting back the outputs we expect
76
- assert .Equal (t , "eg-test-ecs-cloudwatch-autoscaling" , serviceName )
84
+ assert .Equal (t , "eg-test-ecs-cloudwatch-autoscaling-" + randID , serviceName )
77
85
78
86
// Run `terraform output` to get the value of an output variable
79
87
serviceRoleArn := terraform .Output (t , terraformOptions , "service_role_arn" )
@@ -85,35 +93,35 @@ func TestExamplesComplete(t *testing.T) {
85
93
// Run `terraform output` to get the value of an output variable
86
94
taskDefinitionFamily := terraform .Output (t , terraformOptions , "task_definition_family" )
87
95
// Verify we're getting back the outputs we expect
88
- assert .Equal (t , "eg-test-ecs-cloudwatch-autoscaling" , taskDefinitionFamily )
96
+ assert .Equal (t , "eg-test-ecs-cloudwatch-autoscaling-" + randID , taskDefinitionFamily )
89
97
90
98
// Run `terraform output` to get the value of an output variable
91
99
taskExecRoleName := terraform .Output (t , terraformOptions , "task_exec_role_name" )
92
100
// Verify we're getting back the outputs we expect
93
- assert .Equal (t , "eg-test-ecs-cloudwatch-autoscaling-exec" , taskExecRoleName )
101
+ assert .Equal (t , "eg-test-ecs-cloudwatch-autoscaling-exec-" + randID , taskExecRoleName )
94
102
95
103
// Run `terraform output` to get the value of an output variable
96
104
taskExecRoleArn := terraform .Output (t , terraformOptions , "task_exec_role_arn" )
97
105
// Verify we're getting back the outputs we expect
98
- assert .Equal (t , "arn:aws:iam::126450723953:role/eg-test-ecs-cloudwatch-autoscaling-exec" , taskExecRoleArn )
106
+ assert .Equal (t , "arn:aws:iam::126450723953:role/eg-test-ecs-cloudwatch-autoscaling-exec-" + randID , taskExecRoleArn )
99
107
100
108
// Run `terraform output` to get the value of an output variable
101
109
taskRoleName := terraform .Output (t , terraformOptions , "task_role_name" )
102
110
// Verify we're getting back the outputs we expect
103
- assert .Equal (t , "eg-test-ecs-cloudwatch-autoscaling-task" , taskRoleName )
111
+ assert .Equal (t , "eg-test-ecs-cloudwatch-autoscaling-task-" + randID , taskRoleName )
104
112
105
113
// Run `terraform output` to get the value of an output variable
106
114
taskRoleArn := terraform .Output (t , terraformOptions , "task_role_arn" )
107
115
// Verify we're getting back the outputs we expect
108
- assert .Equal (t , "arn:aws:iam::126450723953:role/eg-test-ecs-cloudwatch-autoscaling-task" , taskRoleArn )
116
+ assert .Equal (t , "arn:aws:iam::126450723953:role/eg-test-ecs-cloudwatch-autoscaling-task-" + randID , taskRoleArn )
109
117
110
118
// Run `terraform output` to get the value of an output variable
111
119
scaleUpPolicyArn := terraform .Output (t , terraformOptions , "scale_up_policy_arn" )
112
120
// Verify we're getting back the outputs we expect
113
- assert .Contains (t , scaleUpPolicyArn , "eg-test-ecs-cloudwatch-autoscaling-up" )
121
+ assert .Contains (t , scaleUpPolicyArn , "eg-test-ecs-cloudwatch-autoscaling-" + randID + "- up" )
114
122
115
123
// Run `terraform output` to get the value of an output variable
116
124
scaleDownPolicyArn := terraform .Output (t , terraformOptions , "scale_down_policy_arn" )
117
125
// Verify we're getting back the outputs we expect
118
- assert .Contains (t , scaleDownPolicyArn , "eg-test-ecs-cloudwatch-autoscaling-down" )
126
+ assert .Contains (t , scaleDownPolicyArn , "eg-test-ecs-cloudwatch-autoscaling-" + randID + "- down" )
119
127
}
0 commit comments