|
1 | 1 | package test
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "strings" |
4 | 5 | "testing"
|
5 | 6 |
|
6 | 7 | "github.com/gruntwork-io/terratest/modules/terraform"
|
@@ -35,6 +36,58 @@ func TestPeeringActive(t *testing.T) {
|
35 | 36 | }
|
36 | 37 | }
|
37 | 38 |
|
| 39 | +func TestConnectionName(t *testing.T) { |
| 40 | + var testCases = []struct { |
| 41 | + name string |
| 42 | + expected string |
| 43 | + }{ |
| 44 | + {"DefaultName", "tf-single-account-single-region"}, |
| 45 | + {"CustomName", "tf-custom-name"}, |
| 46 | + } |
| 47 | + |
| 48 | + for _, tc := range testCases { |
| 49 | + t.Run(tc.name, func(t *testing.T) { |
| 50 | + var tfVars = make(map[string]interface{}) |
| 51 | + // Apply the fixtures |
| 52 | + fixturesTerraformOptions := &terraform.Options{ |
| 53 | + TerraformDir: "./fixtures/single-account-single-region", // hardcoded |
| 54 | + } |
| 55 | + |
| 56 | + // Remove the fixtures resources in the end of the test |
| 57 | + defer terraform.Destroy(t, fixturesTerraformOptions) |
| 58 | + |
| 59 | + // Install Prerequisites |
| 60 | + terraform.InitAndApply(t, fixturesTerraformOptions) |
| 61 | + |
| 62 | + // Get the outputs from fixtures |
| 63 | + thisVpcID := terraform.Output(t, fixturesTerraformOptions, "this_vpc_id") |
| 64 | + peerVpcID := terraform.Output(t, fixturesTerraformOptions, "peer_vpc_id") |
| 65 | + |
| 66 | + tfVars["this_vpc_id"] = thisVpcID |
| 67 | + tfVars["peer_vpc_id"] = peerVpcID |
| 68 | + // This is a hack, but I'm too tired to figure out something better |
| 69 | + if strings.EqualFold(tc.name, "CustomName") { |
| 70 | + tfVars["name"] = tc.expected |
| 71 | + } |
| 72 | + |
| 73 | + // Terraform Options for module |
| 74 | + moduleTerraformOptions := &terraform.Options{ |
| 75 | + TerraformDir: "../examples/custom-name-tag", // hardcoded |
| 76 | + Vars: tfVars, |
| 77 | + } |
| 78 | + |
| 79 | + // Remove the module resources in the end of the test |
| 80 | + defer terraform.Destroy(t, moduleTerraformOptions) |
| 81 | + // Create module resources |
| 82 | + terraform.InitAndApply(t, moduleTerraformOptions) |
| 83 | + var conn any |
| 84 | + terraform.OutputStruct(t, moduleTerraformOptions, "vpc_peering_connection", &conn) |
| 85 | + actualName := conn.(map[string]any)["tags_all"].(map[string]any)["Name"].(string) |
| 86 | + assert.Equal(t, tc.expected, actualName) |
| 87 | + }) |
| 88 | + } |
| 89 | +} |
| 90 | + |
38 | 91 | func terratestRun(tc TestCase, t *testing.T) {
|
39 | 92 | var tfVars = make(map[string]interface{})
|
40 | 93 | // Assertions
|
|
0 commit comments