11package test
22
33import (
4+ "fmt"
5+ "math/rand"
6+ "strconv"
7+ "testing"
8+ "time"
9+
410 "github.com/gruntwork-io/terratest/modules/terraform"
511 "github.com/stretchr/testify/assert"
6- "testing"
712)
813
914// Test the Terraform module in examples/complete using Terratest.
1015func TestExamplesComplete (t * testing.T ) {
1116 t .Parallel ()
1217
18+ rand .Seed (time .Now ().UnixNano ())
19+
20+ randId := strconv .Itoa (rand .Intn (100000 ))
21+ attributes := []string {randId }
22+
1323 terraformOptions := & terraform.Options {
1424 // The path to where our Terraform code is located
1525 TerraformDir : "../../examples/complete" ,
1626 Upgrade : true ,
1727 // Variables to pass to our Terraform code using -var-file options
18- VarFiles : []string {"fixtures.us-east-1.tfvars" },
28+ VarFiles : []string {"fixtures.us-east-2.tfvars" },
29+ Vars : map [string ]interface {}{
30+ "attributes" : attributes ,
31+ },
1932 }
2033
2134 // At the end of the test, run `terraform destroy` to clean up any resources that were created
@@ -32,7 +45,7 @@ func TestExamplesComplete(t *testing.T) {
3245 // Run `terraform output` to get the value of an output variable
3346 artifactUrl := terraform .Output (t , terraformOptions , "artifact_url" )
3447 // Verify we're getting back the outputs we expect
35- assert .Equal (t , "https://artifacts.cloudposse. com/terraform-external-module-artifact/example/test .zip" , artifactUrl )
48+ assert .Equal (t , "https://cplive-core-ue2-public-lambda- artifacts.s3.us-east-2.amazonaws. com/terraform-aws-ses-lambda-forwarder/terraform-aws-ses-lambda-forwarder-latest .zip" , artifactUrl )
3649
3750 // Run `terraform output` to get the value of an output variable
3851 lambdaFunctionArn := terraform .Output (t , terraformOptions , "lambda_function_arn" )
@@ -47,25 +60,25 @@ func TestExamplesComplete(t *testing.T) {
4760 // Run `terraform output` to get the value of an output variable
4861 lambdaIamPolicyName := terraform .Output (t , terraformOptions , "lambda_iam_policy_name" )
4962 // Verify we're getting back the outputs we expect
50- assert .Equal (t , "eg-test-lambda-forwarder-test" , lambdaIamPolicyName )
63+ assert .Equal (t , fmt . Sprintf ( "eg-test-lambda-forwarder-test-%s" , randId ) , lambdaIamPolicyName )
5164
5265 // Run `terraform output` to get the value of an output variable
5366 s3BucketArn := terraform .Output (t , terraformOptions , "s3_bucket_arn" )
5467 // Verify we're getting back the outputs we expect
55- assert .Equal (t , "arn:aws:s3:::eg-test-lambda-forwarder-test" , s3BucketArn )
68+ assert .Equal (t , fmt . Sprintf ( "arn:aws:s3:::eg-test-lambda-forwarder-test-%s" , randId ) , s3BucketArn )
5669
5770 // Run `terraform output` to get the value of an output variable
5871 sesDomainIdentityArn := terraform .Output (t , terraformOptions , "ses_domain_identity_arn" )
5972 // Verify we're getting back the outputs we expect
60- assert .Contains (t , sesDomainIdentityArn , "identity/testing.cloudposse.co " )
73+ assert .Contains (t , sesDomainIdentityArn , "identity/modules.cptest.test-automation.app " )
6174
6275 // Run `terraform output` to get the value of an output variable
6376 sesReceiptRuleName := terraform .Output (t , terraformOptions , "ses_receipt_rule_name" )
6477 // Verify we're getting back the outputs we expect
65- assert .Equal (t , "eg-test-lambda-forwarder-test" , sesReceiptRuleName )
78+ assert .Equal (t , fmt . Sprintf ( "eg-test-lambda-forwarder-test-%s" , randId ) , sesReceiptRuleName )
6679
6780 // Run `terraform output` to get the value of an output variable
6881 sesReceiptRuleSetName := terraform .Output (t , terraformOptions , "ses_receipt_rule_set_name" )
6982 // Verify we're getting back the outputs we expect
70- assert .Equal (t , "eg-test-lambda-forwarder-test" , sesReceiptRuleSetName )
83+ assert .Equal (t , fmt . Sprintf ( "eg-test-lambda-forwarder-test-%s" , randId ) , sesReceiptRuleSetName )
7184}
0 commit comments