Skip to content

Commit 54869f7

Browse files
authored
Convert to TF 0.12. Add tests. Add Codefresh test pipeline (#16)
* Convert to TF 0.12 * Convert to TF 0.12 * Convert to TF 0.12 * Convert to TF 0.12 * Convert to TF 0.12 * Convert to TF 0.12 * Convert to TF 0.12 * 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 * 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 * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline
1 parent ecb7fd1 commit 54869f7

34 files changed

+3171
-837
lines changed

.travis.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

README.md

Lines changed: 307 additions & 81 deletions
Large diffs are not rendered by default.

README.yaml

Lines changed: 203 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ screenshots:
2424

2525
# Badges to display
2626
badges:
27-
- name: "Build Status"
28-
image: "https://travis-ci.org/cloudposse/terraform-aws-ecs-atlantis.svg?branch=master"
29-
url: "https://travis-ci.org/cloudposse/terraform-aws-ecs-atlantis"
27+
- name: "Codefresh Build Status"
28+
image: "https://g.codefresh.io/api/badges/pipeline/cloudposse/terraform-modules%2Fterraform-aws-ecs-atlantis?type=cf-1"
29+
url: "https://g.codefresh.io/public/accounts/cloudposse/pipelines/5dc082b14d7990012e651a3b"
3030
- name: "Latest Release"
3131
image: "https://img.shields.io/github/release/cloudposse/terraform-aws-ecs-atlantis.svg"
3232
url: "https://github.com/cloudposse/terraform-aws-ecs-atlantis/releases/latest"
@@ -159,11 +159,15 @@ introduction: |-
159159
# How to use this project
160160
usage: |-
161161
162-
Module usage examples:
162+
For a complete example, see [examples/complete](examples/complete).
163163
164-
- [without authentication](examples/without_authentication) - complete example without authentication
165-
- [with Google OIDC authentication](examples/with_google_oidc_authentication) - complete example with Google OIDC authentication
166-
- [with Cognito authentication](examples/with_cognito_authentication) - complete example with Cognito authentication
164+
For automated tests of the complete example using [bats](https://github.com/bats-core/bats-core) and [Terratest](https://github.com/gruntwork-io/terratest) (which tests and deploys the example on AWS), see [test](test).
165+
166+
Other examples:
167+
168+
- [without authentication](examples/without_authentication) - example without authentication
169+
- [with Google OIDC authentication](examples/with_google_oidc_authentication) - example with Google OIDC authentication
170+
- [with Cognito authentication](examples/with_cognito_authentication) - example with Cognito authentication
167171
168172
169173
**NOTE:**
@@ -172,39 +176,198 @@ usage: |-
172176
173177
If no `github_webhooks_token` is set, [Terraform GitHub Provider](https://www.terraform.io/docs/providers/github/index.html) attempts to look one up in the `GITHUB_TOKEN` environment variable.
174178
175-
```
176-
module "atlantis" {
177-
source = "git::https://github.com/cloudposse/terraform-aws-ecs-atlantis.git?ref=master"
178-
enabled = "true"
179-
name = "${var.name}"
180-
namespace = "${var.namespace}"
181-
region = "${var.region}"
182-
stage = "${var.stage}"
183-
184-
atlantis_gh_team_whitelist = "admins:*,engineering:plan"
185-
atlantis_gh_user = "atlantis_bot"
186-
atlantis_repo_whitelist = ["github.com/testing.example.co/*"]
187-
188-
alb_arn_suffix = "${module.alb.alb_arn_suffix}"
189-
alb_dns_name = "${module.alb.alb_dns_name}"
190-
alb_name = "${module.alb.alb_name}"
191-
alb_zone_id = "${module.alb.alb_zone_id}"
192-
193-
domain_name = "${var.domain_name}"
194-
ecs_cluster_arn = "${aws_ecs_cluster.default.arn}"
195-
ecs_cluster_name = "${aws_ecs_cluster.default.name}"
196-
repo_name = "testing.example.co"
197-
repo_owner = "example_org"
198-
private_subnet_ids = ["${module.subnets.private_subnet_ids}"]
199-
security_group_ids = ["${module.vpc.vpc_default_security_group_id}"]
200-
vpc_id = "${module.vpc.vpc_id}"
201-
202-
alb_ingress_unauthenticated_listener_arns = ["${module.alb.listener_arns}"]
203-
alb_ingress_unauthenticated_listener_arns_count = 2
204-
alb_ingress_unauthenticated_paths = ["/*"]
205-
alb_ingress_listener_unauthenticated_priority = "100"
206-
alb_ingress_authenticated_paths = []
207-
}
179+
```hcl
180+
provider "aws" {
181+
region = var.region
182+
}
183+
184+
module "label" {
185+
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.16.0"
186+
namespace = var.namespace
187+
name = var.name
188+
stage = var.stage
189+
delimiter = var.delimiter
190+
attributes = var.attributes
191+
tags = var.tags
192+
}
193+
194+
module "vpc" {
195+
source = "git::https://github.com/cloudposse/terraform-aws-vpc.git?ref=tags/0.8.1"
196+
namespace = var.namespace
197+
stage = var.stage
198+
name = var.name
199+
delimiter = var.delimiter
200+
attributes = var.attributes
201+
cidr_block = var.vpc_cidr_block
202+
tags = var.tags
203+
}
204+
205+
module "subnets" {
206+
source = "git::https://github.com/cloudposse/terraform-aws-dynamic-subnets.git?ref=tags/0.16.1"
207+
availability_zones = var.availability_zones
208+
namespace = var.namespace
209+
stage = var.stage
210+
name = var.name
211+
attributes = var.attributes
212+
delimiter = var.delimiter
213+
vpc_id = module.vpc.vpc_id
214+
igw_id = module.vpc.igw_id
215+
cidr_block = module.vpc.vpc_cidr_block
216+
nat_gateway_enabled = true
217+
nat_instance_enabled = false
218+
tags = var.tags
219+
}
220+
221+
module "alb" {
222+
source = "git::https://github.com/cloudposse/terraform-aws-alb.git?ref=tags/0.7.0"
223+
namespace = var.namespace
224+
stage = var.stage
225+
name = var.name
226+
attributes = var.attributes
227+
delimiter = var.delimiter
228+
vpc_id = module.vpc.vpc_id
229+
security_group_ids = [module.vpc.vpc_default_security_group_id]
230+
subnet_ids = module.subnets.public_subnet_ids
231+
internal = false
232+
http_enabled = true
233+
access_logs_enabled = false
234+
alb_access_logs_s3_bucket_force_destroy = true
235+
access_logs_region = var.region
236+
cross_zone_load_balancing_enabled = true
237+
http2_enabled = true
238+
deletion_protection_enabled = false
239+
tags = var.tags
240+
}
241+
242+
resource "aws_ecs_cluster" "default" {
243+
name = module.label.id
244+
tags = module.label.tags
245+
}
246+
247+
resource "aws_sns_topic" "sns_topic" {
248+
name = module.label.id
249+
display_name = "Test terraform-aws-ecs-atlantis"
250+
tags = module.label.tags
251+
}
252+
253+
module "kms_key" {
254+
source = "git::https://github.com/cloudposse/terraform-aws-kms-key.git?ref=tags/0.3.0"
255+
enabled = var.enabled
256+
namespace = var.namespace
257+
stage = var.stage
258+
name = var.name
259+
attributes = var.attributes
260+
delimiter = var.delimiter
261+
tags = var.tags
262+
description = "Test terraform-aws-ecs-atlantis KMS key"
263+
deletion_window_in_days = 7
264+
enable_key_rotation = false
265+
}
266+
267+
module "atlantis" {
268+
source = "git::https://github.com/cloudposse/terraform-aws-ecs-atlantis.git?ref=master"
269+
enabled = var.enabled
270+
namespace = var.namespace
271+
stage = var.stage
272+
name = var.name
273+
attributes = var.attributes
274+
delimiter = var.delimiter
275+
tags = var.tags
276+
277+
region = var.region
278+
vpc_id = module.vpc.vpc_id
279+
policy_arn = var.policy_arn
280+
ssh_private_key_name = var.ssh_private_key_name
281+
ssh_public_key_name = var.ssh_public_key_name
282+
kms_key_id = module.kms_key.key_id
283+
284+
atlantis_gh_user = var.atlantis_gh_user
285+
atlantis_gh_team_whitelist = var.atlantis_gh_team_whitelist
286+
atlantis_gh_webhook_secret = var.atlantis_gh_webhook_secret
287+
atlantis_log_level = var.atlantis_log_level
288+
atlantis_repo_config = var.atlantis_repo_config
289+
atlantis_repo_whitelist = var.atlantis_repo_whitelist
290+
atlantis_port = var.atlantis_port
291+
atlantis_webhook_format = var.atlantis_webhook_format
292+
atlantis_url_format = var.atlantis_url_format
293+
294+
default_backend_image = var.default_backend_image
295+
healthcheck_path = var.healthcheck_path
296+
short_name = var.short_name
297+
hostname = var.hostname
298+
parent_zone_id = var.parent_zone_id
299+
300+
// Container
301+
container_cpu = var.container_cpu
302+
container_memory = var.container_memory
303+
304+
// Authentication
305+
authentication_type = var.authentication_type
306+
alb_ingress_listener_unauthenticated_priority = var.alb_ingress_listener_unauthenticated_priority
307+
alb_ingress_listener_authenticated_priority = var.alb_ingress_listener_authenticated_priority
308+
alb_ingress_unauthenticated_hosts = var.alb_ingress_unauthenticated_hosts
309+
alb_ingress_authenticated_hosts = var.alb_ingress_authenticated_hosts
310+
alb_ingress_unauthenticated_paths = var.alb_ingress_unauthenticated_paths
311+
alb_ingress_authenticated_paths = var.alb_ingress_authenticated_paths
312+
authentication_cognito_user_pool_arn = var.authentication_cognito_user_pool_arn
313+
authentication_cognito_user_pool_client_id = var.authentication_cognito_user_pool_client_id
314+
authentication_cognito_user_pool_domain = var.authentication_cognito_user_pool_domain
315+
authentication_oidc_client_id = var.authentication_oidc_client_id
316+
authentication_oidc_client_secret = var.authentication_oidc_client_secret
317+
authentication_oidc_issuer = var.authentication_oidc_issuer
318+
authentication_oidc_authorization_endpoint = var.authentication_oidc_authorization_endpoint
319+
authentication_oidc_token_endpoint = var.authentication_oidc_token_endpoint
320+
authentication_oidc_user_info_endpoint = var.authentication_oidc_user_info_endpoint
321+
322+
// ECS
323+
private_subnet_ids = module.subnets.private_subnet_ids
324+
ecs_cluster_arn = aws_ecs_cluster.default.arn
325+
ecs_cluster_name = aws_ecs_cluster.default.name
326+
security_group_ids = var.security_group_ids
327+
desired_count = var.desired_count
328+
launch_type = var.launch_type
329+
330+
// ALB
331+
alb_zone_id = module.alb.alb_zone_id
332+
alb_arn_suffix = module.alb.alb_arn_suffix
333+
alb_dns_name = module.alb.alb_dns_name
334+
alb_security_group = module.alb.security_group_id
335+
alb_ingress_unauthenticated_listener_arns = [module.alb.http_listener_arn]
336+
alb_ingress_unauthenticated_listener_arns_count = 1
337+
338+
// CodePipeline
339+
codepipeline_enabled = var.codepipeline_enabled
340+
github_oauth_token = var.github_oauth_token
341+
github_webhooks_token = var.github_webhooks_token
342+
repo_owner = var.repo_owner
343+
repo_name = var.repo_name
344+
branch = var.branch
345+
build_timeout = var.build_timeout
346+
webhook_enabled = var.webhook_enabled
347+
webhook_secret_length = var.webhook_secret_length
348+
webhook_events = var.webhook_events
349+
codepipeline_s3_bucket_force_destroy = var.codepipeline_s3_bucket_force_destroy
350+
351+
// Autoscaling
352+
autoscaling_enabled = var.autoscaling_enabled
353+
autoscaling_min_capacity = var.autoscaling_min_capacity
354+
autoscaling_max_capacity = var.autoscaling_max_capacity
355+
356+
// Alarms
357+
alb_target_group_alarms_enabled = var.alb_target_group_alarms_enabled
358+
ecs_alarms_enabled = var.ecs_alarms_enabled
359+
alb_target_group_alarms_alarm_actions = [aws_sns_topic.sns_topic.arn]
360+
alb_target_group_alarms_ok_actions = [aws_sns_topic.sns_topic.arn]
361+
alb_target_group_alarms_insufficient_data_actions = [aws_sns_topic.sns_topic.arn]
362+
ecs_alarms_cpu_utilization_high_alarm_actions = [aws_sns_topic.sns_topic.arn]
363+
ecs_alarms_cpu_utilization_high_ok_actions = [aws_sns_topic.sns_topic.arn]
364+
ecs_alarms_cpu_utilization_low_alarm_actions = [aws_sns_topic.sns_topic.arn]
365+
ecs_alarms_cpu_utilization_low_ok_actions = [aws_sns_topic.sns_topic.arn]
366+
ecs_alarms_memory_utilization_high_alarm_actions = [aws_sns_topic.sns_topic.arn]
367+
ecs_alarms_memory_utilization_high_ok_actions = [aws_sns_topic.sns_topic.arn]
368+
ecs_alarms_memory_utilization_low_alarm_actions = [aws_sns_topic.sns_topic.arn]
369+
ecs_alarms_memory_utilization_low_ok_actions = [aws_sns_topic.sns_topic.arn]
370+
}
208371
```
209372
210373
# Example usage

codefresh/test.yml

Lines changed: 74 additions & 0 deletions
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

0 commit comments

Comments
 (0)