Skip to content

Commit 170a68b

Browse files
move to kitchen-terraform 3.0.x and terraform 0.11.0 (#19)
* moved to kitchen-terraform 3.0.x and terraform 0.11 in CI * condensed .travis.yml where possible
1 parent 53eb9e1 commit 170a68b

File tree

8 files changed

+97
-83
lines changed

8 files changed

+97
-83
lines changed

.kitchen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
driver:
33
name: "terraform"
4-
directory: "examples/test_fixtures"
4+
root_module_directory: "examples/test_fixtures"
55

66
provisioner:
77
name: "terraform"

.travis.yml

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
language: ruby
2-
32
sudo: false
4-
53
dist: trusty
6-
74
rvm:
85
- 2.4.2
96

@@ -20,67 +17,40 @@ install:
2017

2118
before_script:
2219
- echo 'before_script'
23-
# Get a random variable from the awscli and use it through the remainder of the test cycle.
20+
# Get a random region from the awscli and use it through the remainder of the test cycle.
2421
- export AWS_REGION=$(docker run --env AWS_DEFAULT_REGION=us-east-2 --env AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} --env AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} garland/aws-cli-docker aws ec2 describe-regions --query 'Regions[].{Name:RegionName}' --output text | shuf | head -n1)
25-
- echo "using AWS_REGION=${AWS_REGION}"
2622
- export TF_VAR_region=${AWS_REGION}
27-
- wget https://releases.hashicorp.com/terraform/0.10.7/terraform_0.10.7_linux_amd64.zip
28-
- unzip terraform_0.10.7_linux_amd64
29-
- chmod +x terraform
30-
- mkdir -p ${HOME}/bin
31-
- export PATH=${PATH}:${HOME}/bin
32-
- mv terraform ${HOME}/bin/
33-
- rm -f terraform_*
23+
- echo "using AWS_REGION=${AWS_REGION}"
24+
- curl --silent --output terraform.zip https://releases.hashicorp.com/terraform/0.11.0/terraform_0.11.0_linux_amd64.zip
25+
- sha256sum terraform.zip | grep "402b4333792967986383670134bb52a8948115f83ab6bda35f57fa2c3c9e9279" -q
26+
- unzip terraform.zip ; rm -f terraform.zip; chmod +x terraform
27+
- mkdir -p ${HOME}/bin ; export PATH=${PATH}:${HOME}/bin; mv terraform ${HOME}/bin/
3428
- terraform -v
3529

3630
script:
3731
- echo 'script'
38-
# no terraform through docker until kitchen-terraform supports it
39-
# - docker run -i -t -v $(pwd):/app/ -w /app/ hashicorp/terraform:light init
40-
# - docker run -i -t -v $(pwd):/app/ -w /app/ hashicorp/terraform:light fmt -check=true
41-
# - docker run -i -t -v $(pwd):/app/ -w /app/ hashicorp/terraform:light validate
4232
- terraform init
4333
- terraform fmt -check=true
4434
- terraform validate -var "region=${AWS_REGION}" -var "certificate_arn=arn:aws:iam::123456789012:server-certificate/test_cert-123456789012" -var "health_check_path=/" -var "subnets=[]" -var "vpc_id=vpc-abcde012" -var "alb_name=my-alb" -var "alb_security_groups=[]"
4535
- docker run --rm -v $(pwd):/app/ --workdir=/app/ -t wata727/tflint --error-with-issues
4636
- cd examples/test_fixtures
47-
# this line is to change the source of the root module to 2 dirs back which works when validating in CI but when running through test kitchen, we need to source from 3 dirs up, oddly
48-
- sed -i.bak 's/\.\.\/\.\.\/\.\./\.\.\/\.\./g' main.tf
49-
# - docker run -i -t -v $(pwd):/app/ -w /app/ hashicorp/terraform:light init
50-
# - docker run -i -t -v $(pwd):/app/ -w /app/ hashicorp/terraform:light fmt -check=true
51-
# - docker run -i -t -v $(pwd):/app/ -w /app/ hashicorp/terraform:light validate
5237
- terraform init
5338
- terraform fmt -check=true
5439
- terraform validate
55-
# FIXME: tflint is unhappy with sourcing a module from a relative dir here.
56-
# - docker run --rm -v $(pwd):/data --workdir=/data -t wata727/tflint --error-with-issues
57-
- mv main.tf.bak main.tf
5840
- cd -
59-
- pwd
60-
- ls -lah
6141
- terraform -v
62-
- kitchen test --destroy always
63-
64-
# after_success:
65-
# - echo 'after_success'
66-
67-
# after_failure:
68-
# - echo 'after_failure'
69-
70-
before_deploy:
71-
# check if this is new release and conditionally continue?
72-
- echo 'before_deploy phase'
42+
- bundle exec kitchen test --destroy always
7343

7444
deploy:
75-
# likely want to publish to the registry
45+
# publish to the registry when those APIs are documented
7646
provider: script
7747
script: ci/deploy.sh
7848
on:
79-
branch: dev
80-
81-
# after_deploy:
82-
# notify of success/failure provide links
83-
# - echo 'after_deploy'
84-
85-
# after_script:
86-
# - echo 'after_script'
49+
branch: master
50+
51+
notifications:
52+
email:
53+
recipients:
54+
55+
on_success: change
56+
on_failure: change

CHANGELOG.md

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,116 @@
11
# Change Log
2+
23
All notable changes to this project will be documented in this file.
34

4-
The format is based on [Keep a Changelog](http://keepachangelog.com/)
5-
and this project adheres to [Semantic Versioning](http://semver.org/).
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this
6+
project adheres to [Semantic Versioning](http://semver.org/).
7+
8+
## [2.1.1] - 2017-11-27
9+
10+
#### Added
11+
12+
* variable `health_check_matcher` determines a set or range of successful HTTP
13+
status codes for target group health checks (🧀 @mbolek).
14+
* adapted test kitchen configuration to KT 3.0.x.
615

716
## [2.1.0] - 2017-11-16
17+
818
#### Added
9-
* outputs added for listeners - these can be useful for ECR integration (🍰 @mbolek).
10-
* Moved default `alb_protocols` to HTTP to lower barier of entry in getting started.
19+
20+
* outputs added for listeners - these can be useful for ECR integration (🍰
21+
@mbolek).
22+
* Moved default `alb_protocols` to HTTP to lower barier of entry in getting
23+
started.
1124

1225
## [2.0.0] - 2017-11-06
26+
1327
#### Added
14-
* added `create_log_bucket` and `enable_logging` to help control logging more granularly.
28+
29+
* added `create_log_bucket` and `enable_logging` to help control logging more
30+
granularly.
1531

1632
#### Changed
17-
* existing log-related variables made more descriptive (this is the breaking change)
33+
34+
* existing log-related variables made more descriptive (this is the breaking
35+
change)
1836
* S3 policy related test made more explicit (⭐ @antonbabenko)
1937

2038
## [1.0.3] - 2017-10-19
39+
2140
#### Added
41+
2242
* TravisCI configuration added and now passing.
2343
* badge added to docs.
2444
* permissions section now in the example readme.
25-
* placeholder shell script added for CI deployment. Eventually this should conditionally release to the registry when those APIs become available.
45+
* placeholder shell script added for CI deployment. Eventually this should
46+
conditionally release to the registry when those APIs become available.
2647

2748
#### Changed
49+
2850
* altered tf variable `aws_region` to `region`.
29-
* replaced hardcoding the region to instead use a random region as retrieved by an awscli docker container within CI.
30-
* example cert is now a regionally-specific resource enabling tests to run in various regions at once and not collide.
51+
* replaced hardcoding the region to instead use a random region as retrieved by
52+
an awscli docker container within CI.
53+
* example cert is now a regionally-specific resource enabling tests to run in
54+
various regions at once and not collide.
3155
* ruby version bump means `Rhcl` becomes `rhcl`.
3256

3357
## [1.0.2] - 2017-10-12
58+
3459
#### Added
60+
3561
* moved data sources to dedicated `data.tf` file.
36-
* `aws_caller_identity` now used to gather account_id rather than using a variable.
62+
* `aws_caller_identity` now used to gather account_id rather than using a
63+
variable.
3764
* tests added for `target_group` and expanded for `alb`.
38-
* input variables added for health checks, bucket policy, force_destroy_log_bucket - increasing flexibility.
65+
* input variables added for health checks, bucket policy,
66+
force_destroy_log_bucket - increasing flexibility.
3967

4068
#### Changed
41-
* altered structure of module to conform to the new [Terraform registry standards](https://www.terraform.io/docs/registry/modules/publish.html#requirements)
42-
* `principle_account_id` (sp) moved to a data source rather than variable map. Spelling corrected.
43-
* removed redundant `/test/alb` directory which had module contents copied. Test kitchen now uses the module itself.
69+
70+
* altered structure of module to conform to the new
71+
[Terraform registry standards](https://www.terraform.io/docs/registry/modules/publish.html#requirements)
72+
* `principle_account_id` (sp) moved to a data source rather than variable map.
73+
Spelling corrected.
74+
* removed redundant `/test/alb` directory which had module contents copied. Test
75+
kitchen now uses the module itself.
4476
* pinned examples to provider and terraform versions to harden versioning.
45-
* self signed cert added to the test fixtures, eliminating the need for manual upload and terraform.tfvars configuration.
46-
* modules referenced in the test fixture are now sourced from the terraform registry.
47-
* removed bucket_policy.json in favor of creating the policy via the `aws_iam_policy_document` resource or optionally a variable.
77+
* self signed cert added to the test fixtures, eliminating the need for manual
78+
upload and terraform.tfvars configuration.
79+
* modules referenced in the test fixture are now sourced from the terraform
80+
registry.
81+
* removed bucket_policy.json in favor of creating the policy via the
82+
`aws_iam_policy_document` resource or optionally a variable.
4883
* stringed list variables moved to native lists
4984

5085
## [1.0.1] - 2017-09-14
86+
5187
#### Added
88+
5289
* tag maps can now be provided (thanks @kwach)
5390

5491
#### Changed
92+
5593
* optional S3 logging (thanks @marocchino)
5694

5795
## [1.0.0] - 2017-03-16
96+
5897
#### Added
98+
5999
* Tests and fixtures for ALB components using awspec and test kitchen
60100
* S3 log bucket and policy rendering for logging now in place
61101
* root_principle_id added and referenced through a map for s3 bucket policy
62102
* string lists moved to native list types
63103
* default region removed
64104

65105
#### Changed
66-
* Restructured project templates to alb dir to add testing. This is a breaking change so upping major version.
106+
107+
* Restructured project templates to alb dir to add testing. This is a breaking
108+
change so upping major version.
67109
* Redundant examples dir removed
68110
* Updated documentation
69111

70112
## [0.1.0] - 2017-03-09
113+
71114
#### Added
115+
72116
* Initial release.

Gemfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
ruby '2.4.2'
22

33
source 'https://rubygems.org/' do
4-
gem 'kitchen-terraform', '~> 2.0'
54
gem 'kitchen-verifier-awspec'
6-
gem 'awspec'
75
gem 'rhcl'
6+
gem 'awspec'
87
end
8+
9+
gem(
10+
"kitchen-terraform",
11+
git: "https://github.com/newcontext-oss/kitchen-terraform",
12+
branch: "ncs-alane-3.0.0"
13+
)

examples/test_fixtures/main.tf

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
terraform {
2-
required_version = "~> 0.10.6"
2+
required_version = ">= 0.10.0"
33
}
44

55
provider "aws" {
66
region = "${var.region}"
7-
version = "~> 1.0.0"
7+
version = ">= 1.0.0"
88
}
99

10-
provider "template" {
11-
version = "~> 1.0.0"
12-
}
10+
provider "template" {}
1311

1412
resource "aws_iam_server_certificate" "fixture_cert" {
1513
name = "test_cert-${data.aws_caller_identity.fixtures.account_id}-${var.region}"
16-
certificate_body = "${file("${path.module}/../../../examples/test_fixtures/certs/example.crt.pem")}"
17-
private_key = "${file("${path.module}/../../../examples/test_fixtures/certs/example.key.pem")}"
14+
certificate_body = "${file("${path.module}/../../examples/test_fixtures/certs/example.crt.pem")}"
15+
private_key = "${file("${path.module}/../../examples/test_fixtures/certs/example.key.pem")}"
1816

1917
lifecycle {
2018
create_before_destroy = true
@@ -40,7 +38,7 @@ module "security-group" {
4038
}
4139

4240
module "alb" {
43-
source = "../../.."
41+
source = "../.."
4442
alb_name = "my-alb"
4543
alb_security_groups = ["${module.security-group.this_security_group_id}"]
4644
region = "${var.region}"

main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
provider "aws" {
44
region = "${var.region}"
5-
version = "~> 1.0.0"
5+
version = ">= 1.0.0"
66
}
77

88
resource "aws_alb" "main" {
@@ -60,7 +60,7 @@ resource "aws_alb_target_group" "target_group" {
6060
unhealthy_threshold = "${var.health_check_unhealthy_threshold}"
6161
timeout = "${var.health_check_timeout}"
6262
protocol = "${var.backend_protocol}"
63-
matcher = "${var.health_check_code}"
63+
matcher = "${var.health_check_matcher}"
6464
}
6565

6666
stickiness {

test/integration/default/local_alb.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
module_vars = Rhcl.parse(File.open('examples/test_fixtures/variables.tf'))
55
log_location_prefix = module_vars['variable']['log_location_prefix']['default']
66

7-
tf_state = JSON.parse(File.open('.kitchen/kitchen-terraform/default-aws/terraform.tfstate').read)
7+
tf_state = JSON.parse(File.open('terraform.tfstate.d/kitchen-terraform-default-aws/terraform.tfstate').read)
88
principal_account_id = tf_state['modules'][0]['outputs']['principal_account_id']['value']
99
account_id = tf_state['modules'][0]['outputs']['account_id']['value']
1010
vpc_id = tf_state['modules'][0]['outputs']['vpc_id']['value']
@@ -14,7 +14,6 @@
1414
ENV['AWS_REGION'] = region
1515
# this must match the format in examples/test_fixtures/locals.tf
1616
log_bucket_name = 'logs-' + region + '-' + account_id
17-
# subnet_ids = tf_state['modules'][0]['outputs']['subnet_ids']['value']
1817

1918
describe alb('my-alb') do
2019
it { should exist }
@@ -25,15 +24,13 @@
2524
its (:scheme) {should eq 'internet-facing'}
2625
its (:ip_address_type) {should eq 'ipv4'}
2726
it { should have_security_group(security_group_id) }
28-
# it { should have_subnet(subnet_id) }
2927
end
3028

3129
describe alb_target_group('my-alb-tg') do
3230
it { should exist }
3331
its(:health_check_path) { should eq '/' }
3432
its(:health_check_port) { should eq 'traffic-port' }
3533
its(:health_check_protocol) { should eq 'HTTP' }
36-
its(:health_check_code) { should eq '200-299' }
3734
it { should belong_to_alb('my-alb') }
3835
it { should belong_to_vpc('my-vpc') }
3936
end

variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ variable "health_check_unhealthy_threshold" {
8080
default = 3
8181
}
8282

83-
variable "health_check_code" {
84-
description = "The HTTP codes that are a success when checking TG health"
83+
variable "health_check_matcher" {
84+
description = "The HTTP codes that are a success when checking TG health."
8585
default = "200-299"
8686
}
8787

0 commit comments

Comments
 (0)