@@ -2,22 +2,29 @@ package test
22
33import (
44 "encoding/json"
5+ "strings"
56 "testing"
67
8+ "github.com/gruntwork-io/terratest/modules/random"
79 "github.com/gruntwork-io/terratest/modules/terraform"
810 "github.com/stretchr/testify/assert"
911)
1012
1113// Test the Terraform module in examples/complete using Terratest.
1214func TestExamplesComplete (t * testing.T ) {
1315 t .Parallel ()
16+ randID := strings .ToLower (random .UniqueId ())
17+ attributes := []string {randID }
1418
1519 terraformOptions := & terraform.Options {
1620 // The path to where our Terraform code is located
1721 TerraformDir : "../../examples/complete" ,
1822 Upgrade : true ,
1923 // Variables to pass to our Terraform code using -var-file options
2024 VarFiles : []string {"fixtures.us-east-2.tfvars" },
25+ Vars : map [string ]interface {}{
26+ "attributes" : attributes ,
27+ },
2128 }
2229
2330 // At the end of the test, run `terraform destroy` to clean up any resources that were created
@@ -68,50 +75,50 @@ func TestExamplesComplete(t *testing.T) {
6875 // Run `terraform output` to get the value of an output variable
6976 ecsExecRolePolicyName := terraform .Output (t , terraformOptions , "ecs_exec_role_policy_name" )
7077 // Verify we're getting back the outputs we expect
71- assert .Equal (t , "eg-test-ecs-codepipeline-exec" , ecsExecRolePolicyName )
78+ assert .Equal (t , "eg-test-ecs-codepipeline-" + attributes [ 0 ] + "- exec" , ecsExecRolePolicyName )
7279
7380 // Run `terraform output` to get the value of an output variable
7481 serviceName := terraform .Output (t , terraformOptions , "service_name" )
7582 // Verify we're getting back the outputs we expect
76- assert .Equal (t , "eg-test-ecs-codepipeline" , serviceName )
83+ assert .Equal (t , "eg-test-ecs-codepipeline-" + attributes [ 0 ] , serviceName )
7784
7885 // Run `terraform output` to get the value of an output variable
7986 taskDefinitionFamily := terraform .Output (t , terraformOptions , "task_definition_family" )
8087 // Verify we're getting back the outputs we expect
81- assert .Equal (t , "eg-test-ecs-codepipeline" , taskDefinitionFamily )
88+ assert .Equal (t , "eg-test-ecs-codepipeline-" + attributes [ 0 ] , taskDefinitionFamily )
8289
8390 // Run `terraform output` to get the value of an output variable
8491 taskExecRoleName := terraform .Output (t , terraformOptions , "task_exec_role_name" )
8592 // Verify we're getting back the outputs we expect
86- assert .Equal (t , "eg-test-ecs-codepipeline-exec" , taskExecRoleName )
93+ assert .Equal (t , "eg-test-ecs-codepipeline-" + attributes [ 0 ] + "- exec" , taskExecRoleName )
8794
8895 // Run `terraform output` to get the value of an output variable
8996 taskExecRoleArn := terraform .Output (t , terraformOptions , "task_exec_role_arn" )
9097 // Verify we're getting back the outputs we expect
91- assert .Contains (t , taskExecRoleArn , "role/eg-test-ecs-codepipeline-exec" )
98+ assert .Contains (t , taskExecRoleArn , "role/eg-test-ecs-codepipeline-" + attributes [ 0 ] + "- exec" )
9299
93100 // Run `terraform output` to get the value of an output variable
94101 taskRoleName := terraform .Output (t , terraformOptions , "task_role_name" )
95102 // Verify we're getting back the outputs we expect
96- assert .Equal (t , "eg-test-ecs-codepipeline-task" , taskRoleName )
103+ assert .Equal (t , "eg-test-ecs-codepipeline-" + attributes [ 0 ] + "- task" , taskRoleName )
97104
98105 // Run `terraform output` to get the value of an output variable
99106 taskRoleArn := terraform .Output (t , terraformOptions , "task_role_arn" )
100107 // Verify we're getting back the outputs we expect
101- assert .Contains (t , taskRoleArn , "role/eg-test-ecs-codepipeline-task" )
108+ assert .Contains (t , taskRoleArn , "role/eg-test-ecs-codepipeline-" + attributes [ 0 ] + "- task" )
102109
103110 // Run `terraform output` to get the value of an output variable
104111 codebuildProjectName := terraform .Output (t , terraformOptions , "codebuild_project_name" )
105112 // Verify we're getting back the outputs we expect
106- assert .Equal (t , "eg-test-ecs-codepipeline-build" , codebuildProjectName )
113+ assert .Equal (t , "eg-test-ecs-codepipeline-" + attributes [ 0 ] + "- build" , codebuildProjectName )
107114
108115 // Run `terraform output` to get the value of an output variable
109116 codebuildCacheS3BucketName := terraform .Output (t , terraformOptions , "codebuild_cache_bucket_name" )
110117 // Verify we're getting back the outputs we expect
111- assert .Contains (t , codebuildCacheS3BucketName , "eg-test-ecs-codepipeline-build" )
118+ assert .Contains (t , codebuildCacheS3BucketName , "eg-test-ecs-codepipeline-" + attributes [ 0 ] + "- build" )
112119
113120 // Run `terraform output` to get the value of an output variable
114121 codepipelineId := terraform .Output (t , terraformOptions , "codepipeline_id" )
115122 // Verify we're getting back the outputs we expect
116- assert .Equal (t , "eg-test-ecs-codepipeline-codepipeline" , codepipelineId )
123+ assert .Equal (t , "eg-test-ecs-codepipeline-" + attributes [ 0 ] + "- codepipeline" , codepipelineId )
117124}
0 commit comments