Skip to content

Commit 8f3c50b

Browse files
authored
Convert to TF 0.12. Add tests. Add Codefresh test pipeline (cloudposse#23)
* Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline
1 parent 8f73075 commit 8f3c50b

23 files changed

+1269
-416
lines changed

Diff for: .travis.yml

-16
This file was deleted.

Diff for: README.md

+125-50
Large diffs are not rendered by default.

Diff for: README.yaml

+91-17
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ github_repo: cloudposse/terraform-aws-alb-ingress
1818

1919
# Badges to display
2020
badges:
21-
- name: "Build Status"
22-
image: "https://travis-ci.org/cloudposse/terraform-aws-alb-ingress.svg?branch=master"
23-
url: "https://travis-ci.org/cloudposse/terraform-aws-alb-ingress"
21+
- name: "Codefresh Build Status"
22+
image: "https://g.codefresh.io/api/badges/pipeline/cloudposse/terraform-modules%2Fterraform-aws-alb-ingress?type=cf-1"
23+
url: "https://g.codefresh.io/public/accounts/cloudposse/pipelines/5db79c3e041f80d14e93f012"
2424
- name: "Latest Release"
2525
image: "https://img.shields.io/github/release/cloudposse/terraform-aws-alb-ingress.svg"
2626
url: "https://github.com/cloudposse/terraform-aws-alb-ingress/releases/latest"
@@ -35,25 +35,99 @@ related:
3535

3636
# Short description of this project
3737
description: |-
38-
Terraform module to provision an HTTP style ingress based on hostname and/or path.
38+
Terraform module to provision an HTTP style ALB ingress based on hostname and/or path.
39+
40+
ALB ingress can be provisioned without authentication, or using Cognito or OIDC authentication.
3941
4042
# How to use this project
4143
usage: |-
42-
Include this module in your existing terraform code:
44+
For a complete example, see [examples/complete](examples/complete).
45+
46+
For automated test of the complete example using `bats` and `Terratest`, see [test](test).
4347
4448
```hcl
45-
module "alb_ingress" {
46-
source = "git::https://github.com/cloudposse/terraform-aws-alb-ingress.git?ref=master"
47-
namespace = "eg"
48-
name = "app"
49-
stage = "dev"
50-
51-
vpc_id = "xxxxxxxx"
52-
unauthenticated_listener_arns = ["xxxxxx", "yyyyyyy"]
53-
unauthenticated_listener_arns_count = "2"
54-
health_check_path = "/healthz"
55-
unauthenticated_paths = ["/*"]
56-
}
49+
provider "aws" {
50+
region = var.region
51+
}
52+
53+
module "vpc" {
54+
source = "git::https://github.com/cloudposse/terraform-aws-vpc.git?ref=tags/0.8.1"
55+
namespace = var.namespace
56+
stage = var.stage
57+
name = var.name
58+
delimiter = var.delimiter
59+
attributes = var.attributes
60+
cidr_block = var.vpc_cidr_block
61+
tags = var.tags
62+
}
63+
64+
module "subnets" {
65+
source = "git::https://github.com/cloudposse/terraform-aws-dynamic-subnets.git?ref=tags/0.16.1"
66+
availability_zones = var.availability_zones
67+
namespace = var.namespace
68+
stage = var.stage
69+
name = var.name
70+
attributes = var.attributes
71+
delimiter = var.delimiter
72+
vpc_id = module.vpc.vpc_id
73+
igw_id = module.vpc.igw_id
74+
cidr_block = module.vpc.vpc_cidr_block
75+
nat_gateway_enabled = false
76+
nat_instance_enabled = false
77+
tags = var.tags
78+
}
79+
80+
module "alb" {
81+
source = "git::https://github.com/cloudposse/terraform-aws-alb.git?ref=tags/0.7.0"
82+
namespace = var.namespace
83+
stage = var.stage
84+
name = var.name
85+
attributes = var.attributes
86+
delimiter = var.delimiter
87+
vpc_id = module.vpc.vpc_id
88+
security_group_ids = [module.vpc.vpc_default_security_group_id]
89+
subnet_ids = module.subnets.public_subnet_ids
90+
internal = var.internal
91+
http_enabled = var.http_enabled
92+
access_logs_enabled = var.access_logs_enabled
93+
alb_access_logs_s3_bucket_force_destroy = var.alb_access_logs_s3_bucket_force_destroy
94+
access_logs_region = var.access_logs_region
95+
cross_zone_load_balancing_enabled = var.cross_zone_load_balancing_enabled
96+
http2_enabled = var.http2_enabled
97+
idle_timeout = var.idle_timeout
98+
ip_address_type = var.ip_address_type
99+
deletion_protection_enabled = var.deletion_protection_enabled
100+
deregistration_delay = var.deregistration_delay
101+
health_check_path = var.health_check_path
102+
health_check_timeout = var.health_check_timeout
103+
health_check_healthy_threshold = var.health_check_healthy_threshold
104+
health_check_unhealthy_threshold = var.health_check_unhealthy_threshold
105+
health_check_interval = var.health_check_interval
106+
health_check_matcher = var.health_check_matcher
107+
target_group_port = var.target_group_port
108+
target_group_target_type = var.target_group_target_type
109+
tags = var.tags
110+
}
111+
112+
module "alb_ingress" {
113+
source = "git::https://github.com/cloudposse/terraform-aws-alb-ingress.git?ref=master"
114+
namespace = var.namespace
115+
stage = var.stage
116+
name = var.name
117+
attributes = var.attributes
118+
delimiter = var.delimiter
119+
vpc_id = module.vpc.vpc_id
120+
authentication_type = var.authentication_type
121+
unauthenticated_priority = var.unauthenticated_priority
122+
unauthenticated_paths = var.unauthenticated_paths
123+
slow_start = var.slow_start
124+
stickiness_enabled = var.stickiness_enabled
125+
default_target_group_enabled = false
126+
target_group_arn = module.alb.default_target_group_arn
127+
unauthenticated_listener_arns = [module.alb.http_listener_arn]
128+
unauthenticated_listener_arns_count = 1
129+
tags = var.tags
130+
}
57131
```
58132
59133
# Other files to include in this README from the project folder

Diff for: codefresh/test.yml

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
version: '1.0'
2+
3+
stages:
4+
- Prepare
5+
- Test
6+
7+
steps:
8+
wait:
9+
title: Wait
10+
stage: Prepare
11+
image: codefresh/cli:latest
12+
commands:
13+
- codefresh get builds --pipeline=${{CF_REPO_NAME}} --status running --limit 1000 -o json | jq --arg id ${{CF_BUILD_ID}} -ser 'flatten|.[-1].id==$id'
14+
retry:
15+
maxAttempts: 10
16+
delay: 20
17+
exponentialFactor: 1.1
18+
19+
main_clone:
20+
title: "Clone repository"
21+
type: git-clone
22+
stage: Prepare
23+
description: "Initialize"
24+
repo: ${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}
25+
git: CF-default
26+
revision: ${{CF_REVISION}}
27+
28+
clean_init:
29+
title: Prepare build-harness and test-harness
30+
image: ${{TEST_IMAGE}}
31+
stage: Prepare
32+
commands:
33+
- cf_export PATH="/usr/local/terraform/0.12/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
34+
- make init
35+
- git -C build-harness checkout master
36+
- make -C test/ clean init TEST_HARNESS_BRANCH=master
37+
- make -C test/src clean init
38+
- find . -type d -name '.terraform' | xargs rm -rf
39+
- find . -type f -name 'terraform.tfstate*' -exec rm -f {} \;
40+
41+
test:
42+
type: "parallel"
43+
title: "Run tests"
44+
description: "Run all tests in parallel"
45+
stage: Test
46+
steps:
47+
test_readme_lint:
48+
title: "Test README.md updated"
49+
stage: "Test"
50+
image: ${{TEST_IMAGE}}
51+
description: Test "readme/lint"
52+
commands:
53+
- make readme/lint
54+
55+
test_module:
56+
title: Test module with bats
57+
image: ${{TEST_IMAGE}}
58+
stage: Test
59+
commands:
60+
- make -C test/ module
61+
62+
test_examples_complete:
63+
title: Test "examples/complete" with bats
64+
image: ${{TEST_IMAGE}}
65+
stage: Test
66+
commands:
67+
- make -C test/ examples/complete
68+
69+
test_examples_complete_terratest:
70+
title: Test "examples/complete" with terratest
71+
image: ${{TEST_IMAGE}}
72+
stage: Test
73+
commands:
74+
- make -C test/src

Diff for: docs/terraform.md

+36-35
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
| Name | Description | Type | Default | Required |
44
|------|-------------|:----:|:-----:|:-----:|
5-
| attributes | Additional attributes, e.g. `1` | list | `<list>` | no |
6-
| authenticated_hosts | Authenticated hosts to match in Hosts header | list | `<list>` | no |
7-
| authenticated_listener_arns | A list of authenticated ALB listener ARNs to attach ALB listener rules to | list | `<list>` | no |
8-
| authenticated_listener_arns_count | The number of authenticated ARNs in `authenticated_listener_arns`. This is necessary to work around a limitation in Terraform where counts cannot be computed | string | `0` | no |
9-
| authenticated_paths | Authenticated path pattern to match (a maximum of 1 can be defined) | list | `<list>` | no |
10-
| authenticated_priority | The priority for the rules with authentication, between 1 and 50000 (1 being highest priority). Must be different from `unauthenticated_priority` since a listener can't have multiple rules with the same priority | string | `300` | no |
5+
| attributes | Additional attributes (_e.g._ "1") | list(string) | `<list>` | no |
6+
| authenticated_hosts | Authenticated hosts to match in Hosts header | list(string) | `<list>` | no |
7+
| authenticated_listener_arns | A list of authenticated ALB listener ARNs to attach ALB listener rules to | list(string) | `<list>` | no |
8+
| authenticated_listener_arns_count | The number of authenticated ARNs in `authenticated_listener_arns`. This is necessary to work around a limitation in Terraform where counts cannot be computed | number | `0` | no |
9+
| authenticated_paths | Authenticated path pattern to match (a maximum of 1 can be defined) | list(string) | `<list>` | no |
10+
| authenticated_priority | The priority for the rules with authentication, between 1 and 50000 (1 being highest priority). Must be different from `unauthenticated_priority` since a listener can't have multiple rules with the same priority | number | `300` | no |
1111
| authentication_cognito_user_pool_arn | Cognito User Pool ARN | string | `` | no |
1212
| authentication_cognito_user_pool_client_id | Cognito User Pool Client ID | string | `` | no |
1313
| authentication_cognito_user_pool_domain | Cognito User Pool Domain. The User Pool Domain should be set to the domain prefix (`xxx`) instead of full domain (https://xxx.auth.us-west-2.amazoncognito.com) | string | `` | no |
@@ -18,41 +18,42 @@
1818
| authentication_oidc_token_endpoint | OIDC Token Endpoint | string | `` | no |
1919
| authentication_oidc_user_info_endpoint | OIDC User Info Endpoint | string | `` | no |
2020
| authentication_type | Authentication type. Supported values are `COGNITO` and `OIDC` | string | `` | no |
21-
| delimiter | Delimiter to be used between `namespace`, `name`, `stage` and `attributes` | string | `-` | no |
22-
| deregistration_delay | The amount of time to wait in seconds while deregistering target | string | `15` | no |
23-
| health_check_enabled | Indicates whether health checks are enabled. Defaults to `true`. | string | `true` | no |
24-
| health_check_healthy_threshold | The number of consecutive health checks successes required before healthy | string | `2` | no |
25-
| health_check_interval | The duration in seconds in between health checks | string | `15` | no |
21+
| default_target_group_enabled | Enable/disable creation of the default target group | bool | `true` | no |
22+
| delimiter | Delimiter between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
23+
| deregistration_delay | The amount of time to wait in seconds while deregistering target | number | `15` | no |
24+
| health_check_enabled | Indicates whether health checks are enabled. Defaults to `true` | bool | `true` | no |
25+
| health_check_healthy_threshold | The number of consecutive health checks successes required before healthy | number | `2` | no |
26+
| health_check_interval | The duration in seconds in between health checks | number | `15` | no |
2627
| health_check_matcher | The HTTP response codes to indicate a healthy check | string | `200-399` | no |
2728
| health_check_path | The destination for the health check request | string | `/` | no |
28-
| health_check_port | The port to use to connect with the target. Valid values are either ports 1-65536, or `traffic-port`. Defaults to `traffic-port`. | string | `traffic-port` | no |
29-
| health_check_protocol | The protocol to use to connect with the target. Defaults to `HTTP`. Not applicable when `target_type` is `lambda`. | string | `HTTP` | no |
30-
| health_check_timeout | The amount of time to wait in seconds before failing a health check request | string | `10` | no |
31-
| health_check_unhealthy_threshold | The number of consecutive health check failures required before unhealthy | string | `2` | no |
32-
| name | Solution name, e.g. `app` | string | - | yes |
33-
| namespace | Namespace, which could be your organization name, e.g. `cp` or `cloudposse` | string | - | yes |
34-
| port | The port for generated ALB target group (if `target_group_arn` not set) | string | `80` | no |
35-
| protocol | The protocol for generated ALB target group (if `target_group_arn` not set) | string | `HTTP` | no |
36-
| slow_start | The amount time for targets to warm up before the load balancer sends them a full share of requests. The range is 30-900 seconds or 0 to disable. The default value is `0` seconds. | string | `0` | no |
37-
| stage | Stage, e.g. `prod`, `staging`, `dev`, or `test` | string | - | yes |
38-
| stickiness_cookie_duration | The time period, in seconds, during which requests from a client should be routed to the same target. After this time period expires, the load balancer-generated cookie is considered stale. The range is 1 second to 1 week (604800 seconds). The default value is 1 day (86400 seconds). | string | `86400` | no |
39-
| stickiness_enabled | Boolean to enable / disable `stickiness`. Default is `true` | string | `true` | no |
40-
| stickiness_type | The type of sticky sessions. The only current possible value is `lb_cookie`. | string | `lb_cookie` | no |
41-
| tags | Additional tags (e.g. `map(`BusinessUnit`,`XYZ`) | map | `<map>` | no |
42-
| target_group_arn | ALB target group ARN. If this is an empty string, a new one will be generated | string | `` | no |
43-
| target_type | - | string | `ip` | no |
44-
| unauthenticated_hosts | Unauthenticated hosts to match in Hosts header | list | `<list>` | no |
45-
| unauthenticated_listener_arns | A list of unauthenticated ALB listener ARNs to attach ALB listener rules to | list | `<list>` | no |
46-
| unauthenticated_listener_arns_count | The number of unauthenticated ARNs in `unauthenticated_listener_arns`. This is necessary to work around a limitation in Terraform where counts cannot be computed | string | `0` | no |
47-
| unauthenticated_paths | Unauthenticated path pattern to match (a maximum of 1 can be defined) | list | `<list>` | no |
48-
| unauthenticated_priority | The priority for the rules without authentication, between 1 and 50000 (1 being highest priority). Must be different from `authenticated_priority` since a listener can't have multiple rules with the same priority | string | `100` | no |
29+
| health_check_port | The port to use to connect with the target. Valid values are either ports 1-65536, or `traffic-port`. Defaults to `traffic-port` | string | `traffic-port` | no |
30+
| health_check_protocol | The protocol to use to connect with the target. Defaults to `HTTP`. Not applicable when `target_type` is `lambda` | string | `HTTP` | no |
31+
| health_check_timeout | The amount of time to wait in seconds before failing a health check request | number | `10` | no |
32+
| health_check_unhealthy_threshold | The number of consecutive health check failures required before unhealthy | number | `2` | no |
33+
| name | Name of the application | string | - | yes |
34+
| namespace | Namespace (e.g. `eg` or `cp`) | string | `` | no |
35+
| port | The port for the created ALB target group (if `target_group_arn` is not set) | number | `80` | no |
36+
| protocol | The protocol for the created ALB target group (if `target_group_arn` is not set) | string | `HTTP` | no |
37+
| slow_start | The amount of time for targets to warm up before the load balancer sends them a full share of requests. The range is 30-900 seconds or 0 to disable. The default value is `0` seconds | number | `0` | no |
38+
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | `` | no |
39+
| stickiness_cookie_duration | The time period, in seconds, during which requests from a client should be routed to the same target. After this time period expires, the load balancer-generated cookie is considered stale. The range is 1 second to 1 week (604800 seconds). The default value is 1 day (86400 seconds) | number | `86400` | no |
40+
| stickiness_enabled | Boolean to enable / disable `stickiness`. Default is `true` | bool | `true` | no |
41+
| stickiness_type | The type of sticky sessions. The only current possible value is `lb_cookie` | string | `lb_cookie` | no |
42+
| tags | Additional tags (_e.g._ { BusinessUnit : ABC }) | map(string) | `<map>` | no |
43+
| target_group_arn | Existing ALB target group ARN. If provided, set `default_target_group_enabled` to `false` to disable creation of the default target group | string | `` | no |
44+
| target_type | The type (`instance`, `ip` or `lambda`) of targets that can be registered with the target group | string | `ip` | no |
45+
| unauthenticated_hosts | Unauthenticated hosts to match in Hosts header | list(string) | `<list>` | no |
46+
| unauthenticated_listener_arns | A list of unauthenticated ALB listener ARNs to attach ALB listener rules to | list(string) | `<list>` | no |
47+
| unauthenticated_listener_arns_count | The number of unauthenticated ARNs in `unauthenticated_listener_arns`. This is necessary to work around a limitation in Terraform where counts cannot be computed | number | `0` | no |
48+
| unauthenticated_paths | Unauthenticated path pattern to match (a maximum of 1 can be defined) | list(string) | `<list>` | no |
49+
| unauthenticated_priority | The priority for the rules without authentication, between 1 and 50000 (1 being highest priority). Must be different from `authenticated_priority` since a listener can't have multiple rules with the same priority | number | `100` | no |
4950
| vpc_id | The VPC ID where generated ALB target group will be provisioned (if `target_group_arn` is not set) | string | - | yes |
5051

5152
## Outputs
5253

5354
| Name | Description |
5455
|------|-------------|
55-
| target_group_arn | ALB Target group ARN |
56-
| target_group_arn_suffix | ALB Target group ARN suffix |
57-
| target_group_name | ALB Target group name |
56+
| target_group_arn | ALB Target Group ARN |
57+
| target_group_arn_suffix | ALB Target Group ARN suffix |
58+
| target_group_name | ALB Target Group name |
5859

Diff for: example/main.tf

-16
This file was deleted.

0 commit comments

Comments
 (0)