Skip to content

Commit dea191d

Browse files
3.0.0 release - configuration supports n of each ancillary ALB resource (#49)
1 parent ca654e4 commit dea191d

File tree

21 files changed

+425
-340
lines changed

21 files changed

+425
-340
lines changed

.kitchen.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
---
22
driver:
33
name: "terraform"
4-
root_module_directory: "examples/test_fixtures"
4+
root_module_directory: "examples/alb_test_fixture"
55

66
provisioner:
77
name: "terraform"
8-
variable_files:
9-
- "examples/test_fixtures/terraform.tfvars"
108

119
platforms:
1210
- name: "aws"

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ before_script:
2121
- 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)
2222
- export TF_VAR_region=${AWS_REGION}
2323
- echo "using AWS_REGION=${AWS_REGION}"
24-
- curl --silent --output terraform.zip https://releases.hashicorp.com/terraform/0.11.2/terraform_0.11.2_linux_amd64.zip
25-
- sha256sum terraform.zip | grep "f728fa73ff2a4c4235a28de4019802531758c7c090b6ca4c024d48063ab8537b" -q
24+
- curl --silent --output terraform.zip https://releases.hashicorp.com/terraform/0.11.3/terraform_0.11.3_linux_amd64.zip
25+
- sha256sum terraform.zip | grep "6b8a7b83954597d36bbed23913dd51bc253906c612a070a21db373eab71b277b" -q
2626
- unzip terraform.zip ; rm -f terraform.zip; chmod +x terraform
2727
- mkdir -p ${HOME}/bin ; export PATH=${PATH}:${HOME}/bin; mv terraform ${HOME}/bin/
2828
- terraform -v
@@ -31,9 +31,9 @@ script:
3131
- echo 'script'
3232
- terraform init
3333
- terraform fmt -check=true
34-
- 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=[]"
34+
- terraform validate -var "region=${AWS_REGION}" -var "subnets=[]" -var "vpc_id=vpc-abcde012" -var "load_balancer_name=my-lb" -var "log_bucket_name=my-log-bucket" -var "load_balancer_security_groups=[]"
3535
- docker run --rm -v $(pwd):/app/ --workdir=/app/ -t wata727/tflint --error-with-issues
36-
- cd examples/test_fixtures
36+
- cd examples/alb_test_fixture
3737
- terraform init
3838
- terraform fmt -check=true
3939
- terraform validate

CHANGELOG.md

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

8+
## [v3.0.0] - 2018-03-
9+
10+
### Added
11+
12+
* default values added for most target group and listener attributes.
13+
* new application load balancer attributes added as variables with defaults.
14+
* tests now covering listeners.
15+
16+
### Changed
17+
18+
* listeners and target groups now defined by lists of maps allowing many-to-many relationships of those resources.
19+
* listeners and target groups creation is now data driven through variables giving greater flexibility.
20+
* `name_prefix` used where possible to avoid naming conflicts in resource testing.
21+
* logging to S3 now made manditory and done outside the module as this is better practice.
22+
* terraform 0.11.3 now used in CI. 0.11.4 seems to have warnings on plan that become errors in CI.
23+
824
## [v2.5.0] - 2018-03-07
925

1026
### Added

README.md

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ Balancer (ALB) running over HTTP/HTTPS. Available through the [terraform registr
99

1010
## Assumptions
1111

12-
* You want to create a set of resources for the ALB: namely an associated target group and listener.
13-
* You've created a Virtual Private Cloud (VPC) + subnets where you intend to put this ALB.
12+
* You want to create a set of resources around an application load balancer: namely associated target groups and listeners.
13+
* You've created a Virtual Private Cloud (VPC) and subnets where you intend to put this ALB.
1414
* You have one or more security groups to attach to the ALB.
15-
* You want to configure a listener for HTTPS/HTTP.
16-
* You've uploaded an SSL certificate to AWS IAM if using HTTPS.
15+
* Additionally, if you plan to use an HTTPS listener, the ARN of an SSL certificate is required.
1716

1817
The module supports both (mutually exclusive):
1918

@@ -27,49 +26,51 @@ It's recommended you use this module with [terraform-aws-vpc](https://registry.t
2726
## Why ALB instead of ELB
2827

2928
The use-case presented here appears almost identical to how one would use an ELB
30-
but we inherit a few bonuses by moving to ALB. Those are best outlined in [AWS's
31-
documentation](https://aws.amazon.com/elasticloadbalancing/applicationloadbalancer/).
32-
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).
29+
but we inherit a few bonuses by moving to ALB like the ability to leverage WAF.
30+
[AWS's documentation](https://aws.amazon.com/elasticloadbalancing/applicationloadbalancer/) has a more
31+
exhastive set of reasons. Alternatively, if using ALB with ECS look no further than
32+
the [hashicorp example](https://github.com/terraform-providers/terraform-provider-aws/blob/master/examples/ecs-alb).
3333

3434
## Resources, inputs, outputs
3535

3636
[Resources](https://registry.terraform.io/modules/terraform-aws-modules/alb/aws?tab=resources), [inputs](https://registry.terraform.io/modules/terraform-aws-modules/alb/aws?tab=inputs), and [outputs](https://registry.terraform.io/modules/terraform-aws-modules/alb/aws?tab=outputs) documented in the terraform registry.
3737

3838
## Usage example
3939

40-
A full example leveraging other community modules is contained in the [examples/test_fixtures directory](https://github.com/terraform-aws-modules/terraform-aws-alb/tree/master/examples/test_fixtures). Here's the gist of using it via the Terraform registry:
40+
A full example leveraging other community modules is contained in the [examples/alb_test_fixture directory](https://github.com/terraform-aws-modules/terraform-aws-alb/tree/master/examples/alb_test_fixture). Here's the gist of using it via the Terraform registry:
4141

4242
```hcl
4343
module "alb" {
4444
source = "terraform-aws-modules/alb/aws"
45-
alb_name = "my-alb"
46-
alb_protocols = ["HTTPS"]
47-
alb_security_groups = ["sg-edcd9784", "sg-edcd9785"]
48-
certificate_arn = "arn:aws:iam::123456789012:server-certificate/test_cert-123456789012"
49-
create_log_bucket = true
50-
enable_logging = true
51-
health_check_path = "/"
45+
load_balancer_name = "my-alb"
46+
load_balancer_security_groups = ["sg-edcd9784", "sg-edcd9785"]
5247
log_bucket_name = "logs-us-east-2-123456789012"
5348
log_location_prefix = "my-alb-logs"
54-
subnets = ["subnet-abcde012", "subnet-bcde012a"]
49+
subnets = ["subnet-abcde012", subnet-bcde012a"]
5550
tags = "${map("Environment", "test")}"
5651
vpc_id = "vpc-abcde012"
52+
https_listeners = "${list(map("certificate_arn", "arn:aws:iam::123456789012:server-certificate/test_cert-123456789012", "port", 443))}"
53+
https_listeners_count = "1"
54+
target_groups = "${list(map("name", "foo", "backend_protocol", "HTTP", "backend_port", "80"))}"
55+
http_tcp_listeners_count = "1"
56+
http_tcp_listeners = "${list(map("port", "80", "protocol", "HTTP"))}"
57+
target_groups_count = "1"
5758
}
5859
```
5960

6061
## Testing
6162

62-
This module has been packaged with [awspec](https://github.com/k1LoW/awspec) tests through test kitchen. To run them:
63+
This module has been packaged with [awspec](https://github.com/k1LoW/awspec) tests through [kitchen](https://kitchen.ci/) and [kitchen-terraform](https://newcontext-oss.github.io/kitchen-terraform/). To run them:
6364

6465
1. Install [rvm](https://rvm.io/rvm/install) and the ruby version specified in the [Gemfile](https://github.com/terraform-aws-modules/terraform-aws-alb/tree/master/Gemfile).
65-
1. Install bundler and the gems from our Gemfile:
66+
2. Install bundler and the gems from our Gemfile:
6667

67-
```bash
68-
gem install bundler && bundle install
69-
```
68+
```bash
69+
gem install bundler && bundle install
70+
```
7071

71-
1. 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}`).
72-
1. Test using `kitchen test` from the root of the repo.
72+
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}`).
73+
4. Test using `bundle exec kitchen test` from the root of the repo.
7374

7475
## Contributing
7576

@@ -79,15 +80,15 @@ Pull requests are welcome! Ideally create a feature branch and issue for every
7980
individual change made. These are the steps:
8081

8182
1. Fork the repo to a personal space or org.
82-
1. Create your feature branch from master (`git checkout -b my-new-feature`).
83-
1. Commit your awesome changes (`git commit -am 'Added some feature'`).
84-
1. Push to the branch (`git push origin my-new-feature`).
85-
1. Create a new Pull Request and tell us about your changes.
83+
2. Create your feature branch from master (`git checkout -b my-new-feature`).
84+
3. Commit your awesome changes (`git commit -am 'Added some feature'`).
85+
4. Push to the branch (`git push origin my-new-feature`).
86+
5. Create a new Pull Request and tell us about your changes.
8687

8788
## IAM Permissions
8889

8990
Testing and using this repo requires a minimum set of IAM permissions. Test permissions
90-
are listed in the [test_fixtures README](https://github.com/terraform-aws-modules/terraform-aws-alb/tree/master/examples/test_fixtures/README.md).
91+
are listed in the [alb_test_fixture README](https://github.com/terraform-aws-modules/terraform-aws-alb/tree/master/examples/alb_test_fixture/README.md).
9192

9293
## Change log
9394

examples/test_fixtures/README.md renamed to examples/alb_test_fixture/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# test_fixtures example
1+
# alb_test_fixture example
22

33
This set of templates serves two purposes:
44

data.tf renamed to examples/alb_test_fixture/data.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
data "aws_caller_identity" "current" {}
22

3+
data "aws_availability_zones" "available" {}
4+
5+
data "aws_region" "current" {}
6+
37
data "aws_elb_service_account" "main" {}
48

59
data "aws_iam_policy_document" "bucket_policy" {
610
statement {
711
sid = "AllowToPutLoadBalancerLogsToS3Bucket"
812
actions = ["s3:PutObject"]
9-
resources = ["arn:aws:s3:::${var.log_bucket_name}/${var.log_location_prefix == "" ? "" : format("%s/", var.log_location_prefix)}AWSLogs/${data.aws_caller_identity.current.account_id}/*"]
13+
resources = ["arn:aws:s3:::${local.log_bucket_name}/${var.log_location_prefix}/AWSLogs/${data.aws_caller_identity.current.account_id}/*"]
1014

1115
principals {
1216
type = "AWS"
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
locals {
2+
tags = "${map("Environment", "test", "GithubRepo", "tf-aws-alb", "GithubOrg", "terraform-aws-modules", "Workspace", "${terraform.workspace}")}"
3+
log_bucket_name = "${var.log_bucket_name}-${data.aws_caller_identity.current.account_id}-${data.aws_region.current.name}"
4+
https_listeners_count = 2
5+
6+
https_listeners = "${list(
7+
map(
8+
"certificate_arn", aws_iam_server_certificate.fixture_cert.arn,
9+
"port", 443
10+
),
11+
map(
12+
"certificate_arn", aws_iam_server_certificate.fixture_cert.arn,
13+
"port", 8443,
14+
"ssl_policy", "ELBSecurityPolicy-TLS-1-2-2017-01",
15+
"target_group_index", 1
16+
)
17+
)}"
18+
19+
http_tcp_listeners_count = 3
20+
21+
http_tcp_listeners = "${list(
22+
map(
23+
"port", 80,
24+
"protocol", "HTTP"
25+
),
26+
map(
27+
"port", 8080,
28+
"protocol", "HTTP",
29+
"target_group_index", 0
30+
),
31+
map(
32+
"port", 8081,
33+
"protocol", "HTTP",
34+
"target_group_index", 1
35+
)
36+
)}"
37+
38+
target_groups_count = 2
39+
40+
target_groups = "${list(
41+
map("name", "foo",
42+
"backend_protocol", "HTTP",
43+
"backend_port", 80
44+
),
45+
map("name", "bar",
46+
"backend_protocol", "HTTP",
47+
"backend_port", 8080
48+
)
49+
)}"
50+
}

examples/alb_test_fixture/main.tf

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
terraform {
2+
required_version = ">= 0.11.3"
3+
}
4+
5+
provider "aws" {
6+
version = ">= 1.10.0"
7+
region = "${var.region}"
8+
}
9+
10+
resource "aws_iam_server_certificate" "fixture_cert" {
11+
name = "test_cert-${data.aws_caller_identity.current.account_id}-${data.aws_region.current.name}"
12+
certificate_body = "${file("${path.module}/../../examples/alb_test_fixture/certs/example.crt.pem")}"
13+
private_key = "${file("${path.module}/../../examples/alb_test_fixture/certs/example.key.pem")}"
14+
15+
lifecycle {
16+
create_before_destroy = true
17+
}
18+
}
19+
20+
resource "aws_s3_bucket" "log_bucket" {
21+
bucket = "${local.log_bucket_name}"
22+
policy = "${data.aws_iam_policy_document.bucket_policy.json}"
23+
force_destroy = true
24+
tags = "${local.tags}"
25+
26+
lifecycle_rule {
27+
id = "log-expiration"
28+
enabled = "true"
29+
30+
expiration {
31+
days = "7"
32+
}
33+
}
34+
}
35+
36+
module "vpc" {
37+
source = "terraform-aws-modules/vpc/aws"
38+
version = "1.14.0"
39+
name = "test-vpc"
40+
cidr = "10.0.0.0/16"
41+
azs = ["${data.aws_availability_zones.available.names[0]}", "${data.aws_availability_zones.available.names[1]}"]
42+
private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
43+
public_subnets = ["10.0.3.0/24", "10.0.4.0/24"]
44+
enable_nat_gateway = true
45+
single_nat_gateway = true
46+
tags = "${local.tags}"
47+
}
48+
49+
module "security_group" {
50+
source = "terraform-aws-modules/security-group/aws"
51+
version = "1.12.0"
52+
name = "test-sg-https"
53+
vpc_id = "${module.vpc.vpc_id}"
54+
tags = "${local.tags}"
55+
}
56+
57+
module "alb" {
58+
source = "../.."
59+
load_balancer_name = "test-alb"
60+
load_balancer_security_groups = ["${module.security_group.this_security_group_id}"]
61+
log_bucket_name = "${aws_s3_bucket.log_bucket.id}"
62+
log_location_prefix = "${var.log_location_prefix}"
63+
subnets = "${module.vpc.public_subnets}"
64+
tags = "${local.tags}"
65+
vpc_id = "${module.vpc.vpc_id}"
66+
https_listeners = "${local.https_listeners}"
67+
https_listeners_count = "${local.https_listeners_count}"
68+
http_tcp_listeners = "${local.http_tcp_listeners}"
69+
http_tcp_listeners_count = "${local.http_tcp_listeners_count}"
70+
target_groups = "${local.target_groups}"
71+
target_groups_count = "${local.target_groups_count}"
72+
}

0 commit comments

Comments
 (0)