Skip to content

Commit 5e7184c

Browse files
Adding CI to module (#5)
* CI added through Travis - tests passing * moved travis badge to official org builds
1 parent b5a4c76 commit 5e7184c

File tree

11 files changed

+240
-21
lines changed

11 files changed

+240
-21
lines changed

.travis.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
language: ruby
2+
3+
sudo: false
4+
5+
dist: trusty
6+
7+
rvm:
8+
- 2.4.2
9+
10+
services:
11+
- docker
12+
13+
before_install:
14+
- echo "before_install"
15+
16+
install:
17+
- echo "install"
18+
- gem install bundler --no-rdoc --no-ri
19+
- bundle install
20+
21+
before_script:
22+
- echo 'before_script'
23+
# Get a random variable from the awscli and use it through the remainder of the test cycle.
24+
- 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}"
26+
- 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_*
34+
- terraform -v
35+
36+
script:
37+
- echo 'before_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
42+
- terraform init
43+
- terraform fmt -check=true
44+
- 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=[]"
45+
- docker run --rm -v $(pwd):/app/ --workdir=/app/ -t wata727/tflint --error-with-issues
46+
- 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
52+
- terraform init
53+
- terraform fmt -check=true
54+
- 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
58+
- cd -
59+
- pwd
60+
- ls -lah
61+
- 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'
73+
74+
deploy:
75+
# likely want to publish to the registry
76+
provider: script
77+
script: ci/deploy.sh
78+
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'

CHANGELOG.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,25 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [1.0.3] - 2017-10-19
8+
## Added
9+
* TravisCI configuration added and now passing.
10+
* badge added to docs.
11+
* permissions section now in the example readme.
12+
* placeholder shell script added for CI deployment. Eventually this should conditionally release to the registry when those APIs become available.
13+
14+
## Changed
15+
* altered tf variable `aws_region` to `region`.
16+
* replaced hardcoding the region to instead use a random region as retrieved by an awscli docker container within CI.
17+
* example cert is now a regionally-specific resource enabling tests to run in various regions at once and not collide.
18+
* ruby version bump means `Rhcl` becomes `rhcl`.
19+
720
## [1.0.2] - 2017-10-12
821
### Added
922
* moved data sources to dedicated `data.tf` file.
1023
* `aws_caller_identity` now used to gather account_id rather than using a variable.
1124
* tests added for `target_group` and expanded for `alb`.
1225
* input variables added for health checks, bucket policy, force_destroy_log_bucket - increasing flexibility.
13-
* circle CI config and badge
1426

1527
### Changed
1628
* altered structure of module to conform to the new [Terraform registry standards](https://www.terraform.io/docs/registry/modules/publish.html#requirements)
@@ -19,9 +31,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1931
* pinned examples to provider and terraform versions to harden versioning.
2032
* self signed cert added to the test fixtures, eliminating the need for manual upload and terraform.tfvars configuration.
2133
* modules referenced in the test fixture are now sourced from the terraform registry.
22-
* moved bucket_policy.json and template rending to locals + optional variable input.
34+
* removed bucket_policy.json in favor of creating the policy via the `aws_iam_policy_document` resource or optionally a variable.
2335
* stringed list variables moved to native lists
24-
*
2536

2637
## [1.0.1] - 2017-09-14
2738
### Added

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
A Terraform module containing common configurations for an AWS Application Load
33
Balancer (ALB) running over HTTP/HTTPS. Available through the [terraform registry](https://registry.terraform.io/modules/terraform-aws-modules/alb/aws).
44

5+
| Branch | Build status |
6+
| --- | --- |
7+
| master | [![build Status](https://travis-ci.org/terraform-aws-modules/terraform-aws-alb.svg?branch=master)](https://travis-ci.org/terraform-aws-modules/terraform-aws-skeleton) |
8+
59
## Assumptions
610
* You want to create a set of resources for the ALB: namely an associated target group and listener.
711
* You've created a Virtual Private Cloud (VPC) + subnets where you intend to put
@@ -20,7 +24,7 @@ It's recommended you use this module with [terraform-aws-vpc](https://registry.t
2024

2125
## Why ALB instead of ELB?
2226
The use-case presented here appears almost identical to how one would use an ELB
23-
BUT we inherit a few bonuses by moving to ALB. Those are best outlined in [AWS's
27+
but we inherit a few bonuses by moving to ALB. Those are best outlined in [AWS's
2428
documentation](https://aws.amazon.com/elasticloadbalancing/applicationloadbalancer/).
2529
For an example of using ALB with ECS look no further than the [hashicorp example](https://github.com/terraform-providers/terraform-provider-aws/blob/master/examples/ecs-alb).
2630

@@ -32,12 +36,15 @@ A full example leveraging other community modules is contained in the [examples/
3236
```
3337
module "alb" {
3438
source = "terraform-aws-modules/alb/aws"
39+
alb_name = "my-alb"
40+
region = "us-east-2"
41+
alb_security_groups = ["sg-edcd9784", "sg-edcd9785"]
3542
vpc_id = "vpc-abcde012"
3643
subnets = ["subnet-abcde012", "subnet-bcde012a"]
37-
alb_security_groups = ["sg-edcd9784", "sg-edcd9785"]
3844
certificate_arn = "arn:aws:iam::123456789012:server-certificate/test_cert-123456789012"
3945
log_bucket = "logs-us-east-2-123456789012"
4046
log_prefix = "my-alb-logs"
47+
health_check_path = "/"
4148
4249
tags {
4350
"Terraform" = "true"
@@ -55,7 +62,7 @@ This module has been packaged with [awspec](https://github.com/k1LoW/awspec) tes
5562
```
5663
gem install bundler; bundle install
5764
```
58-
3. Configure variables in `test/fixtures/terraform.tfvars`. An example of how this should look is in [terraform.tfvars.example](test/fixtures/terraform.tfvars.example).
65+
3. Ensure your AWS environment is configured (i.e. credentials and region) for test and set TF_VAR_region to a valid AWS region (e.g. `export TF_VAR_region=${AWS_REGION}`).
5966
4. Test using `kitchen test` from the root of the repo.
6067

6168
## Contributing
@@ -70,6 +77,10 @@ individual change made. These are the steps:
7077
5. Push to the branch (`git push origin my-new-feature`).
7178
6. Create a new Pull Request and tell us about your changes.
7279

80+
## IAM Permissions
81+
Testing and using this repo requires a minimum set of IAM permissions. Test permissions
82+
are listed in the [test_fixtures README](examples/test_fixtures/README.md).
83+
7384
## Change log
7485
The [changelog](CHANGELOG.md) captures all important release notes.
7586

ci/deploy.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
# this file is a placeholder. Not sure that the registry API is available yet.
4+
echo "Deployment steps should include publishing to terraform registry on new releases. Exiting with success."

examples/test_fixtures/README.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,105 @@
22
This set of templates serves two purposes:
33
0. it shows developers how to use the module in a straightforward way as integrated with other terraform community supported modules.
44
1. serves as the test infrastructure for CI on the project.
5+
6+
## IAM Permissions
7+
The following IAM policy is the minimum needed to execute the module from the test suite.
8+
```
9+
{
10+
"Version": "2012-10-17",
11+
"Statement": [
12+
{
13+
"Sid": "Stmt1507789535000",
14+
"Effect": "Allow",
15+
"Action": [
16+
"ec2:AllocateAddress",
17+
"ec2:AssignIpv6Addresses",
18+
"ec2:AssignPrivateIpAddresses",
19+
"ec2:AssociateAddress",
20+
"ec2:AssociateDhcpOptions",
21+
"ec2:AssociateRouteTable",
22+
"ec2:AttachInternetGateway",
23+
"ec2:AttachNetworkInterface",
24+
"ec2:AuthorizeSecurityGroupEgress",
25+
"ec2:AuthorizeSecurityGroupIngress",
26+
"ec2:CreateDhcpOptions",
27+
"ec2:CreateInternetGateway",
28+
"ec2:CreateNatGateway",
29+
"ec2:CreateNetworkAcl",
30+
"ec2:CreateNetworkAclEntry",
31+
"ec2:CreateNetworkInterface",
32+
"ec2:CreateNetworkInterfacePermission",
33+
"ec2:CreateRoute",
34+
"ec2:CreateRouteTable",
35+
"ec2:CreateSecurityGroup",
36+
"ec2:CreateSubnet",
37+
"ec2:CreateTags",
38+
"ec2:CreateVpc",
39+
"ec2:DeleteDhcpOptions",
40+
"ec2:DeleteInternetGateway",
41+
"ec2:DeleteNatGateway",
42+
"ec2:DeleteNetworkAcl",
43+
"ec2:DeleteNetworkAclEntry",
44+
"ec2:DeleteNetworkInterface",
45+
"ec2:DeleteRoute",
46+
"ec2:DeleteRouteTable",
47+
"ec2:DeleteSecurityGroup",
48+
"ec2:DeleteSubnet",
49+
"ec2:DeleteTags",
50+
"ec2:DeleteVpc",
51+
"ec2:Describe*",
52+
"ec2:DetachInternetGateway",
53+
"ec2:DetachNetworkInterface",
54+
"ec2:DisassociateAddress",
55+
"ec2:DisassociateRouteTable",
56+
"ec2:DisassociateSubnetCidrBlock",
57+
"ec2:DisassociateVpcCidrBlock",
58+
"ec2:ModifySubnetAttribute",
59+
"ec2:ModifyVpcAttribute",
60+
"ec2:ModifyVpcEndpoint",
61+
"ec2:ReleaseAddress",
62+
"ec2:RevokeSecurityGroupEgress",
63+
"ec2:RevokeSecurityGroupIngress",
64+
"ec2:UpdateSecurityGroupRuleDescriptionsEgress",
65+
"ec2:UpdateSecurityGroupRuleDescriptionsIngress"
66+
],
67+
"Resource": [
68+
"*"
69+
]
70+
},
71+
{
72+
"Sid": "Stmt1507789585001",
73+
"Effect": "Allow",
74+
"Action": [
75+
"s3:*",
76+
],
77+
"Resource": [
78+
"*"
79+
]
80+
},
81+
{
82+
"Sid": "Stmt1507789655000",
83+
"Effect": "Allow",
84+
"Action": [
85+
"elasticloadbalancing:*"
86+
],
87+
"Resource": [
88+
"*"
89+
]
90+
},
91+
{
92+
"Sid": "Stmt1507789655001",
93+
"Effect": "Allow",
94+
"Action": [
95+
"iam:UploadServerCertificate",
96+
"iam:DeleteServerCertificate",
97+
"iam:GetServerCertificate"
98+
],
99+
"Resource": [
100+
"*"
101+
]
102+
}
103+
]
104+
}
105+
106+
```

examples/test_fixtures/data.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
data "aws_caller_identity" "fixtures" {}
2+
3+
data "aws_availability_zones" "available" {}

examples/test_fixtures/main.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ terraform {
33
}
44

55
provider "aws" {
6-
region = "${var.aws_region}"
6+
region = "${var.region}"
77
version = "~> 1.0.0"
88
}
99

@@ -12,7 +12,7 @@ provider "template" {
1212
}
1313

1414
resource "aws_iam_server_certificate" "fixture_cert" {
15-
name = "test_cert-${data.aws_caller_identity.fixtures.account_id}"
15+
name = "test_cert-${data.aws_caller_identity.fixtures.account_id}-${var.region}"
1616
certificate_body = "${file("${path.module}/../../../examples/test_fixtures/certs/example.crt.pem")}"
1717
private_key = "${file("${path.module}/../../../examples/test_fixtures/certs/example.key.pem")}"
1818

@@ -25,9 +25,9 @@ module "vpc" {
2525
source = "terraform-aws-modules/vpc/aws"
2626
name = "my-vpc"
2727
cidr = "10.0.0.0/16"
28-
azs = ["us-east-2a", "us-east-2b", "us-east-2c"]
29-
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
30-
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
28+
azs = ["${data.aws_availability_zones.available.names[0]}", "${data.aws_availability_zones.available.names[1]}"]
29+
private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
30+
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"]
3131
enable_nat_gateway = true
3232
single_nat_gateway = true
3333
tags = {}
@@ -40,15 +40,15 @@ module "security-group" {
4040
}
4141

4242
module "alb" {
43-
source = "../../../"
43+
source = "../../.."
4444
alb_name = "my-alb"
4545
alb_security_groups = ["${module.security-group.this_security_group_id}"]
46-
aws_region = "${var.aws_region}"
46+
region = "${var.region}"
4747
vpc_id = "${module.vpc.vpc_id}"
4848
subnets = "${module.vpc.public_subnets}"
4949
certificate_arn = "${aws_iam_server_certificate.fixture_cert.arn}"
5050
health_check_path = "/"
51-
log_bucket = "logs-${var.aws_region}-${data.aws_caller_identity.fixtures.account_id}"
51+
log_bucket = "logs-${var.region}-${data.aws_caller_identity.fixtures.account_id}"
5252
log_prefix = "${var.log_prefix}"
5353
force_destroy_log_bucket = true
5454

examples/test_fixtures/variables.tf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@ variable "log_prefix" {
22
default = "my-alb-logs"
33
}
44

5-
variable "aws_region" {
6-
default = "us-east-2"
7-
}
5+
variable "region" {}

main.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
### ALB resources
22

3+
provider "aws" {
4+
region = "${var.region}"
5+
version = "~> 1.0.0"
6+
}
7+
38
resource "aws_alb" "main" {
49
name = "${var.alb_name}"
510
subnets = ["${var.subnets}"]

test/integration/default/local_alb.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
require 'awspec'
2-
require 'Rhcl'
2+
require 'rhcl'
33

4-
ENV['AWS_REGION'] = 'us-east-2'
54
module_vars = Rhcl.parse(File.open('examples/test_fixtures/variables.tf'))
65
log_prefix = module_vars['variable']['log_prefix']['default']
76
tf_state = JSON.parse(File.open('.kitchen/kitchen-terraform/default-aws/terraform.tfstate').read)
@@ -11,7 +10,7 @@
1110
security_group_id = tf_state['modules'][0]['outputs']['sg_id']['value']
1211
account_id = tf_state['modules'][0]['outputs']['account_id']['value']
1312
# this must match the format in examples/test_fixtures/locals.tf
14-
log_bucket = 'logs-' + module_vars['variable']['aws_region']['default'] + '-' + account_id
13+
log_bucket = 'logs-' + ENV['AWS_REGION'] + '-' + account_id
1514
# subnet_ids = tf_state['modules'][0]['outputs']['subnet_ids']['value']
1615

1716
describe alb('my-alb') do
@@ -44,6 +43,7 @@
4443
"Version": "2012-10-17",
4544
"Statement": [
4645
{
46+
"Sid": "",
4747
"Effect": "Allow",
4848
"Principal": {
4949
"AWS": "arn:aws:iam::#{principal_account_id}:root"

0 commit comments

Comments
 (0)