11package test
22
33import (
4+ "fmt"
5+ "strings"
46 "testing"
57
68 "github.com/gruntwork-io/terratest/modules/terraform"
9+ "github.com/gruntwork-io/terratest/modules/random"
710 "github.com/stretchr/testify/assert"
811)
912
1013// Test the Terraform module in examples/complete using Terratest.
1114func TestExamplesComplete (t * testing.T ) {
1215 t .Parallel ()
1316
17+ // Give this S3 Bucket a unique ID for a name tag so we can distinguish it from any other Buckets provisioned
18+ // in your AWS account
19+ attributes := []string {strings .ToLower (random .UniqueId ())}
20+
1421 terraformOptions := & terraform.Options {
1522 // The path to where our Terraform code is located
1623 TerraformDir : "../../examples/complete" ,
1724 Upgrade : true ,
1825 // Variables to pass to our Terraform code using -var-file options
1926 VarFiles : []string {"fixtures.us-east-2.tfvars" },
27+ Vars : map [string ]interface {}{
28+ "attributes" : attributes ,
29+ },
2030 }
2131
2232 // At the end of the test, run `terraform destroy` to clean up any resources that were created
@@ -41,14 +51,15 @@ func TestExamplesComplete(t *testing.T) {
4151 assert .Equal (t , []string {"172.16.96.0/19" , "172.16.128.0/19" }, publicSubnetCidrs )
4252
4353 // Run `terraform output` to get the value of an output variable
54+ expectedName := fmt .Sprintf ("eg-test-elastic-beanstalk-env-%s" , attributes [0 ])
4455 elasticBeanstalkApplicationName := terraform .Output (t , terraformOptions , "elastic_beanstalk_application_name" )
4556 // Verify we're getting back the outputs we expect
46- assert .Equal (t , "eg-test-elastic-beanstalk-env" , elasticBeanstalkApplicationName )
57+ assert .Equal (t , expectedName , elasticBeanstalkApplicationName )
4758
4859 // Run `terraform output` to get the value of an output variable
4960 elasticBeanstalkEnvironmentName := terraform .Output (t , terraformOptions , "elastic_beanstalk_environment_name" )
5061 // Verify we're getting back the outputs we expect
51- assert .Equal (t , "eg-test-elastic-beanstalk-env" , elasticBeanstalkEnvironmentName )
62+ assert .Equal (t , expectedName , elasticBeanstalkEnvironmentName )
5263
5364 // Run `terraform output` to get the value of an output variable
5465 elasticBeanstalkEnvironmentHostname := terraform .Output (t , terraformOptions , "elastic_beanstalk_environment_hostname" )
0 commit comments