Skip to content

Commit 6740f97

Browse files
ostermansarkis
authored andcommitted
Initial implementation (#1)
* Initial implementation * add usage example * add healthcheck * add missing vars * terraform fmt * fix typos * use latest terraform-terraform-label * use length to get number of members in list * get around computed count * revert listener computed count * fix arithmetic operands * comment out host-header for now * use 1 here for now * add back in length compute * update readme and remove hosts condition for now * remove backticks * fix repo name * use host or path conditional listeners * use boolean and
1 parent 9b6f000 commit 6740f97

File tree

5 files changed

+386
-3
lines changed

5 files changed

+386
-3
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright [yyyy] [name of copyright owner]
189+
Copyright 2018 Cloud Posse, LLC
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 171 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,171 @@
1-
# terraform-aws-alb-ingress
2-
Terraform module to provision an HTTP style ingress based on hostname and path
1+
![Cloud Posse](https://cloudposse.com/logo-300x69.png)
2+
3+
# terraform-aws-alb-ingress [![Build Status](https://travis-ci.org/cloudposse/terraform-aws-alb-ingress.svg?branch=master)](https://travis-ci.org/cloudposse/terraform-aws-alb-ingress) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
4+
5+
A Terraform module to provision an HTTP style ingress based on hostname and path.
6+
7+
## Usage
8+
9+
```
10+
module "alb" {
11+
source = "git::https://github.com/cloudposse/terraform-aws-alb.git?ref=master"
12+
namespace = "eg"
13+
stage = "dev"
14+
name = "web"
15+
vpc_id = "..."
16+
}
17+
18+
module "api_ingress" {
19+
source = "git::https://github.com/cloudposse/terraform-aws-alb-ingress.git?ref=master"
20+
namespace = "eg"
21+
stage = "dev"
22+
name = "web"
23+
attributes = "api"
24+
vpc_id = "..."
25+
target_group_arn = "${module.alb.default_target_group_arn}"
26+
paths = ["/api/*"]
27+
}
28+
29+
module "blog_ingress" {
30+
source = "git::https://github.com/cloudposse/terraform-aws-alb-ingress.git?ref=master"
31+
namespace = "eg"
32+
stage = "dev"
33+
name = "web"
34+
attributes = "blog"
35+
vpc_id = "..."
36+
target_group_arn = "${module.alb.default_target_group_arn}"
37+
paths = ["/blog/*"]
38+
}
39+
40+
module "blog_service" {
41+
source = "git::https://github.com/cloudposse/terraform-aws-ecs-alb-service-task.git?ref=0.1.0"
42+
namespace = "eg"
43+
stage = "dev"
44+
name = "blog"
45+
alb_target_group_arn = "${module.alb.default_target_group.arn}"
46+
container_definition_json = "${module.container_definition.json}"
47+
ecr_repository_name = "${module.ecr.repository_name}"
48+
ecs_cluster_arn = "${aws_ecs_cluster.default.arn}"
49+
launch_type = "FARGATE"
50+
vpc_id = "${module.vpc.vpc_id}"
51+
security_group_ids = ["${module.vpc.vpc_default_security_group_id}"]
52+
private_subnet_ids = "${module.dynamic_subnets.private_subnet_ids}"
53+
}
54+
```
55+
56+
## Inputs
57+
58+
| Name | Default | Description | Required |
59+
|:-----------------------------------|:---------------:|:---------------------------------------------------------------------------------|:--------:|
60+
| `namespace` | `` | Namespace (e.g. `cp` or `cloudposse`) | Yes |
61+
| `stage` | `` | Stage (e.g. `prod`, `dev`, `staging`) | Yes |
62+
| `name` | `` | Name (e.g. `app` or `cluster`) | Yes |
63+
| `target_group_arn` | `` | ALB target group ARN, if this is an empty string a new one will be generated | No |
64+
| `listener_arns` | `[]` | A list of ALB listener ARNs to attach ALB listener rule to | No |
65+
| `deregistration_delay` | `15` | The amount of time to wait in seconds while deregistering target | No |
66+
| `health_check_path` | `/` | The destination for the health check request | No |
67+
| `health_check_timeout` | `10` | The amount of time to wait in seconds before failing a health check request | No |
68+
| `health_check_healthy_threshold` | `2` | The number of consecutive health checks successes required before healthy | No |
69+
| `health_check_unhealthy_threshold` | `2` | The number of consecutive health check failures required before unhealthy | No |
70+
| `health_check_interval` | `15` | The duration in seconds in between health checks | No |
71+
| `health_check_matcher` | `200-399` | The HTTP response codes to indicate a healthy check | No |
72+
| `priority` | `100` | The priority for the rule between 1 and 50000 (1 being highest priority) | No |
73+
| `port` | `80` | The port for generated ALB target group (if target_group_arn not set) | No |
74+
| `protocol` | `HTTP` | The protocol for generated ALB target group (if target_group_arn not set) | No |
75+
| `vpc_id` | `` | The VPC ID where generated ALB target group (if target_group_arn not set) | No |
76+
| `paths` | `[]` | Path pattern to match (a maximum of 1 can be defined) | No |
77+
| `hosts` | `[]` | Hosts to match in Hosts header | No |
78+
| `attributes` | `[]` | Additional attributes (e.g. `1`) | No |
79+
| `tags` | `{}` | Additional tags (e.g. `map("BusinessUnit","XYZ")` | No |
80+
| `delimiter` | `-` | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | No |
81+
82+
83+
84+
## Outputs
85+
86+
| Name | Description |
87+
|:--------------------------------|:----------------------------------------------------------------|
88+
| `target_group_arn` | The target group ARN |
89+
90+
91+
## Help
92+
93+
**Got a question?**
94+
95+
File a GitHub [issue](https://github.com/cloudposse/terraform-aws-alb-ingress/issues), send us an [email](mailto:[email protected]) or reach out to us on [Slack](https://slack.cloudposse.com).
96+
97+
## Contributing
98+
99+
### Bug Reports & Feature Requests
100+
101+
Please use the [issue tracker](https://github.com/cloudposse/terraform-aws-alb-ingress/issues) to report any bugs or file feature requests.
102+
103+
### Developing
104+
105+
If you are interested in being a contributor and want to get involved in developing `terraform-aws-alb-ingress`, we would love to hear from you! Shoot us an [email](mailto:[email protected]).
106+
107+
In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.
108+
109+
1. **Fork** the repo on GitHub
110+
2. **Clone** the project to your own machine
111+
3. **Commit** changes to your own branch
112+
4. **Push** your work back up to your fork
113+
5. Submit a **Pull request** so that we can review your changes
114+
115+
**NOTE:** Be sure to merge the latest from "upstream" before making a pull request!
116+
117+
## License
118+
119+
[APACHE 2.0](LICENSE) © 2018 [Cloud Posse, LLC](https://cloudposse.com)
120+
121+
See [LICENSE](LICENSE) for full details.
122+
123+
Licensed to the Apache Software Foundation (ASF) under one
124+
or more contributor license agreements. See the NOTICE file
125+
distributed with this work for additional information
126+
regarding copyright ownership. The ASF licenses this file
127+
to you under the Apache License, Version 2.0 (the
128+
"License"); you may not use this file except in compliance
129+
with the License. You may obtain a copy of the License at
130+
131+
http://www.apache.org/licenses/LICENSE-2.0
132+
133+
Unless required by applicable law or agreed to in writing,
134+
software distributed under the License is distributed on an
135+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
136+
KIND, either express or implied. See the License for the
137+
specific language governing permissions and limitations
138+
under the License.
139+
140+
## About
141+
142+
This project is maintained and funded by [Cloud Posse, LLC][website].
143+
144+
![Cloud Posse](https://cloudposse.com/logo-300x69.png)
145+
146+
147+
Like it? Please let us know at <[email protected]>
148+
149+
We love [Open Source Software](https://github.com/cloudposse/)!
150+
151+
See [our other projects][community]
152+
or [hire us][hire] to help build your next cloud platform.
153+
154+
[website]: https://cloudposse.com/
155+
[community]: https://github.com/cloudposse/
156+
[hire]: https://cloudposse.com/contact/
157+
158+
159+
## Contributors
160+
161+
| [![Erik Osterman][erik_img]][erik_web]<br/>[Erik Osterman][erik_web] | [![Andriy Knysh][andriy_img]][andriy_web]<br/>[Andriy Knysh][andriy_web] |[![Igor Rodionov][igor_img]][igor_web]<br/>[Igor Rodionov][igor_img]|[![Sarkis Varozian][sarkis_img]][sarkis_web]<br/>[Sarkis Varozian][sarkis_web] |
162+
|-------------------------------------------------------|------------------------------------------------------------------|------------------------------------------------------------------|------------------------------------------------------------------|
163+
164+
[erik_img]: http://s.gravatar.com/avatar/88c480d4f73b813904e00a5695a454cb?s=144
165+
[erik_web]: https://github.com/osterman/
166+
[andriy_img]: https://avatars0.githubusercontent.com/u/7356997?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144
167+
[andriy_web]: https://github.com/aknysh/
168+
[igor_img]: http://s.gravatar.com/avatar/bc70834d32ed4517568a1feb0b9be7e2?s=144
169+
[igor_web]: https://github.com/goruha/
170+
[sarkis_img]: https://avatars3.githubusercontent.com/u/42673?s=144&v=4
171+
[sarkis_web]: https://github.com/sarkis/

main.tf

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
locals {
2+
generate_target_group_arn = "${var.target_group_arn == "" ? 1 : 0}"
3+
}
4+
5+
locals {
6+
target_group_arn = "${local.generate_target_group_arn ? aws_lb_target_group.default.arn : var.target_group_arn}"
7+
}
8+
9+
module "default_label" {
10+
source = "git::https://github.com/cloudposse/terraform-terraform-label.git?ref=tags/0.1.3"
11+
enabled = "${local.generate_target_group_arn}"
12+
attributes = "${var.attributes}"
13+
delimiter = "${var.delimiter}"
14+
name = "${var.name}"
15+
namespace = "${var.namespace}"
16+
stage = "${var.stage}"
17+
tags = "${var.tags}"
18+
}
19+
20+
resource "aws_lb_target_group" "default" {
21+
count = "${local.generate_target_group_arn}"
22+
name = "${module.default_label.id}"
23+
port = "${var.port}"
24+
protocol = "${var.protocol}"
25+
vpc_id = "${var.vpc_id}"
26+
target_type = "${var.target_type}"
27+
28+
deregistration_delay = "${var.deregistration_delay}"
29+
30+
health_check {
31+
path = "${var.health_check_path}"
32+
timeout = "${var.health_check_timeout}"
33+
healthy_threshold = "${var.health_check_healthy_threshold}"
34+
unhealthy_threshold = "${var.health_check_unhealthy_threshold}"
35+
interval = "${var.health_check_interval}"
36+
matcher = "${var.health_check_matcher}"
37+
}
38+
39+
lifecycle {
40+
create_before_destroy = true
41+
}
42+
}
43+
44+
resource "aws_lb_listener_rule" "paths" {
45+
count = "${length(var.paths) > 0 && length(var.hosts) == 0 ? length(var.listener_arns) : 0}"
46+
listener_arn = "${var.listener_arns[count.index]}"
47+
priority = "${var.priority + count.index}"
48+
49+
action {
50+
type = "forward"
51+
target_group_arn = "${local.target_group_arn}"
52+
}
53+
54+
condition {
55+
field = "path-pattern"
56+
values = ["${var.paths}"]
57+
}
58+
}
59+
60+
resource "aws_lb_listener_rule" "hosts" {
61+
count = "${length(var.hosts) > 0 && length(var.paths) == 0 ? length(var.listener_arns) : 0}"
62+
listener_arn = "${var.listener_arns[count.index]}"
63+
priority = "${var.priority + count.index}"
64+
65+
action {
66+
type = "forward"
67+
target_group_arn = "${local.target_group_arn}"
68+
}
69+
70+
condition {
71+
field = "host-header"
72+
values = ["${var.hosts}"]
73+
}
74+
}
75+
76+
resource "aws_lb_listener_rule" "hosts_paths" {
77+
count = "${length(var.paths) > 0 && length(var.hosts) > 0 ? length(var.listener_arns) : 0}"
78+
listener_arn = "${var.listener_arns[count.index]}"
79+
priority = "${var.priority + count.index}"
80+
81+
action {
82+
type = "forward"
83+
target_group_arn = "${local.target_group_arn}"
84+
}
85+
86+
condition {
87+
field = "host-header"
88+
values = ["${var.hosts}"]
89+
}
90+
91+
condition {
92+
field = "path-pattern"
93+
values = ["${var.paths}"]
94+
}
95+
}

outputs.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "target_group_arn" {
2+
value = "${local.target_group_arn}"
3+
}

0 commit comments

Comments
 (0)