1
1
package test
2
2
3
3
import (
4
+ "strings"
4
5
"testing"
6
+
7
+ "github.com/gruntwork-io/terratest/modules/random"
5
8
"github.com/gruntwork-io/terratest/modules/terraform"
6
9
"github.com/stretchr/testify/assert"
7
10
)
8
11
9
12
// Test the Terraform module in examples/complete using Terratest.
10
13
func TestExamplesComplete (t * testing.T ) {
11
14
t .Parallel ()
15
+ randID := strings .ToLower (random .UniqueId ())
16
+ attributes := []string {randID }
17
+ varFiles := []string {"fixtures.us-east-2.tfvars" }
12
18
13
19
terraformOptions := & terraform.Options {
14
20
// The path to where our Terraform code is located
15
21
TerraformDir : "../../examples/complete" ,
16
22
Upgrade : true ,
17
23
// Variables to pass to our Terraform code using -var-file options
18
- VarFiles : []string {"fixtures.us-east-2.tfvars" },
24
+ VarFiles : varFiles ,
25
+ Vars : map [string ]interface {}{
26
+ "attributes" : attributes ,
27
+ },
19
28
}
20
29
21
30
// At the end of the test, run `terraform destroy` to clean up any resources that were created
@@ -61,12 +70,12 @@ func TestExamplesComplete(t *testing.T) {
61
70
// Run `terraform output` to get the value of an output variable
62
71
elasticBeanstalkApplicationName := terraform .Output (t , terraformOptions , "elastic_beanstalk_application_name" )
63
72
// Verify we're getting back the outputs we expect
64
- assert .Equal (t , "eg-test-jenkins-app" , elasticBeanstalkApplicationName )
73
+ assert .Equal (t , "eg-test-jenkins-" + randID + "- app" , elasticBeanstalkApplicationName )
65
74
66
75
// Run `terraform output` to get the value of an output variable
67
76
elasticBeanstalkEnvironmentName := terraform .Output (t , terraformOptions , "elastic_beanstalk_environment_name" )
68
77
// Verify we're getting back the outputs we expect
69
- assert .Equal (t , "eg-test-jenkins-env" , elasticBeanstalkEnvironmentName )
78
+ assert .Equal (t , "eg-test-jenkins-" + randID + "- env" , elasticBeanstalkEnvironmentName )
70
79
71
80
// Run `terraform output` to get the value of an output variable
72
81
elasticBeanstalkEnvironmentHostname := terraform .Output (t , terraformOptions , "elastic_beanstalk_environment_hostname" )
@@ -76,22 +85,22 @@ func TestExamplesComplete(t *testing.T) {
76
85
// Run `terraform output` to get the value of an output variable
77
86
ecrRepositoryName := terraform .Output (t , terraformOptions , "ecr_repository_name" )
78
87
// Verify we're getting back the outputs we expect
79
- assert .Equal (t , "eg-test-jenkins" , ecrRepositoryName )
88
+ assert .Equal (t , "eg-test-jenkins-" + randID , ecrRepositoryName )
80
89
81
90
// Run `terraform output` to get the value of an output variable
82
91
codebuildProjectName := terraform .Output (t , terraformOptions , "codebuild_project_name" )
83
92
// Verify we're getting back the outputs we expect
84
- assert .Equal (t , "eg-test-jenkins-build-cicd" , codebuildProjectName )
93
+ assert .Equal (t , "eg-test-jenkins-build-" + randID + "- cicd" , codebuildProjectName )
85
94
86
95
// Run `terraform output` to get the value of an output variable
87
96
codebuildCacheBucketName := terraform .Output (t , terraformOptions , "codebuild_cache_bucket_name" )
88
97
// Verify we're getting back the outputs we expect
89
- assert .Contains (t , codebuildCacheBucketName , "eg-test-jenkins-build-cicd" )
98
+ assert .Contains (t , codebuildCacheBucketName , "eg-test-jenkins-build-" + randID + "- cicd" )
90
99
91
100
// Run `terraform output` to get the value of an output variable
92
101
codepipelineId := terraform .Output (t , terraformOptions , "codepipeline_id" )
93
102
// Verify we're getting back the outputs we expect
94
- assert .Equal (t , "eg-test-jenkins-cicd" , codepipelineId )
103
+ assert .Equal (t , "eg-test-jenkins-" + randID + "- cicd" , codepipelineId )
95
104
96
105
// Run `terraform output` to get the value of an output variable
97
106
efsArn := terraform .Output (t , terraformOptions , "efs_arn" )
@@ -106,10 +115,10 @@ func TestExamplesComplete(t *testing.T) {
106
115
// Run `terraform output` to get the value of an output variable
107
116
efsBackupVaultArn := terraform .Output (t , terraformOptions , "efs_backup_vault_arn" )
108
117
// Verify we're getting back the outputs we expect
109
- assert .Equal (t , "arn:aws:backup:us-east-2:126450723953:backup-vault:eg-test-jenkins-efs" , efsBackupVaultArn )
118
+ assert .Equal (t , "arn:aws:backup:us-east-2:126450723953:backup-vault:eg-test-jenkins-" + randID + "- efs" , efsBackupVaultArn )
110
119
111
120
// Run `terraform output` to get the value of an output variable
112
121
efsBackupVaultId := terraform .Output (t , terraformOptions , "efs_backup_vault_id" )
113
122
// Verify we're getting back the outputs we expect
114
- assert .Equal (t , "eg-test-jenkins-efs" , efsBackupVaultId )
123
+ assert .Equal (t , "eg-test-jenkins-" + randID + "- efs" , efsBackupVaultId )
115
124
}
0 commit comments