-
Notifications
You must be signed in to change notification settings - Fork 0
Add terraform test coverage for vpc + quilt modules #116
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
4 commits
Select commit
Hold shift + click to select a range
51eae3b
Add terraform test coverage for vpc + quilt modules
sir-sigurd 88682d7
Address review: pin test AWS provider, add new-VPC assertion
sir-sigurd ee640b4
Address review: README Test entry, wrapper cautions, internal smoke run
sir-sigurd 7de946c
Address review: existing-VPC + internal-ALB coverage symmetry
sir-sigurd 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
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,3 +1,4 @@ | ||
| .DS_Store | ||
| .terraform | ||
| .terraform.lock.hcl | ||
| tfplan |
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,8 @@ | ||
| AWSTemplateFormatVersion: "2010-09-09" | ||
| Description: >- | ||
| Test fixture for terraform test smoke runs. Stands in for the real Quilt | ||
| CloudFormation template so plan-time references (template_file / filemd5) | ||
| resolve. Not a deployable Quilt stack. | ||
| Resources: | ||
| Placeholder: | ||
| Type: AWS::CloudFormation::WaitConditionHandle |
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,96 @@ | ||
| # Wrapper root for the `quilt` module smoke tests. | ||
| # | ||
| # The smoke tests run against this wrapper rather than modules/quilt directly | ||
| # because the quilt module's `stack` output embeds sensitive values (DB + admin | ||
| # passwords); as a root module under test that trips a sensitive-output error. | ||
| # The wrapper re-exposes only the non-sensitive stack name. | ||
| # | ||
| # The required_providers block below is also load-bearing for the tests: | ||
| # declaring the provider requirement at the root is what lets the test's | ||
| # mock_provider engage for the whole module tree. Without a direct provider | ||
| # reference at the root, the mock never attaches and the child modules fall | ||
| # back to real AWS credentials. | ||
| terraform { | ||
| required_providers { | ||
| aws = { | ||
| source = "hashicorp/aws" | ||
| # Match what the modules under test transitively require: the | ||
| # terraform-aws-modules/vpc ~> 6.0 module needs aws >= 6.28. Pinning keeps | ||
| # CI deterministic and off a future major. (Note: examples/main.tf and | ||
| # modules/cnames still pin ~> 5.0, which is incompatible with that floor.) | ||
| version = "~> 6.0" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| variable "create_new_vpc" { | ||
| type = bool | ||
| } | ||
|
|
||
| variable "internal" { | ||
| type = bool | ||
| default = false | ||
| } | ||
|
|
||
| variable "vpc_id" { | ||
| type = string | ||
| default = null | ||
| } | ||
|
sir-sigurd marked this conversation as resolved.
|
||
|
|
||
| variable "api_endpoint" { | ||
| type = string | ||
| default = null | ||
| } | ||
|
|
||
| variable "intra_subnets" { | ||
| type = list(string) | ||
| default = null | ||
| } | ||
|
|
||
| variable "private_subnets" { | ||
| type = list(string) | ||
| default = null | ||
| } | ||
|
|
||
| variable "public_subnets" { | ||
| type = list(string) | ||
| default = null | ||
| } | ||
|
|
||
| variable "user_security_group" { | ||
| type = string | ||
| default = null | ||
| } | ||
|
sir-sigurd marked this conversation as resolved.
|
||
|
|
||
| variable "user_subnets" { | ||
| type = list(string) | ||
| default = null | ||
| } | ||
|
|
||
| # New inputs added to the quilt module must be threaded through here, or the | ||
| # smoke coverage silently narrows (the new input is never exercised). | ||
| module "quilt" { | ||
| source = "../../" | ||
|
|
||
| name = "quilt-test" | ||
| parameters = {} | ||
| template_file = "${path.module}/fixtures/quilt.yaml" | ||
|
|
||
| create_new_vpc = var.create_new_vpc | ||
| internal = var.internal | ||
| vpc_id = var.vpc_id | ||
| api_endpoint = var.api_endpoint | ||
| intra_subnets = var.intra_subnets | ||
| private_subnets = var.private_subnets | ||
| public_subnets = var.public_subnets | ||
| user_security_group = var.user_security_group | ||
| user_subnets = var.user_subnets | ||
| } | ||
|
sir-sigurd marked this conversation as resolved.
|
||
|
|
||
| # Re-expose ONLY the non-sensitive stack name. Do not output module.quilt.stack | ||
| # (it embeds the DB URL + admin password) or any *_password value — a sensitive | ||
| # root output makes `terraform test` fail, which is the whole reason this | ||
| # wrapper exists. | ||
| output "stack_name" { | ||
| value = module.quilt.stack.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,84 @@ | ||
| # Smoke tests for the public `quilt` module, run against the wrapper root in | ||
| # this directory (see main.tf). | ||
| # | ||
| # Plan-only with the AWS provider mocked: no credentials, no infrastructure. | ||
| # Exercises the full wiring (vpc + db + search + the CloudFormation stack), so | ||
| # a change that breaks the public boundary or the vpc pass-through fails in CI. | ||
| # | ||
| # Assertions reference known inputs (the stack name), not mocked computed | ||
| # attributes, whose generated values are intentionally arbitrary. | ||
|
|
||
| mock_provider "aws" { | ||
| # slice(..., 0, 2) and the cidrsubnet math in the vpc submodule need at | ||
| # least two AZ names; mocked collections are otherwise empty. | ||
| mock_data "aws_availability_zones" { | ||
| defaults = { | ||
| names = ["us-east-1a", "us-east-1b", "us-east-1c"] | ||
| } | ||
| } | ||
| } | ||
|
|
||
| run "new_vpc_plans" { | ||
| command = plan | ||
| variables { | ||
| create_new_vpc = true | ||
| internal = false | ||
| } | ||
| assert { | ||
| condition = output.stack_name == "quilt-test" | ||
| error_message = "The CloudFormation stack must be named after var.name" | ||
| } | ||
| } | ||
|
|
||
| run "new_vpc_internal_plans" { | ||
| command = plan | ||
| variables { | ||
| create_new_vpc = true | ||
| internal = true | ||
| } | ||
| # internal = true exercises the most conditional wiring in quilt/main.tf: | ||
| # the PublicSubnets/UserSubnets null-coalescing and the internal-gated api | ||
| # endpoint. | ||
| assert { | ||
| condition = output.stack_name == "quilt-test" | ||
| error_message = "The CloudFormation stack must be named after var.name" | ||
| } | ||
| } | ||
|
|
||
| run "existing_vpc_plans" { | ||
| command = plan | ||
| variables { | ||
| create_new_vpc = false | ||
| internal = false | ||
| vpc_id = "vpc-00000000000000000" | ||
| intra_subnets = ["subnet-intra-a", "subnet-intra-b"] | ||
| private_subnets = ["subnet-priv-a", "subnet-priv-b"] | ||
| public_subnets = ["subnet-pub-a", "subnet-pub-b"] | ||
| user_security_group = "sg-00000000000000000" | ||
| } | ||
| assert { | ||
| condition = output.stack_name == "quilt-test" | ||
| error_message = "The CloudFormation stack must be named after var.name" | ||
| } | ||
| } | ||
|
|
||
| run "existing_vpc_internal_plans" { | ||
| command = plan | ||
| variables { | ||
| create_new_vpc = false | ||
| internal = true | ||
| vpc_id = "vpc-00000000000000000" | ||
| api_endpoint = "vpce-00000000000000000" | ||
| intra_subnets = ["subnet-intra-a", "subnet-intra-b"] | ||
| private_subnets = ["subnet-priv-a", "subnet-priv-b"] | ||
| public_subnets = null | ||
| user_security_group = "sg-00000000000000000" | ||
| user_subnets = ["subnet-user-a", "subnet-user-b"] | ||
| } | ||
| # internal = true on the existing-VPC path exercises quilt's pass-through of | ||
| # api_endpoint + user_subnets and the internal-gated CFN wiring. | ||
| assert { | ||
| condition = output.stack_name == "quilt-test" | ||
| error_message = "The CloudFormation stack must be named after var.name" | ||
| } | ||
| } | ||
|
sir-sigurd marked this conversation as resolved.
|
||
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.