Skip to content

Commit 4c0f5db

Browse files
authored
Convert to TF 0.12. Add tests. Add Codefresh test pipeline (#27)
* 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 7d05c8d commit 4c0f5db

22 files changed

+1406
-292
lines changed

.travis.yml

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

README.md

Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
[![Cloud Posse][logo]](https://cpco.io/homepage)
55

6-
# terraform-aws-ecs-codepipeline [![Build Status](https://travis-ci.org/cloudposse/terraform-aws-ecs-codepipeline.svg?branch=master)](https://travis-ci.org/cloudposse/terraform-aws-ecs-codepipeline) [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-ecs-codepipeline.svg)](https://github.com/cloudposse/terraform-aws-ecs-codepipeline/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
6+
# terraform-aws-ecs-codepipeline [![Codefresh Build Status](https://g.codefresh.io/api/badges/pipeline/cloudposse/terraform-modules%2Fterraform-aws-ecs-codepipeline?type=cf-1)](https://g.codefresh.io/public/accounts/cloudposse/pipelines/5db7b474041f802a8893f018) [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-ecs-codepipeline.svg)](https://github.com/cloudposse/terraform-aws-ecs-codepipeline/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
77

88

99
Terraform Module for CI/CD with AWS Code Pipeline using GitHub webhook triggers and Code Build for ECS.
@@ -48,22 +48,27 @@ Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest re
4848

4949

5050

51+
For a complete example, see [examples/complete](examples/complete).
52+
53+
For automated tests of the complete example using `bats` and `Terratest`, see [test](test).
54+
5155
### Trigger on GitHub Push
5256

5357
In this example, we'll trigger the pipeline anytime the `master` branch is updated.
5458
```hcl
5559
module "ecs_push_pipeline" {
56-
source = "git::https://github.com/cloudposse/terraform-aws-ecs-codepipeline.git?ref=master"
57-
name = "app"
58-
namespace = "eg"
59-
stage = "staging"
60-
github_oauth_token = "xxxxxxxxxxxxxx"
61-
repo_owner = "cloudposse"
62-
repo_name = "example"
63-
branch = "master"
64-
service_name = "example"
65-
ecs_cluster_name = "example-ecs-cluster"
66-
privileged_mode = "true"
60+
source = "git::https://github.com/cloudposse/terraform-aws-ecs-codepipeline.git?ref=master"
61+
name = "app"
62+
namespace = "eg"
63+
stage = "staging"
64+
github_oauth_token = "xxxxxxxxxxxxxx"
65+
github_webhooks_token = "xxxxxxxxxxxxxx"
66+
repo_owner = "cloudposse"
67+
repo_name = "example"
68+
branch = "master"
69+
service_name = "example"
70+
ecs_cluster_name = "eg-staging-example-cluster"
71+
privileged_mode = "true"
6772
}
6873
```
6974

@@ -78,17 +83,19 @@ module "ecs_release_pipeline" {
7883
namespace = "eg"
7984
stage = "staging"
8085
github_oauth_token = "xxxxxxxxxxxxxx"
86+
github_webhooks_token = "xxxxxxxxxxxxxx"
8187
repo_owner = "cloudposse"
8288
repo_name = "example"
8389
branch = "master"
8490
service_name = "example"
85-
ecs_cluster_name = "example-ecs-cluster"
91+
ecs_cluster_name = "eg-staging-example-cluster"
8692
privileged_mode = "true"
8793
github_webhook_events = ["release"]
8894
webhook_filter_json_path = "$.action"
8995
webhook_filter_match_equals = "published"
9096
}
9197
```
98+
9299
(Thanks to [Stack Overflow](https://stackoverflow.com/questions/52516087/trigger-aws-codepipeline-by-github-release-webhook#comment91997146_52524711))
93100

94101

@@ -147,46 +154,55 @@ Available targets:
147154
148155
| Name | Description | Type | Default | Required |
149156
|------|-------------|:----:|:-----:|:-----:|
150-
| attributes | Additional attributes (e.g. `policy` or `role`) | list | `<list>` | no |
157+
| attributes | Additional attributes (_e.g._ "1") | list(string) | `<list>` | no |
151158
| aws_account_id | AWS Account ID. Used as CodeBuild ENV variable when building Docker images. [For more info](http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html) | string | `` | no |
152-
| aws_region | AWS Region, e.g. us-east-1. Used as CodeBuild ENV variable when building Docker images. [For more info](http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html) | string | `` | no |
153-
| badge_enabled | Generates a publicly-accessible URL for the projects build badge. Available as badge_url attribute when enabled. | string | `false` | no |
159+
| badge_enabled | Generates a publicly-accessible URL for the projects build badge. Available as badge_url attribute when enabled | bool | `false` | no |
154160
| branch | Branch of the GitHub repository, _e.g._ `master` | string | - | yes |
155161
| build_compute_type | `CodeBuild` instance size. Possible values are: `BUILD_GENERAL1_SMALL` `BUILD_GENERAL1_MEDIUM` `BUILD_GENERAL1_LARGE` | string | `BUILD_GENERAL1_SMALL` | no |
156162
| build_image | Docker image for build environment, _e.g._ `aws/codebuild/docker:docker:17.09.0` | string | `aws/codebuild/docker:17.09.0` | no |
157-
| build_timeout | How long in minutes, from 5 to 480 (8 hours), for AWS CodeBuild to wait until timing out any related build that does not get marked as completed. | string | `60` | no |
163+
| build_timeout | How long in minutes, from 5 to 480 (8 hours), for AWS CodeBuild to wait until timing out any related build that does not get marked as completed | number | `60` | no |
158164
| buildspec | Declaration to use for building the project. [For more info](http://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html) | string | `` | no |
159-
| delimiter | Delimiter to be used between `name`, `namespace`, `stage`, etc. | string | `-` | no |
165+
| delimiter | Delimiter between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
160166
| ecs_cluster_name | ECS Cluster Name | string | - | yes |
161-
| enabled | Enable `CodePipeline` creation | string | `true` | no |
162-
| environment_variables | A list of maps, that contain both the key 'name' and the key 'value' to be used as additional environment variables for the build. | list | `<list>` | no |
167+
| enabled | Enable `CodePipeline` creation | bool | `true` | no |
168+
| environment_variables | A list of maps, that contain both the key 'name' and the key 'value' to be used as additional environment variables for the build | object | `<list>` | no |
163169
| github_oauth_token | GitHub OAuth Token with permissions to access private repositories | string | - | yes |
164-
| github_webhook_events | A list of events which should trigger the webhook. See a list of [available events](https://developer.github.com/v3/activity/events/types/) | list | `<list>` | no |
170+
| github_webhook_events | A list of events which should trigger the webhook. See a list of [available events](https://developer.github.com/v3/activity/events/types/) | list(string) | `<list>` | no |
165171
| github_webhooks_token | GitHub OAuth Token with permissions to create webhooks. If not provided, can be sourced from the `GITHUB_TOKEN` environment variable | string | `` | no |
166-
| image_repo_name | ECR repository name to store the Docker image built by this module. Used as CodeBuild ENV variable when building Docker images. [For more info](http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html) | string | `UNSET` | no |
172+
| image_repo_name | ECR repository name to store the Docker image built by this module. Used as CodeBuild ENV variable when building Docker images. [For more info](http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html) | string | - | yes |
167173
| image_tag | Docker image tag in the ECR repository, e.g. 'latest'. Used as CodeBuild ENV variable when building Docker images. [For more info](http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html) | string | `latest` | no |
168-
| name | Solution name, e.g. 'app' or 'jenkins' | string | `app` | no |
169-
| namespace | Namespace, which could be your organization name, e.g. 'cp' or 'cloudposse' | string | `global` | no |
170-
| poll_source_changes | Periodically check the location of your source content and run the pipeline if changes are detected | string | `false` | no |
171-
| privileged_mode | If set to true, enables running the Docker daemon inside a Docker container on the CodeBuild instance. Used when building Docker images | string | `false` | no |
172-
| repo_name | GitHub repository name of the application to be built and deployed to ECS. | string | - | yes |
173-
| repo_owner | GitHub Organization or Username. | string | - | yes |
174-
| s3_bucket_force_destroy | A boolean that indicates all objects should be deleted from the CodePipeline artifact store S3 bucket so that the bucket can be destroyed without error | string | `false` | no |
174+
| name | Name of the application | string | - | yes |
175+
| namespace | Namespace (e.g. `eg` or `cp`) | string | `` | no |
176+
| poll_source_changes | Periodically check the location of your source content and run the pipeline if changes are detected | bool | `false` | no |
177+
| privileged_mode | If set to true, enables running the Docker daemon inside a Docker container on the CodeBuild instance. Used when building Docker images | bool | `false` | no |
178+
| region | AWS Region, e.g. us-east-1. Used as CodeBuild ENV variable when building Docker images. [For more info](http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html) | string | - | yes |
179+
| repo_name | GitHub repository name of the application to be built and deployed to ECS | string | - | yes |
180+
| repo_owner | GitHub Organization or Username | string | - | yes |
181+
| s3_bucket_force_destroy | A boolean that indicates all objects should be deleted from the CodePipeline artifact store S3 bucket so that the bucket can be destroyed without error | bool | `false` | no |
175182
| service_name | ECS Service Name | string | - | yes |
176-
| stage | Stage, e.g. 'prod', 'staging', 'dev', or 'test' | string | `default` | no |
177-
| tags | Additional tags (e.g. `map('BusinessUnit', 'XYZ')` | map | `<map>` | no |
178-
| webhook_authentication | The type of authentication to use. One of IP, GITHUB_HMAC, or UNAUTHENTICATED. | string | `GITHUB_HMAC` | no |
179-
| webhook_enabled | Set to false to prevent the module from creating any webhook resources | string | `true` | no |
180-
| webhook_filter_json_path | The JSON path to filter on. | string | `$.ref` | no |
183+
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | `` | no |
184+
| tags | Additional tags (_e.g._ { BusinessUnit : ABC }) | map(string) | `<map>` | no |
185+
| webhook_authentication | The type of authentication to use. One of IP, GITHUB_HMAC, or UNAUTHENTICATED | string | `GITHUB_HMAC` | no |
186+
| webhook_enabled | Set to false to prevent the module from creating any webhook resources | bool | `true` | no |
187+
| webhook_filter_json_path | The JSON path to filter on | string | `$.ref` | no |
181188
| webhook_filter_match_equals | The value to match on (e.g. refs/heads/{Branch}) | string | `refs/heads/{Branch}` | no |
182-
| webhook_target_action | The name of the action in a pipeline you want to connect to the webhook. The action must be from the source (first) stage of the pipeline. | string | `Source` | no |
189+
| webhook_target_action | The name of the action in a pipeline you want to connect to the webhook. The action must be from the source (first) stage of the pipeline | string | `Source` | no |
183190

184191
## Outputs
185192

186193
| Name | Description |
187194
|------|-------------|
188195
| badge_url | The URL of the build badge when badge_enabled is enabled |
189-
| webhook_id | The CodePipeline webhook's ARN. |
196+
| codebuild_badge_url | The URL of the build badge when badge_enabled is enabled |
197+
| codebuild_cache_bucket_arn | CodeBuild cache S3 bucket ARN |
198+
| codebuild_cache_bucket_name | CodeBuild cache S3 bucket name |
199+
| codebuild_project_id | CodeBuild project ID |
200+
| codebuild_project_name | CodeBuild project name |
201+
| codebuild_role_arn | CodeBuild IAM Role ARN |
202+
| codebuild_role_id | CodeBuild IAM Role ID |
203+
| codepipeline_arn | CodePipeline ARN |
204+
| codepipeline_id | CodePipeline ID |
205+
| webhook_id | The CodePipeline webhook's ID |
190206
| webhook_url | The CodePipeline webhook's URL. POST events to this endpoint to trigger the target |
191207

192208

@@ -342,13 +358,13 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
342358
|---|---|---|---|
343359

344360
[osterman_homepage]: https://github.com/osterman
345-
[osterman_avatar]: https://github.com/osterman.png?size=150
361+
[osterman_avatar]: https://img.cloudposse.com/150x150/https://github.com/osterman.png
346362
[goruha_homepage]: https://github.com/goruha
347-
[goruha_avatar]: https://github.com/goruha.png?size=150
363+
[goruha_avatar]: https://img.cloudposse.com/150x150/https://github.com/goruha.png
348364
[aknysh_homepage]: https://github.com/aknysh
349-
[aknysh_avatar]: https://github.com/aknysh.png?size=150
365+
[aknysh_avatar]: https://img.cloudposse.com/150x150/https://github.com/aknysh.png
350366
[sarkis_homepage]: https://github.com/sarkis
351-
[sarkis_avatar]: https://github.com/sarkis.png?size=150
367+
[sarkis_avatar]: https://img.cloudposse.com/150x150/https://github.com/sarkis.png
352368

353369

354370

README.yaml

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ github_repo: cloudposse/terraform-aws-ecs-codepipeline
1818

1919
# Badges to display
2020
badges:
21-
- name: "Build Status"
22-
image: "https://travis-ci.org/cloudposse/terraform-aws-ecs-codepipeline.svg?branch=master"
23-
url: "https://travis-ci.org/cloudposse/terraform-aws-ecs-codepipeline"
21+
- name: "Codefresh Build Status"
22+
image: "https://g.codefresh.io/api/badges/pipeline/cloudposse/terraform-modules%2Fterraform-aws-ecs-codepipeline?type=cf-1"
23+
url: "https://g.codefresh.io/public/accounts/cloudposse/pipelines/5db7b474041f802a8893f018"
2424
- name: "Latest Release"
2525
image: "https://img.shields.io/github/release/cloudposse/terraform-aws-ecs-codepipeline.svg"
2626
url: "https://github.com/cloudposse/terraform-aws-ecs-codepipeline/releases/latest"
@@ -58,22 +58,27 @@ description: |-
5858
# How to use this project
5959
usage: |-
6060
61+
For a complete example, see [examples/complete](examples/complete).
62+
63+
For automated tests of the complete example using `bats` and `Terratest`, see [test](test).
64+
6165
### Trigger on GitHub Push
6266
6367
In this example, we'll trigger the pipeline anytime the `master` branch is updated.
6468
```hcl
6569
module "ecs_push_pipeline" {
66-
source = "git::https://github.com/cloudposse/terraform-aws-ecs-codepipeline.git?ref=master"
67-
name = "app"
68-
namespace = "eg"
69-
stage = "staging"
70-
github_oauth_token = "xxxxxxxxxxxxxx"
71-
repo_owner = "cloudposse"
72-
repo_name = "example"
73-
branch = "master"
74-
service_name = "example"
75-
ecs_cluster_name = "example-ecs-cluster"
76-
privileged_mode = "true"
70+
source = "git::https://github.com/cloudposse/terraform-aws-ecs-codepipeline.git?ref=master"
71+
name = "app"
72+
namespace = "eg"
73+
stage = "staging"
74+
github_oauth_token = "xxxxxxxxxxxxxx"
75+
github_webhooks_token = "xxxxxxxxxxxxxx"
76+
repo_owner = "cloudposse"
77+
repo_name = "example"
78+
branch = "master"
79+
service_name = "example"
80+
ecs_cluster_name = "eg-staging-example-cluster"
81+
privileged_mode = "true"
7782
}
7883
```
7984
@@ -88,19 +93,20 @@ usage: |-
8893
namespace = "eg"
8994
stage = "staging"
9095
github_oauth_token = "xxxxxxxxxxxxxx"
96+
github_webhooks_token = "xxxxxxxxxxxxxx"
9197
repo_owner = "cloudposse"
9298
repo_name = "example"
9399
branch = "master"
94100
service_name = "example"
95-
ecs_cluster_name = "example-ecs-cluster"
101+
ecs_cluster_name = "eg-staging-example-cluster"
96102
privileged_mode = "true"
97103
github_webhook_events = ["release"]
98104
webhook_filter_json_path = "$.action"
99105
webhook_filter_match_equals = "published"
100106
}
101107
```
102-
(Thanks to [Stack Overflow](https://stackoverflow.com/questions/52516087/trigger-aws-codepipeline-by-github-release-webhook#comment91997146_52524711))
103108
109+
(Thanks to [Stack Overflow](https://stackoverflow.com/questions/52516087/trigger-aws-codepipeline-by-github-release-webhook#comment91997146_52524711))
104110
105111
106112
# 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)