├── .gitignore ├── docs ├── targets.md └── terraform.md ├── .travis.yml ├── Makefile ├── outputs.tf ├── variables.tf ├── README.yaml ├── main.tf ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled files 2 | *.tfstate 3 | *.tfstate.backup 4 | 5 | # Module directory 6 | .terraform 7 | .idea 8 | *.iml 9 | 10 | .build-harness 11 | build-harness 12 | -------------------------------------------------------------------------------- /docs/targets.md: -------------------------------------------------------------------------------- 1 | ## Makefile Targets 2 | ``` 3 | Available targets: 4 | 5 | help Help screen 6 | help/all Display help for all targets 7 | help/short This help short screen 8 | 9 | ``` 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | addons: 2 | apt: 3 | packages: 4 | - git 5 | - make 6 | - curl 7 | 8 | install: 9 | - make init 10 | 11 | script: 12 | - make terraform/install 13 | - make terraform/get-plugins 14 | - make terraform/get-modules 15 | - make terraform/lint 16 | - make terraform/validate -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SHELL := /bin/bash 2 | 3 | # List of targets the `readme` target should call before generating the readme 4 | export README_DEPS ?= docs/targets.md docs/terraform.md 5 | 6 | -include $(shell curl -sSL -o .build-harness "https://git.io/build-harness"; echo .build-harness) 7 | 8 | lint: 9 | $(SELF) terraform/install terraform/get-modules terraform/get-plugins terraform/lint terraform/validate 10 | -------------------------------------------------------------------------------- /outputs.tf: -------------------------------------------------------------------------------- 1 | output "badge_url" { 2 | description = "The URL of the build badge when badge_enabled is enabled" 3 | value = "${module.build.badge_url}" 4 | } 5 | 6 | output "webhook_id" { 7 | description = "The CodePipeline webhook's ARN." 8 | value = "${join("", aws_codepipeline_webhook.webhook.*.id)}" 9 | } 10 | 11 | output "webhook_url" { 12 | description = "The CodePipeline webhook's URL. POST events to this endpoint to trigger the target." 13 | value = "${local.webhook_url}" 14 | sensitive = true 15 | } 16 | -------------------------------------------------------------------------------- /docs/terraform.md: -------------------------------------------------------------------------------- 1 | ## Inputs 2 | 3 | | Name | Description | Type | Default | Required | 4 | |------|-------------|:----:|:-----:|:-----:| 5 | | attributes | Additional attributes (e.g. `policy` or `role`) | list | `` | no | 6 | | 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 | 7 | | 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 | 8 | | badge_enabled | Generates a publicly-accessible URL for the projects build badge. Available as badge_url attribute when enabled. | string | `false` | no | 9 | | branch | Branch of the GitHub repository, _e.g._ `master` | string | - | yes | 10 | | build_compute_type | `CodeBuild` instance size. Possible values are: `BUILD_GENERAL1_SMALL` `BUILD_GENERAL1_MEDIUM` `BUILD_GENERAL1_LARGE` | string | `BUILD_GENERAL1_SMALL` | no | 11 | | build_image | Docker image for build environment, _e.g._ `aws/codebuild/docker:docker:17.09.0` | string | `aws/codebuild/docker:17.09.0` | no | 12 | | 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 | 13 | | 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 | 14 | | delimiter | Delimiter to be used between `name`, `namespace`, `stage`, etc. | string | `-` | no | 15 | | ecs_cluster_name | ECS Cluster Name | string | - | yes | 16 | | enabled | Enable `CodePipeline` creation | string | `true` | no | 17 | | 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 | `` | no | 18 | | github_oauth_token | GitHub Oauth Token with permissions to access private repositories | string | - | yes | 19 | | 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 | `` | no | 20 | | 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 | 21 | | 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 | 22 | | name | Solution name, e.g. 'app' or 'jenkins' | string | `app` | no | 23 | | namespace | Namespace, which could be your organization name, e.g. 'cp' or 'cloudposse' | string | `global` | no | 24 | | poll_source_changes | Periodically check the location of your source content and run the pipeline if changes are detected | string | `false` | no | 25 | | 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 | 26 | | repo_name | GitHub repository name of the application to be built and deployed to ECS. | string | - | yes | 27 | | repo_owner | GitHub Organization or Username. | string | - | yes | 28 | | service_name | ECS Service Name | string | - | yes | 29 | | stage | Stage, e.g. 'prod', 'staging', 'dev', or 'test' | string | `default` | no | 30 | | tags | Additional tags (e.g. `map('BusinessUnit', 'XYZ')` | map | `` | no | 31 | | webhook_authentication | The type of authentication to use. One of IP, GITHUB_HMAC, or UNAUTHENTICATED. | string | `GITHUB_HMAC` | no | 32 | | webhook_enabled | Set to false to prevent the module from creating any webhook resources | string | `true` | no | 33 | | webhook_filter_json_path | The JSON path to filter on. | string | `$.ref` | no | 34 | | webhook_filter_match_equals | The value to match on (e.g. refs/heads/{Branch}) | string | `refs/heads/{Branch}` | no | 35 | | 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 | 36 | 37 | ## Outputs 38 | 39 | | Name | Description | 40 | |------|-------------| 41 | | badge_url | The URL of the build badge when badge_enabled is enabled | 42 | | webhook_id | The CodePipeline webhook's ARN. | 43 | | webhook_url | The CodePipeline webhook's URL. POST events to this endpoint to trigger the target. | 44 | 45 | -------------------------------------------------------------------------------- /variables.tf: -------------------------------------------------------------------------------- 1 | variable "namespace" { 2 | default = "global" 3 | description = "Namespace, which could be your organization name, e.g. 'cp' or 'cloudposse'" 4 | } 5 | 6 | variable "stage" { 7 | default = "default" 8 | description = "Stage, e.g. 'prod', 'staging', 'dev', or 'test'" 9 | } 10 | 11 | variable "name" { 12 | default = "app" 13 | description = "Solution name, e.g. 'app' or 'jenkins'" 14 | } 15 | 16 | variable "enabled" { 17 | default = "true" 18 | description = "Enable `CodePipeline` creation" 19 | } 20 | 21 | variable "ecs_cluster_name" { 22 | type = "string" 23 | description = "ECS Cluster Name" 24 | } 25 | 26 | variable "service_name" { 27 | type = "string" 28 | description = "ECS Service Name" 29 | } 30 | 31 | variable "staging_service_name" { 32 | type = "string" 33 | description = "ECS Staging Service Name" 34 | } 35 | 36 | variable "approve_sns_arn" { 37 | type = "string" 38 | description = "SNS topic ARN for code approval" 39 | } 40 | 41 | variable "github_oauth_token" { 42 | description = "GitHub Oauth Token with permissions to access private repositories" 43 | } 44 | 45 | variable "github_webhook_events" { 46 | description = "A list of events which should trigger the webhook. See a list of [available events](https://developer.github.com/v3/activity/events/types/)." 47 | default = ["push"] 48 | } 49 | 50 | variable "repo_owner" { 51 | description = "GitHub Organization or Username." 52 | } 53 | 54 | variable "repo_name" { 55 | description = "GitHub repository name of the application to be built and deployed to ECS." 56 | } 57 | 58 | variable "branch" { 59 | description = "Branch of the GitHub repository, _e.g._ `master`" 60 | } 61 | 62 | variable "badge_enabled" { 63 | type = "string" 64 | default = "false" 65 | description = "Generates a publicly-accessible URL for the projects build badge. Available as badge_url attribute when enabled." 66 | } 67 | 68 | variable "build_image" { 69 | default = "aws/codebuild/docker:17.09.0" 70 | description = "Docker image for build environment, _e.g._ `aws/codebuild/docker:docker:17.09.0`" 71 | } 72 | 73 | variable "build_compute_type" { 74 | default = "BUILD_GENERAL1_SMALL" 75 | description = "`CodeBuild` instance size. Possible values are: `BUILD_GENERAL1_SMALL` `BUILD_GENERAL1_MEDIUM` `BUILD_GENERAL1_LARGE`" 76 | } 77 | 78 | variable "build_timeout" { 79 | type = "string" 80 | default = "60" 81 | description = "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." 82 | } 83 | 84 | variable "buildspec" { 85 | default = "" 86 | description = "Declaration to use for building the project. [For more info](http://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html)" 87 | } 88 | 89 | # https://www.terraform.io/docs/configuration/variables.html 90 | # It is recommended you avoid using boolean values and use explicit strings 91 | variable "poll_source_changes" { 92 | type = "string" 93 | default = "false" 94 | description = "Periodically check the location of your source content and run the pipeline if changes are detected" 95 | } 96 | 97 | variable "delimiter" { 98 | type = "string" 99 | default = "-" 100 | description = "Delimiter to be used between `name`, `namespace`, `stage`, etc." 101 | } 102 | 103 | variable "attributes" { 104 | type = "list" 105 | default = [] 106 | description = "Additional attributes (e.g. `policy` or `role`)" 107 | } 108 | 109 | variable "tags" { 110 | type = "map" 111 | default = {} 112 | description = "Additional tags (e.g. `map('BusinessUnit', 'XYZ')`" 113 | } 114 | 115 | variable "privileged_mode" { 116 | default = "false" 117 | description = "If set to true, enables running the Docker daemon inside a Docker container on the CodeBuild instance. Used when building Docker images" 118 | } 119 | 120 | variable "aws_region" { 121 | type = "string" 122 | default = "" 123 | description = "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)" 124 | } 125 | 126 | variable "aws_account_id" { 127 | type = "string" 128 | default = "" 129 | description = "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)" 130 | } 131 | 132 | variable "image_repo_name" { 133 | type = "string" 134 | default = "UNSET" 135 | description = "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)" 136 | } 137 | 138 | variable "image_tag" { 139 | type = "string" 140 | default = "latest" 141 | description = "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)" 142 | } 143 | 144 | variable "environment_variables" { 145 | type = "list" 146 | 147 | default = [{ 148 | "name" = "NO_ADDITIONAL_BUILD_VARS" 149 | "value" = "TRUE" 150 | }] 151 | 152 | description = "A list of maps, that contain both the key 'name' and the key 'value' to be used as additional environment variables for the build." 153 | } 154 | 155 | variable "webhook_enabled" { 156 | description = "Set to false to prevent the module from creating any webhook resources" 157 | default = "true" 158 | } 159 | 160 | variable "webhook_target_action" { 161 | description = "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." 162 | default = "Source" 163 | } 164 | 165 | variable "webhook_authentication" { 166 | description = "The type of authentication to use. One of IP, GITHUB_HMAC, or UNAUTHENTICATED." 167 | default = "GITHUB_HMAC" 168 | } 169 | 170 | variable "webhook_filter_json_path" { 171 | description = "The JSON path to filter on." 172 | default = "$.ref" 173 | } 174 | 175 | variable "webhook_filter_match_equals" { 176 | description = "The value to match on (e.g. refs/heads/{Branch})" 177 | default = "refs/heads/{Branch}" 178 | } 179 | -------------------------------------------------------------------------------- /README.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | # 3 | # This is the canonical configuration for the `README.md` 4 | # Run `make readme` to rebuild the `README.md` 5 | # 6 | 7 | # Name of this project 8 | name: terraform-aws-ecs-codepipeline 9 | 10 | # Logo for this project 11 | #logo: docs/logo.png 12 | 13 | # License of this project 14 | license: "APACHE2" 15 | 16 | # Canonical GitHub repo 17 | github_repo: cloudposse/terraform-aws-ecs-codepipeline 18 | 19 | # Badges to display 20 | 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" 24 | - name: "Latest Release" 25 | image: "https://img.shields.io/github/release/cloudposse/terraform-aws-ecs-codepipeline.svg" 26 | url: "https://github.com/cloudposse/terraform-aws-ecs-codepipeline/releases/latest" 27 | - name: "Slack Community" 28 | image: "https://slack.cloudposse.com/badge.svg" 29 | url: "https://slack.cloudposse.com" 30 | 31 | related: 32 | - name: "terraform-aws-alb" 33 | description: "Terraform module to provision a standard ALB for HTTP/HTTP traffic" 34 | url: "https://github.com/cloudposse/terraform-aws-alb" 35 | - name: "terraform-aws-alb-ingress" 36 | description: "Terraform module to provision an HTTP style ingress rule based on hostname and path for an ALB" 37 | url: "https://github.com/cloudposse/terraform-aws-alb-ingress" 38 | - name: "terraform-aws-codebuild" 39 | description: "Terraform Module to easily leverage AWS CodeBuild for Continuous Integration" 40 | url: "https://github.com/cloudposse/terraform-aws-codebuild" 41 | - name: "terraform-aws-ecr" 42 | description: "Terraform Module to manage Docker Container Registries on AWS ECR" 43 | url: "https://github.com/cloudposse/terraform-aws-ecr" 44 | - name: "terraform-aws-ecs-alb-service-task" 45 | description: "Terraform module which implements an ECS service which exposes a web service via ALB." 46 | url: "https://github.com/cloudposse/terraform-aws-ecs-alb-service-task" 47 | - name: "terraform-aws-ecs-container-definition" 48 | description: "Terraform module to generate well-formed JSON documents that are passed to the aws_ecs_task_definition Terraform resource" 49 | url: "https://github.com/cloudposse/terraform-aws-ecs-container-definition" 50 | - name: "terraform-aws-lb-s3-bucket" 51 | description: "Terraform module to provision an S3 bucket with built in IAM policy to allow AWS Load Balancers to ship access logs." 52 | url: "https://github.com/cloudposse/terraform-aws-lb-s3-bucket" 53 | 54 | # Short description of this project 55 | description: |- 56 | Terraform Module for CI/CD with AWS Code Pipeline using GitHub webhook triggers and Code Build for ECS. 57 | 58 | # How to use this project 59 | usage: |- 60 | 61 | ### Trigger on GitHub Push 62 | 63 | In this example, we'll trigger the pipeline anytime the `master` branch is updated. 64 | ```hcl 65 | module "ecs_push_pipeline" { 66 | source = "git::https://github.com/cloudposse/terraform-aws-ecs-codepipeline.git?ref=tags/0.1.2" 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" 77 | } 78 | ``` 79 | 80 | ### Trigger on GitHub Releases 81 | 82 | In this example, we'll trigger anytime a new GitHub release is cut by setting the even type to `release` and using the `json_path` to *exactly* match an `action` of `published`. 83 | 84 | ```hcl 85 | module "ecs_release_pipeline" { 86 | source = "git::https://github.com/cloudposse/terraform-aws-ecs-codepipeline.git?ref=tags/0.1.2" 87 | name = "app" 88 | namespace = "eg" 89 | stage = "staging" 90 | github_oauth_token = "xxxxxxxxxxxxxx" 91 | repo_owner = "cloudposse" 92 | repo_name = "example" 93 | branch = "master" 94 | service_name = "example" 95 | ecs_cluster_name = "example-ecs-cluster" 96 | privileged_mode = "true" 97 | github_webhook_events = ["release"] 98 | webhook_filter_json_path = "$.action" 99 | webhook_filter_match_equals = "published" 100 | } 101 | ``` 102 | (Thanks to [Stack Overflow](https://stackoverflow.com/questions/52516087/trigger-aws-codepipeline-by-github-release-webhook#comment91997146_52524711)) 103 | 104 | 105 | 106 | # Example usage 107 | examples: |- 108 | Complete usage can be seen in the [terraform-aws-ecs-web-app](https://github.com/cloudposse/terraform-aws-ecs-web-app/blob/master/main.tf) module. 109 | 110 | ## Example Buildspec 111 | 112 | Here's an example `buildspec.yaml`. Stick this in the root of your project repository. 113 | 114 | ```yaml 115 | version: 0.2 116 | phases: 117 | pre_build: 118 | commands: 119 | - echo Logging in to Amazon ECR... 120 | - aws --version 121 | - eval $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email) 122 | - REPOSITORY_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$IMAGE_REPO_NAME 123 | - IMAGE_TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7) 124 | build: 125 | commands: 126 | - echo Build started on `date` 127 | - echo Building the Docker image... 128 | - REPO_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$IMAGE_REPO_NAME 129 | - docker pull $REPO_URI:latest || true 130 | - docker build --cache-from $REPO_URI:latest --tag $REPO_URI:latest --tag $REPO_URI:$IMAGE_TAG . 131 | post_build: 132 | commands: 133 | - echo Build completed on `date` 134 | - echo Pushing the Docker images... 135 | - REPO_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$IMAGE_REPO_NAME 136 | - docker push $REPO_URI:latest 137 | - docker push $REPO_URI:$IMAGE_TAG 138 | - echo Writing image definitions file... 139 | - printf '[{"name":"%s","imageUri":"%s"}]' "$CONTAINER_NAME" "$REPO_URI:$IMAGE_TAG" | tee imagedefinitions.json 140 | artifacts: 141 | files: imagedefinitions.json 142 | ``` 143 | 144 | # How to get started quickly 145 | #quickstart: |- 146 | # Here's how to get started... 147 | 148 | # Other files to include in this README from the project folder 149 | include: 150 | - "docs/targets.md" 151 | - "docs/terraform.md" 152 | 153 | references: 154 | - name: "aws_codepipeline_webhook" 155 | description: "Provides a CodePipeline Webhook" 156 | url: "https://www.terraform.io/docs/providers/aws/r/codepipeline_webhook.html" 157 | 158 | # Contributors to this project 159 | contributors: 160 | - name: "Erik Osterman" 161 | github: "osterman" 162 | - name: "Igor Rodionov" 163 | github: "goruha" 164 | - name: "Andriy Knysh" 165 | github: "aknysh" 166 | - name: "Sarkis Varozian" 167 | github: "sarkis" 168 | -------------------------------------------------------------------------------- /main.tf: -------------------------------------------------------------------------------- 1 | module "codepipeline_label" { 2 | source = "github.com/cloudposse/terraform-terraform-label.git?ref=0.1.2" 3 | attributes = ["${compact(concat(var.attributes, list("codepipeline")))}"] 4 | delimiter = "${var.delimiter}" 5 | name = "${var.name}" 6 | namespace = "${var.namespace}" 7 | stage = "${var.stage}" 8 | tags = "${var.tags}" 9 | } 10 | 11 | resource "aws_s3_bucket" "default" { 12 | count = "${var.enabled == "true" ? 1 : 0}" 13 | bucket = "${module.codepipeline_label.id}" 14 | acl = "private" 15 | tags = "${module.codepipeline_label.tags}" 16 | } 17 | 18 | module "codepipeline_assume_label" { 19 | source = "github.com/cloudposse/terraform-terraform-label.git?ref=0.1.2" 20 | attributes = ["${compact(concat(var.attributes, list("codepipeline", "assume")))}"] 21 | delimiter = "${var.delimiter}" 22 | name = "${var.name}" 23 | namespace = "${var.namespace}" 24 | stage = "${var.stage}" 25 | tags = "${var.tags}" 26 | } 27 | 28 | resource "aws_iam_role" "default" { 29 | count = "${var.enabled == "true" ? 1 : 0}" 30 | name = "${module.codepipeline_assume_label.id}" 31 | assume_role_policy = "${data.aws_iam_policy_document.assume.json}" 32 | } 33 | 34 | data "aws_iam_policy_document" "assume" { 35 | statement { 36 | sid = "" 37 | 38 | actions = [ 39 | "sts:AssumeRole", 40 | ] 41 | 42 | principals { 43 | type = "Service" 44 | identifiers = ["codepipeline.amazonaws.com"] 45 | } 46 | 47 | effect = "Allow" 48 | } 49 | } 50 | 51 | resource "aws_iam_role_policy_attachment" "default" { 52 | count = "${var.enabled == "true" ? 1 : 0}" 53 | role = "${aws_iam_role.default.id}" 54 | policy_arn = "${aws_iam_policy.default.arn}" 55 | } 56 | 57 | resource "aws_iam_policy" "default" { 58 | count = "${var.enabled == "true" ? 1 : 0}" 59 | name = "${module.codepipeline_label.id}" 60 | policy = "${data.aws_iam_policy_document.default.json}" 61 | } 62 | 63 | data "aws_iam_policy_document" "default" { 64 | statement { 65 | sid = "" 66 | 67 | actions = [ 68 | "ec2:*", 69 | "elasticloadbalancing:*", 70 | "autoscaling:*", 71 | "cloudwatch:*", 72 | "s3:*", 73 | "sns:*", 74 | "cloudformation:*", 75 | "rds:*", 76 | "sqs:*", 77 | "ecs:*", 78 | "iam:PassRole", 79 | ] 80 | 81 | resources = ["*"] 82 | effect = "Allow" 83 | } 84 | } 85 | 86 | resource "aws_iam_role_policy_attachment" "s3" { 87 | count = "${var.enabled == "true" ? 1 : 0}" 88 | role = "${aws_iam_role.default.id}" 89 | policy_arn = "${aws_iam_policy.s3.arn}" 90 | } 91 | 92 | module "codepipeline_s3_policy_label" { 93 | source = "github.com/cloudposse/terraform-terraform-label.git?ref=0.1.2" 94 | attributes = ["${compact(concat(var.attributes, list("codepipeline", "s3")))}"] 95 | delimiter = "${var.delimiter}" 96 | name = "${var.name}" 97 | namespace = "${var.namespace}" 98 | stage = "${var.stage}" 99 | tags = "${var.tags}" 100 | } 101 | 102 | resource "aws_iam_policy" "s3" { 103 | count = "${var.enabled == "true" ? 1 : 0}" 104 | name = "${module.codepipeline_s3_policy_label.id}" 105 | policy = "${data.aws_iam_policy_document.s3.json}" 106 | } 107 | 108 | data "aws_iam_policy_document" "s3" { 109 | count = "${var.enabled == "true" ? 1 : 0}" 110 | 111 | statement { 112 | sid = "" 113 | 114 | actions = [ 115 | "s3:GetObject", 116 | "s3:GetObjectVersion", 117 | "s3:GetBucketVersioning", 118 | "s3:PutObject", 119 | ] 120 | 121 | resources = [ 122 | "${aws_s3_bucket.default.arn}", 123 | "${aws_s3_bucket.default.arn}/*", 124 | ] 125 | 126 | effect = "Allow" 127 | } 128 | } 129 | 130 | resource "aws_iam_role_policy_attachment" "codebuild" { 131 | count = "${var.enabled == "true" ? 1 : 0}" 132 | role = "${aws_iam_role.default.id}" 133 | policy_arn = "${aws_iam_policy.codebuild.arn}" 134 | } 135 | 136 | module "codebuild_label" { 137 | source = "github.com/cloudposse/terraform-terraform-label.git?ref=0.1.2" 138 | attributes = ["${compact(concat(var.attributes, list("codebuild")))}"] 139 | delimiter = "${var.delimiter}" 140 | name = "${var.name}" 141 | namespace = "${var.namespace}" 142 | stage = "${var.stage}" 143 | tags = "${var.tags}" 144 | } 145 | 146 | resource "aws_iam_policy" "codebuild" { 147 | count = "${var.enabled == "true" ? 1 : 0}" 148 | name = "${module.codebuild_label.id}" 149 | policy = "${data.aws_iam_policy_document.codebuild.json}" 150 | } 151 | 152 | data "aws_iam_policy_document" "codebuild" { 153 | statement { 154 | sid = "" 155 | 156 | actions = [ 157 | "codebuild:*", 158 | ] 159 | 160 | resources = ["${module.build.project_id}"] 161 | effect = "Allow" 162 | } 163 | } 164 | 165 | data "aws_caller_identity" "default" {} 166 | 167 | data "aws_region" "default" {} 168 | 169 | module "build" { 170 | source = "git::https://github.com/cloudposse/terraform-aws-codebuild.git?ref=tags/0.12.1" 171 | enabled = "${var.enabled}" 172 | namespace = "${var.namespace}" 173 | name = "${var.name}" 174 | stage = "${var.stage}" 175 | build_image = "${var.build_image}" 176 | build_compute_type = "${var.build_compute_type}" 177 | build_timeout = "${var.build_timeout}" 178 | buildspec = "${var.buildspec}" 179 | delimiter = "${var.delimiter}" 180 | attributes = "${concat(var.attributes, list("build"))}" 181 | tags = "${var.tags}" 182 | privileged_mode = "${var.privileged_mode}" 183 | aws_region = "${signum(length(var.aws_region)) == 1 ? var.aws_region : data.aws_region.default.name}" 184 | aws_account_id = "${signum(length(var.aws_account_id)) == 1 ? var.aws_account_id : data.aws_caller_identity.default.account_id}" 185 | image_repo_name = "${var.image_repo_name}" 186 | image_tag = "${var.image_tag}" 187 | github_token = "${var.github_oauth_token}" 188 | environment_variables = "${var.environment_variables}" 189 | badge_enabled = "${var.badge_enabled}" 190 | } 191 | 192 | resource "aws_iam_role_policy_attachment" "codebuild_s3" { 193 | count = "${var.enabled == "true" ? 1 : 0}" 194 | role = "${module.build.role_arn}" 195 | policy_arn = "${aws_iam_policy.s3.arn}" 196 | } 197 | 198 | resource "aws_codepipeline" "source_build_deploy" { 199 | count = "${var.enabled == "true" ? 1 : 0}" 200 | name = "${module.codepipeline_label.id}" 201 | role_arn = "${aws_iam_role.default.arn}" 202 | 203 | artifact_store { 204 | location = "${aws_s3_bucket.default.bucket}" 205 | type = "S3" 206 | } 207 | 208 | stage { 209 | name = "Source" 210 | 211 | action { 212 | name = "Source" 213 | category = "Source" 214 | owner = "ThirdParty" 215 | provider = "GitHub" 216 | version = "1" 217 | output_artifacts = ["code"] 218 | 219 | configuration { 220 | OAuthToken = "${var.github_oauth_token}" 221 | Owner = "${var.repo_owner}" 222 | Repo = "${var.repo_name}" 223 | Branch = "${var.branch}" 224 | PollForSourceChanges = "${var.poll_source_changes}" 225 | } 226 | } 227 | } 228 | 229 | stage { 230 | name = "Build" 231 | 232 | action { 233 | name = "Build" 234 | category = "Build" 235 | owner = "AWS" 236 | provider = "CodeBuild" 237 | version = "1" 238 | 239 | input_artifacts = ["code"] 240 | output_artifacts = ["task"] 241 | 242 | configuration { 243 | ProjectName = "${module.build.project_name}" 244 | } 245 | } 246 | } 247 | 248 | stage { 249 | name = "Staging" 250 | 251 | action { 252 | name = "DeployStaging" 253 | category = "Deploy" 254 | owner = "AWS" 255 | provider = "ECS" 256 | input_artifacts = ["task"] 257 | version = "1" 258 | 259 | configuration { 260 | ClusterName = "${var.ecs_cluster_name}" 261 | ServiceName = "${var.staging_service_name}" 262 | } 263 | } 264 | } 265 | 266 | stage { 267 | name = "Approval" 268 | 269 | action { 270 | name = "Approval" 271 | category = "Approval" 272 | owner = "AWS" 273 | provider = "Manual" 274 | version = "1" 275 | 276 | configuration { 277 | NotificationArn = "${var.approve_sns_arn}" 278 | } 279 | } 280 | } 281 | 282 | stage { 283 | name = "Production" 284 | 285 | action { 286 | name = "DeployProd" 287 | category = "Deploy" 288 | owner = "AWS" 289 | provider = "ECS" 290 | input_artifacts = ["task"] 291 | version = "1" 292 | 293 | configuration { 294 | ClusterName = "${var.ecs_cluster_name}" 295 | ServiceName = "${var.service_name}" 296 | } 297 | } 298 | } 299 | } 300 | 301 | resource "random_string" "webhook_secret" { 302 | count = "${var.webhook_enabled == "true" ? 1 : 0}" 303 | length = 32 304 | 305 | # Special characters are not allowed in webhook secret (AWS silently ignores webhook callbacks) 306 | special = false 307 | } 308 | 309 | locals { 310 | webhook_secret = "${join("", random_string.webhook_secret.*.result)}" 311 | webhook_url = "${join("", aws_codepipeline_webhook.webhook.*.url)}" 312 | } 313 | 314 | resource "aws_codepipeline_webhook" "webhook" { 315 | count = "${var.webhook_enabled == "true" ? 1 : 0}" 316 | name = "${module.codepipeline_label.id}" 317 | authentication = "${var.webhook_authentication}" 318 | target_action = "${var.webhook_target_action}" 319 | target_pipeline = "${join("", aws_codepipeline.source_build_deploy.*.name)}" 320 | 321 | authentication_configuration { 322 | secret_token = "${local.webhook_secret}" 323 | } 324 | 325 | filter { 326 | json_path = "${var.webhook_filter_json_path}" 327 | match_equals = "${var.webhook_filter_match_equals}" 328 | } 329 | } 330 | 331 | module "github_webhooks" { 332 | source = "git::https://github.com/cloudposse/terraform-github-repository-webhooks.git?ref=tags/0.2.0" 333 | enabled = "${var.webhook_enabled}" 334 | github_organization = "${var.repo_owner}" 335 | github_repositories = ["${var.repo_name}"] 336 | github_token = "${var.github_oauth_token}" 337 | webhook_url = "${local.webhook_url}" 338 | webhook_secret = "${local.webhook_secret}" 339 | webhook_content_type = "json" 340 | name = "web" 341 | events = ["${var.github_webhook_events}"] 342 | } 343 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2018 Cloud Posse, LLC 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | [![README Header][readme_header_img]][readme_header_link] 3 | 4 | [![Cloud Posse][logo]](https://cpco.io/homepage) 5 | 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) 7 | 8 | 9 | Terraform Module for CI/CD with AWS Code Pipeline using GitHub webhook triggers and Code Build for ECS. 10 | 11 | 12 | --- 13 | 14 | This project is part of our comprehensive ["SweetOps"](https://cpco.io/sweetops) approach towards DevOps. 15 | [][share_email] 16 | [][share_googleplus] 17 | [][share_facebook] 18 | [][share_reddit] 19 | [][share_linkedin] 20 | [][share_twitter] 21 | 22 | 23 | [![Terraform Open Source Modules](https://docs.cloudposse.com/images/terraform-open-source-modules.svg)][terraform_modules] 24 | 25 | 26 | 27 | It's 100% Open Source and licensed under the [APACHE2](LICENSE). 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | We literally have [*hundreds of terraform modules*][terraform_modules] that are Open Source and well-maintained. Check them out! 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | ## Usage 44 | 45 | 46 | ### Trigger on GitHub Push 47 | 48 | In this example, we'll trigger the pipeline anytime the `master` branch is updated. 49 | ```hcl 50 | module "ecs_push_pipeline" { 51 | source = "git::https://github.com/cloudposse/terraform-aws-ecs-codepipeline.git?ref=tags/0.1.2" 52 | name = "app" 53 | namespace = "eg" 54 | stage = "staging" 55 | github_oauth_token = "xxxxxxxxxxxxxx" 56 | repo_owner = "cloudposse" 57 | repo_name = "example" 58 | branch = "master" 59 | service_name = "example" 60 | ecs_cluster_name = "example-ecs-cluster" 61 | privileged_mode = "true" 62 | } 63 | ``` 64 | 65 | ### Trigger on GitHub Releases 66 | 67 | In this example, we'll trigger anytime a new GitHub release is cut by setting the even type to `release` and using the `json_path` to *exactly* match an `action` of `published`. 68 | 69 | ```hcl 70 | module "ecs_release_pipeline" { 71 | source = "git::https://github.com/cloudposse/terraform-aws-ecs-codepipeline.git?ref=tags/0.1.2" 72 | name = "app" 73 | namespace = "eg" 74 | stage = "staging" 75 | github_oauth_token = "xxxxxxxxxxxxxx" 76 | repo_owner = "cloudposse" 77 | repo_name = "example" 78 | branch = "master" 79 | service_name = "example" 80 | ecs_cluster_name = "example-ecs-cluster" 81 | privileged_mode = "true" 82 | github_webhook_events = ["release"] 83 | webhook_filter_json_path = "$.action" 84 | webhook_filter_match_equals = "published" 85 | } 86 | ``` 87 | (Thanks to [Stack Overflow](https://stackoverflow.com/questions/52516087/trigger-aws-codepipeline-by-github-release-webhook#comment91997146_52524711)) 88 | 89 | 90 | 91 | 92 | ## Examples 93 | 94 | Complete usage can be seen in the [terraform-aws-ecs-web-app](https://github.com/cloudposse/terraform-aws-ecs-web-app/blob/master/main.tf) module. 95 | 96 | ## Example Buildspec 97 | 98 | Here's an example `buildspec.yaml`. Stick this in the root of your project repository. 99 | 100 | ```yaml 101 | version: 0.2 102 | phases: 103 | pre_build: 104 | commands: 105 | - echo Logging in to Amazon ECR... 106 | - aws --version 107 | - eval $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email) 108 | - REPOSITORY_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$IMAGE_REPO_NAME 109 | - IMAGE_TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7) 110 | build: 111 | commands: 112 | - echo Build started on `date` 113 | - echo Building the Docker image... 114 | - REPO_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$IMAGE_REPO_NAME 115 | - docker pull $REPO_URI:latest || true 116 | - docker build --cache-from $REPO_URI:latest --tag $REPO_URI:latest --tag $REPO_URI:$IMAGE_TAG . 117 | post_build: 118 | commands: 119 | - echo Build completed on `date` 120 | - echo Pushing the Docker images... 121 | - REPO_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$IMAGE_REPO_NAME 122 | - docker push $REPO_URI:latest 123 | - docker push $REPO_URI:$IMAGE_TAG 124 | - echo Writing image definitions file... 125 | - printf '[{"name":"%s","imageUri":"%s"}]' "$CONTAINER_NAME" "$REPO_URI:$IMAGE_TAG" | tee imagedefinitions.json 126 | artifacts: 127 | files: imagedefinitions.json 128 | ``` 129 | 130 | 131 | 132 | ## Makefile Targets 133 | ``` 134 | Available targets: 135 | 136 | help Help screen 137 | help/all Display help for all targets 138 | help/short This help short screen 139 | 140 | ``` 141 | ## Inputs 142 | 143 | | Name | Description | Type | Default | Required | 144 | |------|-------------|:----:|:-----:|:-----:| 145 | | attributes | Additional attributes (e.g. `policy` or `role`) | list | `` | no | 146 | | 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 | 147 | | 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 | 148 | | badge_enabled | Generates a publicly-accessible URL for the projects build badge. Available as badge_url attribute when enabled. | string | `false` | no | 149 | | branch | Branch of the GitHub repository, _e.g._ `master` | string | - | yes | 150 | | build_compute_type | `CodeBuild` instance size. Possible values are: `BUILD_GENERAL1_SMALL` `BUILD_GENERAL1_MEDIUM` `BUILD_GENERAL1_LARGE` | string | `BUILD_GENERAL1_SMALL` | no | 151 | | build_image | Docker image for build environment, _e.g._ `aws/codebuild/docker:docker:17.09.0` | string | `aws/codebuild/docker:17.09.0` | no | 152 | | 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 | 153 | | 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 | 154 | | delimiter | Delimiter to be used between `name`, `namespace`, `stage`, etc. | string | `-` | no | 155 | | ecs_cluster_name | ECS Cluster Name | string | - | yes | 156 | | enabled | Enable `CodePipeline` creation | string | `true` | no | 157 | | 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 | `` | no | 158 | | github_oauth_token | GitHub Oauth Token with permissions to access private repositories | string | - | yes | 159 | | 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 | `` | no | 160 | | 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 | 161 | | 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 | 162 | | name | Solution name, e.g. 'app' or 'jenkins' | string | `app` | no | 163 | | namespace | Namespace, which could be your organization name, e.g. 'cp' or 'cloudposse' | string | `global` | no | 164 | | poll_source_changes | Periodically check the location of your source content and run the pipeline if changes are detected | string | `false` | no | 165 | | 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 | 166 | | repo_name | GitHub repository name of the application to be built and deployed to ECS. | string | - | yes | 167 | | repo_owner | GitHub Organization or Username. | string | - | yes | 168 | | service_name | ECS Service Name | string | - | yes | 169 | | stage | Stage, e.g. 'prod', 'staging', 'dev', or 'test' | string | `default` | no | 170 | | tags | Additional tags (e.g. `map('BusinessUnit', 'XYZ')` | map | `` | no | 171 | | webhook_authentication | The type of authentication to use. One of IP, GITHUB_HMAC, or UNAUTHENTICATED. | string | `GITHUB_HMAC` | no | 172 | | webhook_enabled | Set to false to prevent the module from creating any webhook resources | string | `true` | no | 173 | | webhook_filter_json_path | The JSON path to filter on. | string | `$.ref` | no | 174 | | webhook_filter_match_equals | The value to match on (e.g. refs/heads/{Branch}) | string | `refs/heads/{Branch}` | no | 175 | | 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 | 176 | 177 | ## Outputs 178 | 179 | | Name | Description | 180 | |------|-------------| 181 | | badge_url | The URL of the build badge when badge_enabled is enabled | 182 | | webhook_id | The CodePipeline webhook's ARN. | 183 | | webhook_url | The CodePipeline webhook's URL. POST events to this endpoint to trigger the target. | 184 | 185 | 186 | 187 | 188 | ## Share the Love 189 | 190 | Like this project? Please give it a ★ on [our GitHub](https://github.com/cloudposse/terraform-aws-ecs-codepipeline)! (it helps us **a lot**) 191 | 192 | Are you using this project or any of our other projects? Consider [leaving a testimonial][testimonial]. =) 193 | 194 | 195 | ## Related Projects 196 | 197 | Check out these related projects. 198 | 199 | - [terraform-aws-alb](https://github.com/cloudposse/terraform-aws-alb) - Terraform module to provision a standard ALB for HTTP/HTTP traffic 200 | - [terraform-aws-alb-ingress](https://github.com/cloudposse/terraform-aws-alb-ingress) - Terraform module to provision an HTTP style ingress rule based on hostname and path for an ALB 201 | - [terraform-aws-codebuild](https://github.com/cloudposse/terraform-aws-codebuild) - Terraform Module to easily leverage AWS CodeBuild for Continuous Integration 202 | - [terraform-aws-ecr](https://github.com/cloudposse/terraform-aws-ecr) - Terraform Module to manage Docker Container Registries on AWS ECR 203 | - [terraform-aws-ecs-alb-service-task](https://github.com/cloudposse/terraform-aws-ecs-alb-service-task) - Terraform module which implements an ECS service which exposes a web service via ALB. 204 | - [terraform-aws-ecs-container-definition](https://github.com/cloudposse/terraform-aws-ecs-container-definition) - Terraform module to generate well-formed JSON documents that are passed to the aws_ecs_task_definition Terraform resource 205 | - [terraform-aws-lb-s3-bucket](https://github.com/cloudposse/terraform-aws-lb-s3-bucket) - Terraform module to provision an S3 bucket with built in IAM policy to allow AWS Load Balancers to ship access logs. 206 | 207 | 208 | 209 | 210 | ## References 211 | 212 | For additional context, refer to some of these links. 213 | 214 | - [aws_codepipeline_webhook](https://www.terraform.io/docs/providers/aws/r/codepipeline_webhook.html) - Provides a CodePipeline Webhook 215 | 216 | 217 | ## Help 218 | 219 | **Got a question?** 220 | 221 | File a GitHub [issue](https://github.com/cloudposse/terraform-aws-ecs-codepipeline/issues), send us an [email][email] or join our [Slack Community][slack]. 222 | 223 | [![README Commercial Support][readme_commercial_support_img]][readme_commercial_support_link] 224 | 225 | ## Commercial Support 226 | 227 | Work directly with our team of DevOps experts via email, slack, and video conferencing. 228 | 229 | We provide [*commercial support*][commercial_support] for all of our [Open Source][github] projects. As a *Dedicated Support* customer, you have access to our team of subject matter experts at a fraction of the cost of a full-time engineer. 230 | 231 | [![E-Mail](https://img.shields.io/badge/email-hello@cloudposse.com-blue.svg)][email] 232 | 233 | - **Questions.** We'll use a Shared Slack channel between your team and ours. 234 | - **Troubleshooting.** We'll help you triage why things aren't working. 235 | - **Code Reviews.** We'll review your Pull Requests and provide constructive feedback. 236 | - **Bug Fixes.** We'll rapidly work to fix any bugs in our projects. 237 | - **Build New Terraform Modules.** We'll [develop original modules][module_development] to provision infrastructure. 238 | - **Cloud Architecture.** We'll assist with your cloud strategy and design. 239 | - **Implementation.** We'll provide hands-on support to implement our reference architectures. 240 | 241 | 242 | 243 | ## Terraform Module Development 244 | 245 | Are you interested in custom Terraform module development? Submit your inquiry using [our form][module_development] today and we'll get back to you ASAP. 246 | 247 | 248 | ## Slack Community 249 | 250 | Join our [Open Source Community][slack] on Slack. It's **FREE** for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build totally *sweet* infrastructure. 251 | 252 | ## Newsletter 253 | 254 | Signup for [our newsletter][newsletter] that covers everything on our technology radar. Receive updates on what we're up to on GitHub as well as awesome new projects we discover. 255 | 256 | ## Contributing 257 | 258 | ### Bug Reports & Feature Requests 259 | 260 | Please use the [issue tracker](https://github.com/cloudposse/terraform-aws-ecs-codepipeline/issues) to report any bugs or file feature requests. 261 | 262 | ### Developing 263 | 264 | If you are interested in being a contributor and want to get involved in developing this project or [help out](https://cpco.io/help-out) with our other projects, we would love to hear from you! Shoot us an [email][email]. 265 | 266 | In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow. 267 | 268 | 1. **Fork** the repo on GitHub 269 | 2. **Clone** the project to your own machine 270 | 3. **Commit** changes to your own branch 271 | 4. **Push** your work back up to your fork 272 | 5. Submit a **Pull Request** so that we can review your changes 273 | 274 | **NOTE:** Be sure to merge the latest changes from "upstream" before making a pull request! 275 | 276 | 277 | ## Copyright 278 | 279 | Copyright © 2017-2019 [Cloud Posse, LLC](https://cpco.io/copyright) 280 | 281 | 282 | 283 | ## License 284 | 285 | [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) 286 | 287 | See [LICENSE](LICENSE) for full details. 288 | 289 | Licensed to the Apache Software Foundation (ASF) under one 290 | or more contributor license agreements. See the NOTICE file 291 | distributed with this work for additional information 292 | regarding copyright ownership. The ASF licenses this file 293 | to you under the Apache License, Version 2.0 (the 294 | "License"); you may not use this file except in compliance 295 | with the License. You may obtain a copy of the License at 296 | 297 | https://www.apache.org/licenses/LICENSE-2.0 298 | 299 | Unless required by applicable law or agreed to in writing, 300 | software distributed under the License is distributed on an 301 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 302 | KIND, either express or implied. See the License for the 303 | specific language governing permissions and limitations 304 | under the License. 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | ## Trademarks 315 | 316 | All other trademarks referenced herein are the property of their respective owners. 317 | 318 | ## About 319 | 320 | This project is maintained and funded by [Cloud Posse, LLC][website]. Like it? Please let us know by [leaving a testimonial][testimonial]! 321 | 322 | [![Cloud Posse][logo]][website] 323 | 324 | We're a [DevOps Professional Services][hire] company based in Los Angeles, CA. We ❤️ [Open Source Software][we_love_open_source]. 325 | 326 | We offer [paid support][commercial_support] on all of our projects. 327 | 328 | Check out [our other projects][github], [follow us on twitter][twitter], [apply for a job][jobs], or [hire us][hire] to help with your cloud strategy and implementation. 329 | 330 | 331 | 332 | ### Contributors 333 | 334 | | [![Erik Osterman][osterman_avatar]][osterman_homepage]
[Erik Osterman][osterman_homepage] | [![Igor Rodionov][goruha_avatar]][goruha_homepage]
[Igor Rodionov][goruha_homepage] | [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]
[Andriy Knysh][aknysh_homepage] | [![Sarkis Varozian][sarkis_avatar]][sarkis_homepage]
[Sarkis Varozian][sarkis_homepage] | 335 | |---|---|---|---| 336 | 337 | [osterman_homepage]: https://github.com/osterman 338 | [osterman_avatar]: https://github.com/osterman.png?size=150 339 | [goruha_homepage]: https://github.com/goruha 340 | [goruha_avatar]: https://github.com/goruha.png?size=150 341 | [aknysh_homepage]: https://github.com/aknysh 342 | [aknysh_avatar]: https://github.com/aknysh.png?size=150 343 | [sarkis_homepage]: https://github.com/sarkis 344 | [sarkis_avatar]: https://github.com/sarkis.png?size=150 345 | 346 | 347 | 348 | [![README Footer][readme_footer_img]][readme_footer_link] 349 | [![Beacon][beacon]][website] 350 | 351 | [logo]: https://cloudposse.com/logo-300x69.svg 352 | [docs]: https://cpco.io/docs 353 | [website]: https://cpco.io/homepage 354 | [github]: https://cpco.io/github 355 | [jobs]: https://cpco.io/jobs 356 | [hire]: https://cpco.io/hire 357 | [slack]: https://cpco.io/slack 358 | [linkedin]: https://cpco.io/linkedin 359 | [twitter]: https://cpco.io/twitter 360 | [testimonial]: https://cpco.io/leave-testimonial 361 | [newsletter]: https://cpco.io/newsletter 362 | [email]: https://cpco.io/email 363 | [commercial_support]: https://cpco.io/commercial-support 364 | [we_love_open_source]: https://cpco.io/we-love-open-source 365 | [module_development]: https://cpco.io/module-development 366 | [terraform_modules]: https://cpco.io/terraform-modules 367 | [readme_header_img]: https://cloudposse.com/readme/header/img?repo=cloudposse/terraform-aws-ecs-codepipeline 368 | [readme_header_link]: https://cloudposse.com/readme/header/link?repo=cloudposse/terraform-aws-ecs-codepipeline 369 | [readme_footer_img]: https://cloudposse.com/readme/footer/img?repo=cloudposse/terraform-aws-ecs-codepipeline 370 | [readme_footer_link]: https://cloudposse.com/readme/footer/link?repo=cloudposse/terraform-aws-ecs-codepipeline 371 | [readme_commercial_support_img]: https://cloudposse.com/readme/commercial-support/img?repo=cloudposse/terraform-aws-ecs-codepipeline 372 | [readme_commercial_support_link]: https://cloudposse.com/readme/commercial-support/link?repo=cloudposse/terraform-aws-ecs-codepipeline 373 | [share_twitter]: https://twitter.com/intent/tweet/?text=terraform-aws-ecs-codepipeline&url=https://github.com/cloudposse/terraform-aws-ecs-codepipeline 374 | [share_linkedin]: https://www.linkedin.com/shareArticle?mini=true&title=terraform-aws-ecs-codepipeline&url=https://github.com/cloudposse/terraform-aws-ecs-codepipeline 375 | [share_reddit]: https://reddit.com/submit/?url=https://github.com/cloudposse/terraform-aws-ecs-codepipeline 376 | [share_facebook]: https://facebook.com/sharer/sharer.php?u=https://github.com/cloudposse/terraform-aws-ecs-codepipeline 377 | [share_googleplus]: https://plus.google.com/share?url=https://github.com/cloudposse/terraform-aws-ecs-codepipeline 378 | [share_email]: mailto:?subject=terraform-aws-ecs-codepipeline&body=https://github.com/cloudposse/terraform-aws-ecs-codepipeline 379 | [beacon]: https://ga-beacon.cloudposse.com/UA-76589703-4/cloudposse/terraform-aws-ecs-codepipeline?pixel&cs=github&cm=readme&an=terraform-aws-ecs-codepipeline 380 | --------------------------------------------------------------------------------