1
1
package test
2
2
3
3
import (
4
+ "fmt"
5
+ "math/rand"
6
+ "strconv"
7
+ "testing"
8
+ "time"
9
+
4
10
"github.com/gruntwork-io/terratest/modules/terraform"
5
11
"github.com/stretchr/testify/assert"
6
- "testing"
7
12
)
8
13
9
14
// Test the Terraform module in examples/complete using Terratest.
10
15
func TestExamplesComplete (t * testing.T ) {
11
16
t .Parallel ()
12
17
18
+ rand .Seed (time .Now ().UnixNano ())
19
+
20
+ randId := strconv .Itoa (rand .Intn (100000 ))
21
+ attributes := []string {randId }
22
+
13
23
terraformOptions := & terraform.Options {
14
24
// The path to where our Terraform code is located
15
25
TerraformDir : "../../examples/complete" ,
16
26
Upgrade : true ,
17
27
// 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
+ },
19
32
}
20
33
21
34
// 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) {
32
45
// Run `terraform output` to get the value of an output variable
33
46
artifactUrl := terraform .Output (t , terraformOptions , "artifact_url" )
34
47
// 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 )
36
49
37
50
// Run `terraform output` to get the value of an output variable
38
51
lambdaFunctionArn := terraform .Output (t , terraformOptions , "lambda_function_arn" )
@@ -47,25 +60,25 @@ func TestExamplesComplete(t *testing.T) {
47
60
// Run `terraform output` to get the value of an output variable
48
61
lambdaIamPolicyName := terraform .Output (t , terraformOptions , "lambda_iam_policy_name" )
49
62
// 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 )
51
64
52
65
// Run `terraform output` to get the value of an output variable
53
66
s3BucketArn := terraform .Output (t , terraformOptions , "s3_bucket_arn" )
54
67
// 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 )
56
69
57
70
// Run `terraform output` to get the value of an output variable
58
71
sesDomainIdentityArn := terraform .Output (t , terraformOptions , "ses_domain_identity_arn" )
59
72
// 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 " )
61
74
62
75
// Run `terraform output` to get the value of an output variable
63
76
sesReceiptRuleName := terraform .Output (t , terraformOptions , "ses_receipt_rule_name" )
64
77
// 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 )
66
79
67
80
// Run `terraform output` to get the value of an output variable
68
81
sesReceiptRuleSetName := terraform .Output (t , terraformOptions , "ses_receipt_rule_set_name" )
69
82
// 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 )
71
84
}
0 commit comments