-
Notifications
You must be signed in to change notification settings - Fork 8
CA-18 RDS Postgres Initial Tests #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
452767e
CI-159 Update Makefile
rosemarywang 293fac6
adding first test
hbarros-caylent 1e25f16
adding first test
hbarros-caylent cade63e
simple test
hbarros-caylent 5391968
adding helper function for connectivity test
hbarros-caylent 89b29a2
Merge tag '2.0.0' into CA-18
hbarros-caylent 23ff23f
CA-18 adding initial tests
hbarros-caylent 620fa76
standard for test_examples folder name
hbarros-caylent 8463d01
make lint, terraform/docs and fmt
hbarros-caylent 057d812
go mod tidy
hbarros-caylent 7df5db6
fix comments
hbarros-caylent 7195926
Merge remote-tracking branch 'upstream/master' into CA-18
hbarros-caylent d030414
big refactor - test_structure + testCases
hbarros-caylent 8b97937
updating versions
hbarros-caylent 515375f
fixes module name
hbarros-caylent 4762b16
CA-71 - update tests/ to instantiate examples/
hbarros-caylent 97f5ba6
using expectApplyError
hbarros-caylent bd89420
1st version of cloudwatch logs integration
hbarros-caylent 3dfcd41
adding upgrade logs and updating local.tfvars
hbarros-caylent 4eb6a4a
adding parameter log_statement=all
hbarros-caylent 14a6138
creates param group log parameters from module variables
hbarros-caylent 7302b65
Merge tag '3.1.0' into CA-18
hbarros-caylent 2c4bc48
fix: adding require lib
hbarros-caylent 1b10888
adding comments
hbarros-caylent 049ecc6
adding test README
hbarros-caylent ac2069f
Merge remote-tracking branch 'upstream/master' into CA-18
hbarros-caylent ecc9d93
smallfix
hbarros-caylent f420039
update to README
hbarros-caylent fea9c3f
removing local.tfvars
hbarros-caylent 11ba9a2
reverting change on output
hbarros-caylent b1e2f02
Updated documentation
joseamoroso cfa8749
Changed indivual outputs to module output.
joseamoroso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,6 +1,7 @@ | ||
| # Local .terraform directories | ||
| **/.terraform/* | ||
|
|
||
| *.terraform.lock.hcl | ||
| # .tfstate files | ||
| *.tfstate | ||
| *.tfstate.* | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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,8 +1,3 @@ | ||
| output "ingress_ports" { | ||
| value = module.sg-ports | ||
| description = "List of ingress ports" | ||
| } | ||
|
|
||
| output "rds" { | ||
| value = module.rds_postgres | ||
| } | ||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # Tests | ||
|
|
||
| This folder contains automated tests for this Module. All of the tests are written in [Go](https://golang.org/). | ||
| Most of these are "integration tests" that deploy real infrastructure using Terraform and verify that infrastructure works as expected using a helper library called [Terratest](https://github.com/gruntwork-io/terratest). | ||
|
|
||
|
|
||
|
|
||
| ## WARNING WARNING WARNING | ||
|
|
||
| **Note #1**: Many of these tests create real resources in an AWS account and then try to clean those resources up at the end of a test run. That means these tests may cost you money to run! When adding tests, please be considerate of the resources you create and take extra care to clean everything up when you're done! | ||
|
|
||
| **Note #2**: Never forcefully shut the tests down (e.g. by hitting `CTRL + C`) or the cleanup tasks won't run! | ||
|
|
||
| **Note #3**: We need to set `-timeout 60m` on all tests not because they necessarily take that long, but because Go has a default test timeout of 10 minutes, after which it forcefully kills the tests with a `SIGQUIT`, preventing the cleanup tasks from running. Therefore, we set an overlying long timeout to make sure all tests have enough time to finish and clean up. | ||
|
|
||
|
|
||
|
|
||
| ## Running the tests | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| - Install the latest version of [Go](https://golang.org/). | ||
| - Install [Terraform](https://www.terraform.io/downloads.html). | ||
| - Configure your AWS credentials using one of the [options supported by the AWS SDK](http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html). Usually, the easiest option is to set the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables. | ||
|
|
||
|
|
||
| ### Run all the tests | ||
|
|
||
| ```bash | ||
| go test -v -timeout 60m | ||
| ``` | ||
|
|
||
|
|
||
| ### Run a specific test | ||
|
|
||
| To run a specific test called `TestFoo`: | ||
|
|
||
| ```bash | ||
| go test -v -timeout 60m -run TestFoo | ||
| ``` | ||
|
|
||
| When using `t.Run("test_name",...)` inside a test function, you may run a specific test with: | ||
| ```bash | ||
| go test -v -timeout 60m -run TestFoo/test_name | ||
| ``` |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| package test | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/gruntwork-io/terratest/modules/aws" | ||
| "github.com/gruntwork-io/terratest/modules/random" | ||
| "github.com/gruntwork-io/terratest/modules/terraform" | ||
| test_structure "github.com/gruntwork-io/terratest/modules/test-structure" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // These const are declared according to what is found at "../../examples/minimal/main.tf" | ||
| const ( | ||
| expectedPw = "examplePassword" | ||
| expectedUsername = "exampleUsername" | ||
| expectedDBName = "example0" | ||
| ) | ||
|
|
||
| // initTestCases initializes a list of RdsTestCase | ||
| func initTestCases() []RdsTestCase { | ||
| return []RdsTestCase{ | ||
| { | ||
| testName: "minimal", | ||
| expectApplyError: false, | ||
| vars: map[string]interface{}{ | ||
| "vpc_cidr": "172.18.0.0/18", | ||
| "database_subnets": []string{"172.18.0.0/24", "172.18.1.0/24"}, | ||
| "egress_cidr_blocks": []string{"0.0.0.0/0"}, | ||
| "ingress_cidr_blocks": []string{"0.0.0.0/0"}, | ||
| "name_prefix": "", | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| // TestTerraformCreateRDS runs all test cases | ||
| func TestTerraformCreateRDS(t *testing.T) { | ||
|
|
||
| testCases := initTestCases() | ||
|
|
||
| for _, testCase := range testCases { | ||
| testCase := testCase | ||
|
|
||
| t.Run(testCase.testName, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| // These will create a tempTestFolder for each bucketTestCase. | ||
| tempTestFolder := test_structure.CopyTerraformFolderToTemp(t, "..", "test_examples/minimal") | ||
|
|
||
| // this stage will generate a random `awsRegion` and a `uniqueId` to be used in tests. | ||
| test_structure.RunTestStage(t, "pick_new_randoms", func() { | ||
| usRegions := []string{"us-east-1", "us-east-2", "us-west-1", "us-west-2"} | ||
| // This function will first check for the Env Var TERRATEST_REGION and return its value if != "" | ||
| awsRegion := aws.GetRandomStableRegion(t, usRegions, nil) | ||
|
|
||
| test_structure.SaveString(t, tempTestFolder, "region", awsRegion) | ||
| test_structure.SaveString(t, tempTestFolder, "unique_id", strings.ToLower(random.UniqueId())) | ||
| }) | ||
|
|
||
| defer test_structure.RunTestStage(t, "teardown", func() { | ||
| teraformOptions := test_structure.LoadTerraformOptions(t, tempTestFolder) | ||
| terraform.Destroy(t, teraformOptions) | ||
| }) | ||
|
|
||
| test_structure.RunTestStage(t, "setup_options", func() { | ||
| awsRegion := test_structure.LoadString(t, tempTestFolder, "region") | ||
| uniqueID := test_structure.LoadString(t, tempTestFolder, "unique_id") | ||
|
|
||
| testCase.vars["name_prefix"] = uniqueID | ||
|
|
||
| terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{ | ||
| TerraformDir: tempTestFolder, | ||
| Vars: testCase.vars, | ||
| EnvVars: map[string]string{ | ||
| "AWS_REGION": awsRegion, | ||
| }, | ||
| }) | ||
|
|
||
| test_structure.SaveTerraformOptions(t, tempTestFolder, terraformOptions) | ||
| }) | ||
|
|
||
| test_structure.RunTestStage(t, "create_rds", func() { | ||
| terraformOptions := test_structure.LoadTerraformOptions(t, tempTestFolder) | ||
| _, err := terraform.InitAndApplyE(t, terraformOptions) | ||
|
|
||
| if testCase.expectApplyError { | ||
| require.Error(t, err) | ||
| // If it failed as expected, we should skip the rest (validate function). | ||
| t.SkipNow() | ||
| } | ||
| }) | ||
|
|
||
| test_structure.RunTestStage(t, "validate", func() { | ||
| awsRegion := test_structure.LoadString(t, tempTestFolder, "region") | ||
| terraformOptions := test_structure.LoadTerraformOptions(t, tempTestFolder) | ||
| validateModuleOutputs(t, | ||
| terraformOptions, | ||
| awsRegion, | ||
| int64(5432), | ||
| expectedUsername, | ||
| expectedDBName, | ||
| ) | ||
| }) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| module github.com/Datatamer/terraform-aws-rds-postgres | ||
|
|
||
| go 1.16 | ||
|
|
||
| require ( | ||
| github.com/aws/aws-sdk-go v1.40.40 | ||
| github.com/gruntwork-io/terratest v0.37.8 | ||
| github.com/stretchr/testify v1.7.0 | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.