Skip to content

Commit b5a4c76

Browse files
authoredOct 20, 2017
Migrating to new org and terraform registry (#1)
* migrating to the terraform registry and new org. Tests fixed and expanded. * updated docs * Giving thanks to contributors in the changelog * debugging rhcl failure * PR #1 feedback addressed - see CHANGELOG * fixed up the policy creation. tests not working atm * pre-commit config now in place * environment variable for region needed to be set. Handling this better in the subsequent release.
1 parent 3771b8f commit b5a4c76

19 files changed

+622
-2
lines changed
 

‎.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.tfvars
2+
*.tfstate*
3+
.terraform
4+
**/inspec.lock
5+
*.gem
6+
.kitchen
7+
.kitchen.local.yml
8+
Gemfile.lock

‎.kitchen.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
driver:
3+
name: "terraform"
4+
directory: "examples/test_fixtures"
5+
6+
provisioner:
7+
name: "terraform"
8+
variable_files:
9+
- "examples/test_fixtures/terraform.tfvars"
10+
11+
platforms:
12+
- name: "aws"
13+
14+
verifier:
15+
name: "awspec"
16+
17+
suites:
18+
- name: "default"
19+
verifier:
20+
name: "awspec"
21+
patterns:
22+
- "test/integration/default/local_alb.rb"

‎.pre-commit-config.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# See http://pre-commit.com for more information
2+
# See http://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
sha: v0.9.2
6+
hooks:
7+
- id: trailing-whitespace
8+
# - id: end-of-file-fixer
9+
- id: check-yaml
10+
- id: check-added-large-files

‎CHANGELOG.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Change Log
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
5+
and this project adheres to [Semantic Versioning](http://semver.org/).
6+
7+
## [1.0.2] - 2017-10-12
8+
### Added
9+
* moved data sources to dedicated `data.tf` file.
10+
* `aws_caller_identity` now used to gather account_id rather than using a variable.
11+
* tests added for `target_group` and expanded for `alb`.
12+
* input variables added for health checks, bucket policy, force_destroy_log_bucket - increasing flexibility.
13+
* circle CI config and badge
14+
15+
### Changed
16+
* altered structure of module to conform to the new [Terraform registry standards](https://www.terraform.io/docs/registry/modules/publish.html#requirements)
17+
* `principle_account_id` (sp) moved to a data source rather than variable map. Spelling corrected.
18+
* removed redundant `/test/alb` directory which had module contents copied. Test kitchen now uses the module itself.
19+
* pinned examples to provider and terraform versions to harden versioning.
20+
* self signed cert added to the test fixtures, eliminating the need for manual upload and terraform.tfvars configuration.
21+
* 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.
23+
* stringed list variables moved to native lists
24+
*
25+
26+
## [1.0.1] - 2017-09-14
27+
### Added
28+
* tag maps can now be provided (thanks @kwach)
29+
30+
### Changed
31+
* optional S3 logging (thanks @marocchino)
32+
33+
## [1.0.0] - 2017-03-16
34+
### Added
35+
* Tests and fixtures for ALB components using awspec and test kitchen
36+
* S3 log bucket and policy rendering for logging now in place
37+
* root_principle_id added and referenced through a map for s3 bucket policy
38+
* string lists moved to native list types
39+
* default region removed
40+
41+
### Changed
42+
* Restructured project templates to alb dir to add testing. This is a breaking change so upping major version.
43+
* Redundant examples dir removed
44+
* Updated documentation
45+
46+
## [0.1.0] - 2017-03-09
47+
### Added
48+
* Initial release.

‎Gemfile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ruby '2.4.2'
2+
3+
source 'https://rubygems.org/' do
4+
gem 'test-kitchen'
5+
gem 'kitchen-terraform'
6+
gem 'awspec'
7+
gem 'kitchen-verifier-awspec'
8+
gem 'rhcl'
9+
end

‎LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2017 Brandon O'Connor - Run at Scale
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

‎README.md

+77-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,80 @@
11
# terraform-aws-alb
2-
Terraform module which creates ALB resources on AWS
2+
A Terraform module containing common configurations for an AWS Application Load
3+
Balancer (ALB) running over HTTP/HTTPS. Available through the [terraform registry](https://registry.terraform.io/modules/terraform-aws-modules/alb/aws).
34

5+
## Assumptions
6+
* You want to create a set of resources for the ALB: namely an associated target group and listener.
7+
* You've created a Virtual Private Cloud (VPC) + subnets where you intend to put
8+
this ALB.
9+
* You have one or more security groups to attach to the ALB.
10+
* You want to configure a listener for HTTPS/HTTP
11+
* You've uploaded an SSL certificate to AWS IAM if using HTTPS
412

5-
**WORK IN PROGRESS**
13+
The module supports both (mutually exclusive):
14+
* Internal IP ALBs
15+
* External IP ALBs
16+
17+
It's recommended you use this module with [terraform-aws-vpc](https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws),
18+
[terraform-aws-security-group](https://registry.terraform.io/modules/terraform-aws-modules/security-group/aws), and
19+
[terraform-aws-autoscaling](https://registry.terraform.io/modules/terraform-aws-modules/autoscaling/aws/).
20+
21+
## Why ALB instead of ELB?
22+
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
24+
documentation](https://aws.amazon.com/elasticloadbalancing/applicationloadbalancer/).
25+
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).
26+
27+
## Resources, inputs, outputs
28+
[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.
29+
30+
## Usage example
31+
A full example leveraging other community modules is contained in the [examples/test_fixtures directory](examples/test_fixtures). Here's the gist of using it via the Terraform registry:
32+
```
33+
module "alb" {
34+
source = "terraform-aws-modules/alb/aws"
35+
vpc_id = "vpc-abcde012"
36+
subnets = ["subnet-abcde012", "subnet-bcde012a"]
37+
alb_security_groups = ["sg-edcd9784", "sg-edcd9785"]
38+
certificate_arn = "arn:aws:iam::123456789012:server-certificate/test_cert-123456789012"
39+
log_bucket = "logs-us-east-2-123456789012"
40+
log_prefix = "my-alb-logs"
41+
42+
tags {
43+
"Terraform" = "true"
44+
"Env" = "${terraform.workspace}"
45+
}
46+
}
47+
```
48+
3. Always `terraform plan` to see your change before running `terraform apply`.
49+
4. Win the day!
50+
51+
## Testing
52+
This module has been packaged with [awspec](https://github.com/k1LoW/awspec) tests through test kitchen. To run them:
53+
1. Install [rvm](https://rvm.io/rvm/install) and the ruby version specified in the [Gemfile](Gemfile).
54+
2. Install bundler and the gems from our Gemfile:
55+
```
56+
gem install bundler; bundle install
57+
```
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).
59+
4. Test using `kitchen test` from the root of the repo.
60+
61+
## Contributing
62+
Report issues/questions/feature requests on in the [Issues](https://github.com/terraform-aws-modules/terraform-aws-alb/issues) section.
63+
64+
Pull requests are welcome! Ideally create a feature branch and issue for every
65+
individual change made. These are the steps:
66+
67+
1. Fork the repo to a personal space or org.
68+
2. Create your feature branch from master (`git checkout -b my-new-feature`).
69+
4. Commit your awesome changes (`git commit -am 'Added some feature'`).
70+
5. Push to the branch (`git push origin my-new-feature`).
71+
6. Create a new Pull Request and tell us about your changes.
72+
73+
## Change log
74+
The [changelog](CHANGELOG.md) captures all important release notes.
75+
76+
## Authors
77+
Created and maintained by [Brandon O'Connor](https://github.com/brandoconnor) - brandon@atscale.run.
78+
79+
## License
80+
MIT Licensed. See [LICENSE](LICENSE) for full details.

‎data.tf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
data "aws_caller_identity" "current" {}
2+
3+
data "aws_elb_service_account" "main" {}

‎examples/test_fixtures/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# test_fixtures example
2+
This set of templates serves two purposes:
3+
0. it shows developers how to use the module in a straightforward way as integrated with other terraform community supported modules.
4+
1. serves as the test infrastructure for CI on the project.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIETjCCAzagAwIBAgIJALi9NaeI/EcpMA0GCSqGSIb3DQEBBQUAMHcxCzAJBgNV
3+
BAYTAkdCMQ8wDQYDVQQIEwZMb25kb24xDzANBgNVBAcTBkxvbmRvbjEYMBYGA1UE
4+
ChMPR2xvYmFsIFNlY3VyaXR5MRYwFAYDVQQLEw1JVCBEZXBhcnRtZW50MRQwEgYD
5+
VQQDEwtleGFtcGxlLmNvbTAeFw0xNzA5MjcyMTIwNDlaFw0yNzA5MjUyMTIwNDla
6+
MHcxCzAJBgNVBAYTAkdCMQ8wDQYDVQQIEwZMb25kb24xDzANBgNVBAcTBkxvbmRv
7+
bjEYMBYGA1UEChMPR2xvYmFsIFNlY3VyaXR5MRYwFAYDVQQLEw1JVCBEZX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ZqljmQ2238GQ99/VyGMn5uVDpZmXH6dMln
24+
ofEU4fh6sbJvs19KNz9Ql31F0U+hq593T50V8iV+TccBB5ifqfjOnFKmljDjFYeZ
25+
0bg=
26+
-----END CERTIFICATE-----
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-----BEGIN RSA PRIVATE KEY-----
2+
MIIEogIBAAKCAQEAsC2FDDUsbdDufyOuhoGd6ouBLIExfGmKWtYbuhho1wK3d1jg
3+
UXRFanZH6y4wHs5tpZnDMg+x5gPUzUgmjJ5p9IKYf9QIewhpdTJMT0yXr2HFMD7d
4+
Hh6Y7WY85DvV2F5DSJffg2+KLCFAgMlgZEc9hlN4nZj/JZBTDe22FisT0q9hbHpS
5+
FfDQ9sF0eCXpsT9yoBG5r5jiM5k7iNEMjDMo7G0rzq6FY0F2ustU0xjqRo107jTC
6+
JmRv5DZiszK9VRQV0TZOWPIupiA+xO9vxjGHqH1YaqdjwWDVph6Wn3w0V319XD9a
7+
6rHdRvSjwqmd+L67k+GDk97AXk6hBMbFEtWkkwIDAQABAoIBACHCNzJlpgPM+0Zl
8+
gfXINIhS/weWIfNjDd3mFR4Nu1kn7hvybdlt3DdQPuuzyAi/KYeH9T1MgJxAs7A6
9+
WRis6kSuGaa07IMW045fevvfA1nZ9D0QbrJszoT/CD/7rzhsp5vrbirzXpiiLof/
10+
Dndop0NsDzqzrIB4LVIH8NJCouPF4eibhb4XQwvCkG05pvlkeK4OJugF/CpgrJlX
11+
GiXDTZ8Lh/fBXeFpCfcBlgTCPkxcZtuNeddTlEJpY6q8QdofvfpjXmpfQ+63FL5t
12+
GTpoWNtO+UIqwHFQgoH6zGR8bMBx0/FLqrJ8Cq6nj7+uLODGAf4+dJ0m+Cz5t3Om
13+
aHgJWEECgYEA4nXD/FS+Wy69dVei8imp3/x+v0/T4LXf8l8NI/Dzvdg82xU1AgZH
14+
OKqTC2z/z4e+5EAF27kJeOBdh7kqPAF9KMHtd3FsxiYK4RpDlR6JFzHH8h8+v8c/
15+
Egg0WiXgnqfePHbS+q5wxPloReJm+ue4eSBzR6qyQbtfH0Qp+NIHGkMCgYEAxyir
16+
CMmI3v1u70V9NtNOlt5O1JNy47iUaLgvEJXBPsD+JYWgs4nY8gZcy+Yx1LBRqMbi
17+
LojOUGKGK6jcLOHjVBW9WJoFtTDN59lba5ryNW9AQOJsdeeaPttpWiFID5K0KTno
18+
kGHzxQjioSnP+mDV7jaXZSNcvYGWVRSabkRwb3ECgYA/mBqlbZbXPFTv8uBLaO/P
19+
erSNPPmfDPQKuC6UfUG1elf8ngP4wZKWkzAf8UgVG2W760652UiTrU4WoyT9HN3s
20+
6Cirdiq5qk070YhRA/YzkUM49xVD/cv0YGFzP1fIthNun1+4DeyVJAToOx/4LcJc
21+
IYS+B21vkBKyUQ4IVdKwyQKBgGBq3+KxLwJFz58nFSelxTZlCeUAPW7hvXe1M5Pj
22+
7FplNKUVvGcvJUiGrAZKu3Usp1v+bSH6OWfRSwN4DJ/t/BCJNdHfP0QpDIZiRFAk
23+
A367DXBcLgYmyhYEQ0zPMAPaEj6jOmQsB8gsNQuxIm8k0m0xILpmFE/qnM0z3E/l
24+
8kkBAoGAJJQgk6dl2rlbZGZvjhVKWNmA8LBJWg28r9/6VWSwYNHSPmcReGvhAflg
25+
5vY9yRIuJXc1Dfq57dIpX8OaH2n/Txgs/895NvpUk/AlqQiMrCKUO3M4wAA0/kNx
26+
RHgT16B9lRxvTaaH8Eh5/YMHp8afrOVEwVIMMCZlWii+PbKFyM4=
27+
-----END RSA PRIVATE KEY-----

‎examples/test_fixtures/data.tf

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data "aws_caller_identity" "fixtures" {}

‎examples/test_fixtures/main.tf

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
terraform {
2+
required_version = "~> 0.10.6"
3+
}
4+
5+
provider "aws" {
6+
region = "${var.aws_region}"
7+
version = "~> 1.0.0"
8+
}
9+
10+
provider "template" {
11+
version = "~> 1.0.0"
12+
}
13+
14+
resource "aws_iam_server_certificate" "fixture_cert" {
15+
name = "test_cert-${data.aws_caller_identity.fixtures.account_id}"
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")}"
18+
19+
lifecycle {
20+
create_before_destroy = true
21+
}
22+
}
23+
24+
module "vpc" {
25+
source = "terraform-aws-modules/vpc/aws"
26+
name = "my-vpc"
27+
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"]
31+
enable_nat_gateway = true
32+
single_nat_gateway = true
33+
tags = {}
34+
}
35+
36+
module "security-group" {
37+
source = "terraform-aws-modules/security-group/aws"
38+
name = "my-sg-https"
39+
vpc_id = "${module.vpc.vpc_id}"
40+
}
41+
42+
module "alb" {
43+
source = "../../../"
44+
alb_name = "my-alb"
45+
alb_security_groups = ["${module.security-group.this_security_group_id}"]
46+
aws_region = "${var.aws_region}"
47+
vpc_id = "${module.vpc.vpc_id}"
48+
subnets = "${module.vpc.public_subnets}"
49+
certificate_arn = "${aws_iam_server_certificate.fixture_cert.arn}"
50+
health_check_path = "/"
51+
log_bucket = "logs-${var.aws_region}-${data.aws_caller_identity.fixtures.account_id}"
52+
log_prefix = "${var.log_prefix}"
53+
force_destroy_log_bucket = true
54+
55+
tags {
56+
"Terraform" = "true"
57+
"Env" = "${terraform.workspace}"
58+
}
59+
}

‎examples/test_fixtures/outputs.tf

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
Outputs used for tests
3+
*/
4+
5+
output "principal_account_id" {
6+
value = "${module.alb.principal_account_id}"
7+
}
8+
9+
output "vpc_id" {
10+
value = "${module.vpc.vpc_id}"
11+
}
12+
13+
output "sg_id" {
14+
value = "${module.security-group.this_security_group_id}"
15+
}
16+
17+
output "account_id" {
18+
value = "${data.aws_caller_identity.fixtures.account_id}"
19+
}

‎examples/test_fixtures/variables.tf

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
variable "log_prefix" {
2+
default = "my-alb-logs"
3+
}
4+
5+
variable "aws_region" {
6+
default = "us-east-2"
7+
}

0 commit comments

Comments
 (0)