@@ -2,33 +2,21 @@ package test
22
33import (
44 "encoding/json"
5- "math/rand"
6- "strconv"
7- "testing"
8- "time"
9-
105 "github.com/gruntwork-io/terratest/modules/terraform"
116 "github.com/stretchr/testify/assert"
7+ "testing"
128)
139
1410// Test the Terraform module in examples/complete using Terratest.
1511func TestExamplesComplete (t * testing.T ) {
1612 t .Parallel ()
1713
18- rand .Seed (time .Now ().UnixNano ())
19-
20- randId := strconv .Itoa (rand .Intn (100000 ))
21- attributes := []string {randId }
22-
2314 terraformOptions := & terraform.Options {
2415 // The path to where our Terraform code is located
2516 TerraformDir : "../../examples/complete" ,
2617 Upgrade : true ,
2718 // Variables to pass to our Terraform code using -var-file options
2819 VarFiles : []string {"fixtures.us-east-2.tfvars" },
29- Vars : map [string ]interface {}{
30- "attributes" : attributes ,
31- },
3220 }
3321
3422 // At the end of the test, run `terraform destroy` to clean up any resources that were created
@@ -69,61 +57,45 @@ func TestExamplesComplete(t *testing.T) {
6957 // Run `terraform output` to get the value of an output variable
7058 ecsClusterId := terraform .Output (t , terraformOptions , "ecs_cluster_id" )
7159 // Verify we're getting back the outputs we expect
72- assert .Equal (t , "arn:aws:ecs:us-east-2:126450723953:cluster/eg-test-ecs-alb-service-task-" + randId , ecsClusterId )
60+ assert .Equal (t , "arn:aws:ecs:us-east-2:126450723953:cluster/eg-test-ecs-alb-service-task" , ecsClusterId )
7361
7462 // Run `terraform output` to get the value of an output variable
7563 ecsClusterArn := terraform .Output (t , terraformOptions , "ecs_cluster_arn" )
7664 // Verify we're getting back the outputs we expect
77- assert .Equal (t , "arn:aws:ecs:us-east-2:126450723953:cluster/eg-test-ecs-alb-service-task-" + randId , ecsClusterArn )
65+ assert .Equal (t , "arn:aws:ecs:us-east-2:126450723953:cluster/eg-test-ecs-alb-service-task" , ecsClusterArn )
7866
7967 // Run `terraform output` to get the value of an output variable
8068 ecsExecRolePolicyName := terraform .Output (t , terraformOptions , "ecs_exec_role_policy_name" )
8169 // Verify we're getting back the outputs we expect
82- assert .Equal (t , "eg-test-ecs-alb-service-task-" + randId + "- exec" , ecsExecRolePolicyName )
70+ assert .Equal (t , "eg-test-ecs-alb-service-task-exec" , ecsExecRolePolicyName )
8371
8472 // Run `terraform output` to get the value of an output variable
8573 serviceName := terraform .Output (t , terraformOptions , "service_name" )
8674 // Verify we're getting back the outputs we expect
87- assert .Equal (t , "eg-test-ecs-alb-service-task-" + randId , serviceName )
75+ assert .Equal (t , "eg-test-ecs-alb-service-task" , serviceName )
8876
8977 // Run `terraform output` to get the value of an output variable
9078 taskDefinitionFamily := terraform .Output (t , terraformOptions , "task_definition_family" )
9179 // Verify we're getting back the outputs we expect
92- assert .Equal (t , "eg-test-ecs-alb-service-task-" + randId , taskDefinitionFamily )
80+ assert .Equal (t , "eg-test-ecs-alb-service-task" , taskDefinitionFamily )
9381
9482 // Run `terraform output` to get the value of an output variable
9583 taskExecRoleName := terraform .Output (t , terraformOptions , "task_exec_role_name" )
9684 // Verify we're getting back the outputs we expect
97- assert .Equal (t , "eg-test-ecs-alb-service-task-" + randId + "- exec" , taskExecRoleName )
85+ assert .Equal (t , "eg-test-ecs-alb-service-task-exec" , taskExecRoleName )
9886
9987 // Run `terraform output` to get the value of an output variable
10088 taskExecRoleArn := terraform .Output (t , terraformOptions , "task_exec_role_arn" )
10189 // Verify we're getting back the outputs we expect
102- assert .Equal (t , "arn:aws:iam::126450723953:role/eg-test-ecs-alb-service-task-" + randId + "- exec" , taskExecRoleArn )
90+ assert .Equal (t , "arn:aws:iam::126450723953:role/eg-test-ecs-alb-service-task-exec" , taskExecRoleArn )
10391
10492 // Run `terraform output` to get the value of an output variable
10593 taskRoleName := terraform .Output (t , terraformOptions , "task_role_name" )
10694 // Verify we're getting back the outputs we expect
107- assert .Equal (t , "eg-test-ecs-alb-service-task-" + randId + "- task" , taskRoleName )
95+ assert .Equal (t , "eg-test-ecs-alb-service-task-task" , taskRoleName )
10896
10997 // Run `terraform output` to get the value of an output variable
11098 taskRoleArn := terraform .Output (t , terraformOptions , "task_role_arn" )
11199 // Verify we're getting back the outputs we expect
112- assert .Equal (t , "arn:aws:iam::126450723953:role/eg-test-ecs-alb-service-task-" + randId + "-task" , taskRoleArn )
113-
114- // Run `terraform output` to get the value of an output variable
115- securityGroupName := terraform .Output (t , terraformOptions , "service_security_group_name" )
116- expectedSecurityGroupName := "eg-test-ecs-alb-service-task-" + randId + "-service"
117- // Verify we're getting back the outputs we expect
118- assert .Equal (t , expectedSecurityGroupName , securityGroupName )
119-
120- // Run `terraform output` to get the value of an output variable
121- securityGroupID := terraform .Output (t , terraformOptions , "service_security_group_id" )
122- // Verify we're getting back the outputs we expect
123- assert .Contains (t , securityGroupID , "sg-" , "SG ID should contains substring 'sg-'" )
124-
125- // Run `terraform output` to get the value of an output variable
126- securityGroupARN := terraform .Output (t , terraformOptions , "service_security_group_arn" )
127- // Verify we're getting back the outputs we expect
128- assert .Contains (t , securityGroupARN , "arn:aws:ec2" , "SG ID should contains substring 'arn:aws:ec2'" )
100+ assert .Equal (t , "arn:aws:iam::126450723953:role/eg-test-ecs-alb-service-task-task" , taskRoleArn )
129101}
0 commit comments