Skip to content

Commit

Permalink
improvements identified by doing this for a 2nd module (#10)
Browse files Browse the repository at this point in the history
* change git resource to be a generic name so it can be reused

* remove ci parameter used with test.sh (test cannot be run locally with remote state and secrets injected)
rename name_prefixes to reduce chance of creating resources with existing names

* bump terraform version used in examples and travis to 0.11.11
  • Loading branch information
colincoleman authored Jan 3, 2019
1 parent 59eb1d5 commit 813d438
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 47 deletions.
32 changes: 16 additions & 16 deletions .ci/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ jobs:
- name: test-default
plan:
- aggregate:
- get: terraform-aws-vpc
- get: this-module
trigger: true
- task: apply
params:
Expand All @@ -12,27 +12,27 @@ jobs:
AWS_SECRET_ACCESS_KEY: ((telia-divx-common-services-stage-secret-key))
AWS_SESSION_TOKEN: ((telia-divx-common-services-stage-session-token))
KMS_KEY_ID: ((telia-divx-common-services-stage-state-bucket-key))
file: terraform-aws-vpc/.ci/tasks/apply/task.yml
input_mapping: {source: terraform-aws-vpc}
file: this-module/.ci/tasks/apply/task.yml
input_mapping: {source: this-module}
- task: test
params:
directory: default
AWS_ACCESS_KEY_ID: ((telia-divx-common-services-stage-access-key))
AWS_SECRET_ACCESS_KEY: ((telia-divx-common-services-stage-secret-key))
AWS_SESSION_TOKEN: ((telia-divx-common-services-stage-session-token))
file: terraform-aws-vpc/.ci/tasks/test/task.yml
file: this-module/.ci/tasks/test/task.yml
- task: destroy
params:
directory: default
AWS_ACCESS_KEY_ID: ((telia-divx-common-services-stage-access-key))
AWS_SECRET_ACCESS_KEY: ((telia-divx-common-services-stage-secret-key))
AWS_SESSION_TOKEN: ((telia-divx-common-services-stage-session-token))
file: terraform-aws-vpc/.ci/tasks/destroy/task.yml
file: this-module/.ci/tasks/destroy/task.yml

- name: test-private-subnets-no-nat
plan:
- aggregate:
- get: terraform-aws-vpc
- get: this-module
trigger: true
passed:
- test-default
Expand All @@ -44,27 +44,27 @@ jobs:
AWS_SECRET_ACCESS_KEY: ((telia-divx-common-services-stage-secret-key))
AWS_SESSION_TOKEN: ((telia-divx-common-services-stage-session-token))
KMS_KEY_ID: ((telia-divx-common-services-stage-state-bucket-key))
file: terraform-aws-vpc/.ci/tasks/apply/task.yml
input_mapping: {source: terraform-aws-vpc}
file: this-module/.ci/tasks/apply/task.yml
input_mapping: {source: this-module}
- task: test
params:
directory: private-subnets-no-nat
AWS_ACCESS_KEY_ID: ((telia-divx-common-services-stage-access-key))
AWS_SECRET_ACCESS_KEY: ((telia-divx-common-services-stage-secret-key))
AWS_SESSION_TOKEN: ((telia-divx-common-services-stage-session-token))
file: terraform-aws-vpc/.ci/tasks/test/task.yml
file: this-module/.ci/tasks/test/task.yml
- task: destroy
params:
directory: private-subnets-no-nat
AWS_ACCESS_KEY_ID: ((telia-divx-common-services-stage-access-key))
AWS_SECRET_ACCESS_KEY: ((telia-divx-common-services-stage-secret-key))
AWS_SESSION_TOKEN: ((telia-divx-common-services-stage-session-token))
file: terraform-aws-vpc/.ci/tasks/destroy/task.yml
file: this-module/.ci/tasks/destroy/task.yml

- name: test-private-subnets
plan:
- aggregate:
- get: terraform-aws-vpc
- get: this-module
trigger: true
passed:
- test-private-subnets-no-nat
Expand All @@ -76,26 +76,26 @@ jobs:
AWS_SECRET_ACCESS_KEY: ((telia-divx-common-services-stage-secret-key))
AWS_SESSION_TOKEN: ((telia-divx-common-services-stage-session-token))
KMS_KEY_ID: ((telia-divx-common-services-stage-state-bucket-key))
file: terraform-aws-vpc/.ci/tasks/apply/task.yml
input_mapping: {source: terraform-aws-vpc}
file: this-module/.ci/tasks/apply/task.yml
input_mapping: {source: this-module}
- task: test
params:
directory: private-subnets
AWS_ACCESS_KEY_ID: ((telia-divx-common-services-stage-access-key))
AWS_SECRET_ACCESS_KEY: ((telia-divx-common-services-stage-secret-key))
AWS_SESSION_TOKEN: ((telia-divx-common-services-stage-session-token))
file: terraform-aws-vpc/.ci/tasks/test/task.yml
file: this-module/.ci/tasks/test/task.yml
- task: destroy
params:
directory: private-subnets
AWS_ACCESS_KEY_ID: ((telia-divx-common-services-stage-access-key))
AWS_SECRET_ACCESS_KEY: ((telia-divx-common-services-stage-secret-key))
AWS_SESSION_TOKEN: ((telia-divx-common-services-stage-session-token))
file: terraform-aws-vpc/.ci/tasks/destroy/task.yml
file: this-module/.ci/tasks/destroy/task.yml


resources:
- name: terraform-aws-vpc
- name: this-module
type: git
source:
uri: [email protected]:telia-oss/terraform-aws-vpc.git
Expand Down
2 changes: 1 addition & 1 deletion .ci/tasks/apply/task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ image_resource:
type: docker-image
source:
repository: hashicorp/terraform
tag: "0.11.10"
tag: "0.11.11"

params:
AWS_ACCOUNT_ID:
Expand Down
2 changes: 1 addition & 1 deletion .ci/tasks/destroy/task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ image_resource:
type: docker-image
source:
repository: hashicorp/terraform
tag: "0.11.10"
tag: "0.11.11"

params:
directory:
Expand Down
2 changes: 1 addition & 1 deletion .ci/tasks/test/task.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
export DIR="${PWD}"
${DIR}/secret-source/examples/${directory}/test.sh ci
${DIR}/secret-source/examples/${directory}/test.sh
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dist: trusty
sudo: false

before_install:
- curl -fSL "https://releases.hashicorp.com/terraform/0.11.7/terraform_0.11.7_linux_amd64.zip" -o terraform.zip
- curl -fSL "https://releases.hashicorp.com/terraform/0.11.11/terraform_0.11.11_linux_amd64.zip" -o terraform.zip
- sudo unzip terraform.zip -d /opt/terraform
- sudo ln -s /opt/terraform/terraform /usr/bin/terraform
- rm -f terraform.zip
Expand Down
4 changes: 2 additions & 2 deletions examples/default/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = "0.11.10"
required_version = "0.11.11"

backend "s3" {
key = "terraform-modules/development/terraform-aws-vpc/default.tfstate"
Expand All @@ -20,7 +20,7 @@ provider "aws" {

module "vpc" {
source = "../../"
name_prefix = "test-default"
name_prefix = "vpc-test-default"
}

output "vpc_id" {
Expand Down
12 changes: 5 additions & 7 deletions examples/default/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ check_counts() {
tests_failed=$((tests_failed+1))
fi
}

tests_failed=0
if [ $1 == 'ci' ]
then
VPC_ID=`cat terraform-out/terraform-out.json | jq -r '.vpc_id.value'`
export AWS_DEFAULT_REGION=eu-west-1
else
VPC_ID=`terraform output -json | jq -r '.vpc_id.value'`
fi

VPC_ID=`cat terraform-out/terraform-out.json | jq -r '.vpc_id.value'`
export AWS_DEFAULT_REGION=eu-west-1

subnet_count=`aws ec2 describe-subnets | jq --arg VPC_ID "$VPC_ID" '.Subnets[]| select (.VpcId==$VPC_ID)' | jq -s length`
check_counts $subnet_count 3 "Expected # of Subnets"

exit $tests_failed
4 changes: 2 additions & 2 deletions examples/private-subnets-no-nat/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = "0.11.10"
required_version = "0.11.11"

backend "s3" {
key = "terraform-modules/development/terraform-aws-vpc/private-subnets-no-nat.tfstate"
Expand All @@ -20,7 +20,7 @@ provider "aws" {

module "vpc" {
source = "../../"
name_prefix = "test-no-nat"
name_prefix = "vpc-test-no-nat"
private_subnet_count = "3"
create_nat_gateways = "false"
}
Expand Down
11 changes: 4 additions & 7 deletions examples/private-subnets-no-nat/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ check_counts() {
tests_failed=$((tests_failed+1))
fi
}

tests_failed=0
if [ $1 == 'ci' ]
then
VPC_ID=`cat terraform-out/terraform-out.json | jq -r '.vpc_id.value'`
export AWS_DEFAULT_REGION=eu-west-1
else
VPC_ID=`terraform output -json | jq -r '.vpc_id.value'`
fi

VPC_ID=`cat terraform-out/terraform-out.json | jq -r '.vpc_id.value'`
export AWS_DEFAULT_REGION=eu-west-1

subnet_count=`aws ec2 describe-subnets | jq --arg VPC_ID "$VPC_ID" '.Subnets[]| select (.VpcId==$VPC_ID)' | jq -s length`
natgateway_count=`aws ec2 describe-nat-gateways | jq --arg VPC_ID "$VPC_ID" '.NatGateways[]| select (.VpcId==$VPC_ID)'| jq -s length`
Expand Down
4 changes: 2 additions & 2 deletions examples/private-subnets/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = "0.11.10"
required_version = "0.11.11"

backend "s3" {
key = "terraform-modules/development/terraform-aws-vpc/private-subnets.tfstate"
Expand All @@ -20,7 +20,7 @@ provider "aws" {

module "vpc" {
source = "../../"
name_prefix = "test-private-subnets"
name_prefix = "vpc-test-private-subnets"
private_subnet_count = "3"
}

Expand Down
11 changes: 4 additions & 7 deletions examples/private-subnets/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ check_counts() {
tests_failed=$((tests_failed+1))
fi
}

tests_failed=0
if [ $1 == 'ci' ]
then
VPC_ID=`cat terraform-out/terraform-out.json | jq -r '.vpc_id.value'`
export AWS_DEFAULT_REGION=eu-west-1
else
VPC_ID=`terraform output -json | jq -r '.vpc_id.value'`
fi

VPC_ID=`cat terraform-out/terraform-out.json | jq -r '.vpc_id.value'`
export AWS_DEFAULT_REGION=eu-west-1

subnet_count=`aws ec2 describe-subnets | jq --arg VPC_ID "$VPC_ID" '.Subnets[]| select (.VpcId==$VPC_ID)' | jq -s length`
natgateway_count=`aws ec2 describe-nat-gateways | jq --arg VPC_ID "$VPC_ID" '.NatGateways[]| select (.VpcId==$VPC_ID)'| jq -s length`
Expand Down

0 comments on commit 813d438

Please sign in to comment.