generated from cloudposse/terraform-example-module
-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix logic when
enabled = false
. Update tests. Update module version…
…s and GitHub workflows (#53) * Update versions * Updates * Updates * Updates * Updates
- Loading branch information
Showing
15 changed files
with
221 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,87 @@ | ||
package test | ||
|
||
import ( | ||
"math/rand" | ||
"strconv" | ||
"regexp" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/gruntwork-io/terratest/modules/random" | ||
"github.com/gruntwork-io/terratest/modules/terraform" | ||
testStructure "github.com/gruntwork-io/terratest/modules/test-structure" | ||
"github.com/stretchr/testify/assert" | ||
"k8s.io/apimachinery/pkg/util/runtime" | ||
) | ||
|
||
// Test the Terraform module in examples/complete using Terratest. | ||
func TestExamplesComplete(t *testing.T) { | ||
t.Parallel() | ||
|
||
rand.Seed(time.Now().UnixNano()) | ||
randID := strconv.Itoa(rand.Intn(100000)) | ||
randID := strings.ToLower(random.UniqueId()) | ||
attributes := []string{randID} | ||
|
||
rootFolder := "../../" | ||
terraformFolderRelativeToRoot := "examples/complete" | ||
varFiles := []string{"fixtures.us-east-2.tfvars"} | ||
|
||
tempTestFolder := testStructure.CopyTerraformFolderToTemp(t, rootFolder, terraformFolderRelativeToRoot) | ||
|
||
terraformOptions := &terraform.Options{ | ||
// The path to where our Terraform code is located | ||
TerraformDir: "../../examples/complete", | ||
TerraformDir: tempTestFolder, | ||
Upgrade: true, | ||
// Variables to pass to our Terraform code using -var-file options | ||
VarFiles: []string{"fixtures.us-east-2.tfvars"}, | ||
// We always include a random attribute so that parallel tests | ||
// and AWS resources do not interfere with each other | ||
VarFiles: varFiles, | ||
Vars: map[string]interface{}{ | ||
"attributes": attributes, | ||
}, | ||
} | ||
|
||
// At the end of the test, run `terraform destroy` to clean up any resources that were created | ||
defer terraform.Destroy(t, terraformOptions) | ||
defer cleanup(t, terraformOptions, tempTestFolder) | ||
|
||
// If Go runtime crushes, run `terraform destroy` to clean up any resources that were created | ||
defer runtime.HandleCrash(func(i interface{}) { | ||
cleanup(t, terraformOptions, tempTestFolder) | ||
}) | ||
|
||
// This will run `terraform init` and `terraform apply` and fail the test if there are any errors | ||
terraform.InitAndApply(t, terraformOptions) | ||
|
||
lambdaFunctionName := terraform.Output(t, terraformOptions, "lambda_forwarder_log_function_name") | ||
// Verify we're getting back the outputs we expect | ||
//assert.Contains(t, lambdaRdsArn, expectedlambdaRdsArn) | ||
|
||
assert.Equal(t, "eg-ue2-test-datadog-lambda-forwarder-"+randID+"-logs", lambdaFunctionName) | ||
} | ||
|
||
func TestExamplesCompleteDisabled(t *testing.T) { | ||
t.Parallel() | ||
randID := strings.ToLower(random.UniqueId()) | ||
attributes := []string{randID} | ||
|
||
rootFolder := "../../" | ||
terraformFolderRelativeToRoot := "examples/complete" | ||
varFiles := []string{"fixtures.us-east-2.tfvars"} | ||
|
||
tempTestFolder := testStructure.CopyTerraformFolderToTemp(t, rootFolder, terraformFolderRelativeToRoot) | ||
|
||
terraformOptions := &terraform.Options{ | ||
// The path to where our Terraform code is located | ||
TerraformDir: tempTestFolder, | ||
Upgrade: true, | ||
// Variables to pass to our Terraform code using -var-file options | ||
VarFiles: varFiles, | ||
Vars: map[string]interface{}{ | ||
"attributes": attributes, | ||
"enabled": false, | ||
}, | ||
} | ||
|
||
// At the end of the test, run `terraform destroy` to clean up any resources that were created | ||
defer cleanup(t, terraformOptions, tempTestFolder) | ||
|
||
// This will run `terraform init` and `terraform apply` and fail the test if there are any errors | ||
results := terraform.InitAndApply(t, terraformOptions) | ||
|
||
// Should complete successfully without creating or changing any resources. | ||
// Extract the "Resources:" section of the output to make the error message more readable. | ||
re := regexp.MustCompile(`Resources: [^.]+\.`) | ||
match := re.FindString(results) | ||
assert.Equal(t, "Resources: 0 added, 0 changed, 0 destroyed.", match, "Re-applying the same configuration should not change any resources") | ||
} |
Oops, something went wrong.