-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Adding tests for vpc, subnets, and route tables #31
Merged
antonbabenko
merged 10 commits into
terraform-aws-modules:master
from
newcontext-oss:master
Feb 5, 2018
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5a67bd9
Adding base-level tests for simple-example
brandonjbjelland 65958c2
gitignoring test kitchen internals
brandonjbjelland d7fea91
incorporating feedback from newcontext folks
brandonjbjelland 08b963e
comment clean up before PR
brandonjbjelland 1aff6ac
Merge remote-tracking branch 'upstream/master'
83d07f3
upgrading to kt 3.1.x
722c368
test repaired for kt 3 compat
6163ab3
removing the gemfile lock
96c492d
making md linter happy and adjusting content to match test fixture
9f74da9
PR feedback and rubocop compliance
brandonjbjelland 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 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,4 +1,6 @@ | ||
.terraform | ||
terraform.tfstate | ||
*.tfstate* | ||
.kitchen | ||
terraform.tfstate | ||
terraform.tfvars | ||
Gemfile.lock |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
driver: | ||
name: "terraform" | ||
root_module_directory: "examples/test_fixture" | ||
|
||
provisioner: | ||
name: "terraform" | ||
|
||
platforms: | ||
- name: "aws" | ||
|
||
verifier: | ||
name: "awspec" | ||
|
||
suites: | ||
- name: "default" | ||
verifier: | ||
name: "awspec" | ||
patterns: | ||
- "test/integration/default/test_vpc.rb" |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
2.4.2 |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
ruby '2.4.2' | ||
|
||
source 'https://rubygems.org/' do | ||
gem 'aws-sdk', '~> 3.0.1' | ||
gem 'awspec', '~> 1.4.0' | ||
gem 'kitchen-terraform', '~> 3.1' | ||
gem 'kitchen-verifier-awspec', '~> 0.1.1' | ||
gem 'rhcl', '~> 0.1.0' | ||
end |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Test fixture of simple VPC | ||
|
||
Configuration in this directory creates a set of VPC resources to be tested by test kitchen. | ||
|
||
There is a public and private subnet created per availability zone in addition to single NAT Gateway shared between 2 availability zones. | ||
|
||
## Usage | ||
|
||
To run the tests, from the repo root execute: | ||
|
||
```bash | ||
$ kitchen test | ||
... | ||
Finished in 4.25 seconds (files took 2.75 seconds to load) | ||
20 examples, 0 failures | ||
|
||
Finished verifying <default-aws> (0m9.03s). | ||
-----> Kitchen is finished. (0m9.40s) | ||
``` | ||
|
||
This will destroy any existing test resources, create the resources afresh, run the tests, report back, and destroy the resources. |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
provider "aws" { | ||
region = "${var.region}" | ||
} | ||
|
||
data "aws_availability_zones" "available" {} | ||
|
||
module "vpc" { | ||
source = "../.." | ||
name = "test-example" | ||
cidr = "10.0.0.0/16" | ||
azs = ["${data.aws_availability_zones.available.names[0]}", "${data.aws_availability_zones.available.names[1]}"] | ||
private_subnets = ["10.0.1.0/24", "10.0.2.0/24"] | ||
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"] | ||
enable_nat_gateway = true | ||
single_nat_gateway = true | ||
|
||
tags = { | ||
Owner = "user" | ||
Environment = "dev" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
output "region" { | ||
description = "Region we created the resources in." | ||
value = "${var.region}" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
variable "region" { | ||
default = "eu-west-1" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'awspec' | ||
require 'aws-sdk' | ||
require 'rhcl' | ||
|
||
# should strive to randomize the region for more robust testing | ||
example_main = Rhcl.parse(File.open('examples/test_fixture/main.tf')) | ||
vpc_name = example_main['module']['vpc']['name'] | ||
user_tag = example_main['module']['vpc']['tags']['Owner'] | ||
environment_tag = example_main['module']['vpc']['tags']['Environment'] | ||
state_file = 'terraform.tfstate.d/kitchen-terraform-default-aws/terraform.tfstate' | ||
tf_state = JSON.parse(File.open(state_file).read) | ||
region = tf_state['modules'][0]['outputs']['region']['value'] | ||
ENV['AWS_REGION'] = region | ||
|
||
ec2 = Aws::EC2::Client.new(region: region) | ||
azs = ec2.describe_availability_zones | ||
zone_names = azs.to_h[:availability_zones].first(2).map { |az| az[:zone_name] } | ||
|
||
describe vpc(vpc_name.to_s) do | ||
it { should exist } | ||
it { should be_available } | ||
it { should have_tag('Name').value(vpc_name.to_s) } | ||
it { should have_tag('Owner').value(user_tag.to_s) } | ||
it { should have_tag('Environment').value(environment_tag.to_s) } | ||
it { should have_route_table("#{vpc_name}-public") } | ||
zone_names.each do |az| | ||
it { should have_route_table("#{vpc_name}-private-#{az}") } | ||
end | ||
end | ||
|
||
zone_names.each do |az| | ||
describe subnet("#{vpc_name}-public-#{az}") do | ||
it { should exist } | ||
it { should be_available } | ||
it { should belong_to_vpc(vpc_name.to_s) } | ||
it { should have_tag('Name').value("#{vpc_name}-public-#{az}") } | ||
it { should have_tag('Owner').value(user_tag.to_s) } | ||
it { should have_tag('Environment').value(environment_tag.to_s) } | ||
end | ||
end |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert these in gitignore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure when
terraform.tfstate
(tests should confine these to an already ignored dir) orterraform.tfvars
(all vars are packaged, why would we need override) would exist in the repo. Can you explain the use case for either of those existing within the module?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
During work, I run code from
examples
on my mac and don't want to committerraform.tfstate
file. Sometimes I also have specialterraform.tfvars
in specific examples but it is rather seldom when I need it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed, but consider moving the examples from manually run to kitchen terraform to also run with the automated suite. Even a test fixture without tests is valuable and lowers developer effort. That would make the gitignores here irrelevant.