Skip to content

Commit

Permalink
feat: initial implementation (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
SweetOps authored Mar 4, 2021
1 parent 3efd1fb commit 38ecf6c
Show file tree
Hide file tree
Showing 15 changed files with 1,566 additions and 194 deletions.
154 changes: 95 additions & 59 deletions README.md

Large diffs are not rendered by default.

95 changes: 51 additions & 44 deletions README.yaml
Original file line number Diff line number Diff line change
@@ -1,64 +1,71 @@
---
#
# This is the canonical configuration for the `README.md`
# Run `make readme` to rebuild the `README.md`
#

# Name of this project
name: terraform-example-module
name: terraform-aws-code-deploy

# Logo for this project
#logo: docs/logo.png

# License of this project
license: "APACHE2"
license: APACHE2

# Copyrights
copyrights:
- name: "Cloud Posse, LLC"
url: "https://cloudposse.com"
year: "2020"
- name: Cloud Posse, LLC
url: https://cloudposse.com
year: '2020'

# Canonical GitHub repo
github_repo: cloudposse/terraform-example-module
github_repo: cloudposse/terraform-aws-code-deploy

# Badges to display
badges:
- name: "Latest Release"
image: "https://img.shields.io/github/release/cloudposse/terraform-example-module.svg"
url: "https://github.com/cloudposse/terraform-example-module/releases/latest"
- name: "Slack Community"
image: "https://slack.cloudposse.com/badge.svg"
url: "https://slack.cloudposse.com"
- name: "Discourse Forum"
image: "https://img.shields.io/discourse/https/ask.sweetops.com/posts.svg"
url: "https://ask.sweetops.com/"
- name: Latest Release
image: https://img.shields.io/github/release/cloudposse/terraform-aws-code-deploy.svg
url: https://github.com/cloudposse/terraform-aws-code-deploy/releases/latest
- name: Slack Community
image: https://slack.cloudposse.com/badge.svg
url: https://slack.cloudposse.com
- name: Discourse Forum
image: https://img.shields.io/discourse/https/ask.sweetops.com/posts.svg
url: https://ask.sweetops.com/

# List any related terraform modules that this module may be used with or that this module depends on.
related:
- name: "terraform-null-label"
description: "Terraform module designed to generate consistent names and tags for resources. Use terraform-null-label to implement a strict naming convention."
url: "https://github.com/cloudposse/terraform-null-label"

# List any resources helpful for someone to get started. For example, link to the hashicorp documentation or AWS documentation.
- name: terraform-aws-sns-topic
description: Terraform Module to Provide an Amazon Simple Notification Service (SNS)
url: https://github.com/cloudposse/terraform-aws-sns-topic
- name: terraform-null-label
description: Terraform Module to define a consistent naming convention by (namespace,
stage, name, [attributes])
url: https://github.com/cloudposse/terraform-null-label
- name: terraform-aws-codebuild
description: Terraform Module to easily leverage AWS CodeBuild for Continuous Integration
url: https://github.com/cloudposse/terraform-aws-codebuild
- name: terraform-aws-codepipeline-codedeploy
description: Terraform module that generates an AWS Codepipeline, and deploys via
CodeDeploy
url: https://github.com/cloudposse/terraform-aws-codepipeline-codedeploy
- name: terraform-aws-codefresh-backing-services
description: Terraform module to provision AWS backing services necessary to run
Codefresh Enterprise
url: https://github.com/cloudposse/terraform-aws-codefresh-backing-services
- name: terraform-aws-code-deploy
description:
url: https://github.com/cloudposse/terraform-aws-code-deploy
references:
- name: "Terraform Standard Module Structure"
description: "HashiCorp's standard module structure is a file and directory layout we recommend for reusable modules distributed in separate repositories."
url: "https://www.terraform.io/docs/modules/index.html#standard-module-structure"
- name: "Terraform Module Requirements"
description: "HashiCorp's guidance on all the requirements for publishing a module. Meeting the requirements for publishing a module is extremely easy."
url: "https://www.terraform.io/docs/registry/modules/publish.html#requirements"
- name: "Terraform `random_integer` Resource"
description: "The resource random_integer generates random values from a given range, described by the min and max attributes of a given resource."
url: "https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/integer"
- name: "Terraform Version Pinning"
description: "The required_version setting can be used to constrain which versions of the Terraform CLI can be used with your configuration"
url: "https://www.terraform.io/docs/configuration/terraform.html#specifying-a-required-terraform-version"

# Short description of this project
- name: terraform-provider-aws
description: Terraform AWS provider
url: https://registry.terraform.io/providers/hashicorp/aws/latest
- name: terraform-provider-local
description: Terraform local provider – Used to manage local resources, such as
creating files.
url: https://registry.terraform.io/providers/hashicorp/local/latest
description: |-
This is `terraform-example-module` project provides all the scaffolding for a typical well-built Cloud Posse module. It's a template repository you can
use when creating new repositories.
Terraform module to provision AWS Code Deploy app and group.
# Introduction to the project
#introduction: |-
Expand All @@ -67,32 +74,32 @@ description: |-
# How to use this module. Should be an easy example to copy and paste.
usage: |-
For a complete example, see [examples/complete](examples/complete).
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).
```hcl
module "example" {
source = "https://github.com/cloudposse/terraform-example-module.git?ref=master"
source = "https://github.com/cloudposse/terraform-aws-code-deploy.git?ref=master"
example = "Hello world!"
}
```
# Example usage
examples: |-
Here is an example of using this module:
- [`examples/complete`](https://github.com/cloudposse/terraform-example-module/) - complete example of using this module
- [`examples/complete`](https://github.com/cloudposse/terraform-aws-code-deploy/) - complete example of using this module
# How to get started quickly
#quickstart: |-
# Here's how to get started...

# Other files to include in this README from the project folder
include:
- "docs/targets.md"
- "docs/terraform.md"
- docs/targets.md
- docs/terraform.md

# Contributors to this project
contributors:
- name: "Erik Osterman"
github: "osterman"
- name: Vladimir Syromyatnikov
github: SweetOps
48 changes: 41 additions & 7 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,76 @@
| Name | Version |
|------|---------|
| terraform | >= 0.13 |
| aws | >= 2.0 |
| local | >= 1.2 |
| random | >= 2.2 |

## Providers

| Name | Version |
|------|---------|
| random | >= 2.2 |
| aws | >= 2.0 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| sns_topic | cloudposse/sns-topic/aws | 0.16.0 |
| this | cloudposse/label/null | 0.24.1 |

## Resources

| Name |
|------|
| [aws_codedeploy_app](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/codedeploy_app) |
| [aws_codedeploy_deployment_config](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/codedeploy_deployment_config) |
| [aws_codedeploy_deployment_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/codedeploy_deployment_group) |
| [aws_iam_policy_document](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) |
| [aws_iam_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) |
| [aws_iam_role_policy_attachment](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| additional\_tag\_map | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no |
| alarm\_configuration | Configuration of deployment to stop when a CloudWatch alarm detects that a metric has fallen below or exceeded a defined threshold.<br> alarms:<br> A list of alarms configured for the deployment group.<br> ignore\_poll\_alarm\_failure:<br> Indicates whether a deployment should continue if information about the current state of alarms cannot be retrieved from CloudWatch. | <pre>object({<br> alarms = list(string)<br> ignore_poll_alarm_failure = bool<br> })</pre> | `null` | no |
| attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no |
| auto\_rollback\_configuration\_events | The event type or types that trigger a rollback. Supported types are `DEPLOYMENT_FAILURE` and `DEPLOYMENT_STOP_ON_ALARM`. | `string` | `"DEPLOYMENT_FAILURE"` | no |
| autoscaling\_groups | A list of Autoscaling Groups associated with the deployment group. | `list(string)` | `[]` | no |
| blue\_green\_deployment\_config | Configuration block of the blue/green deployment options for a deployment group, <br>see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/codedeploy_deployment_group#blue_green_deployment_config | `any` | `null` | no |
| compute\_platform | The compute platform can either be `ECS`, `Lambda`, or `Server` | `string` | `"ECS"` | no |
| context | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {}<br>}</pre> | no |
| create\_default\_service\_role | Whether to create default IAM role ARN that allows deployments. | `bool` | `true` | no |
| create\_default\_sns\_topic | Whether to create default SNS topic through which notifications are sent. | `bool` | `true` | no |
| delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
| deployment\_style | Configuration of the type of deployment, either in-place or blue/green, <br>you want to run and whether to route deployment traffic behind a load balancer.<br><br>deployment\_option:<br> Indicates whether to route deployment traffic behind a load balancer. <br> Possible values: `WITH_TRAFFIC_CONTROL`, `WITHOUT_TRAFFIC_CONTROL`.<br>deployment\_type:<br> Indicates whether to run an in-place deployment or a blue/green deployment.<br> Possible values: `IN_PLACE`, `BLUE_GREEN`. | <pre>object({<br> deployment_option = string<br> deployment_type = string<br> })</pre> | `null` | no |
| ec2\_tag\_filter | A list of sets of tag filters. If multiple tag groups are specified, <br>any instance that matches to at least one tag filter of every tag group is selected.<br><br>key:<br> The key of the tag filter.<br>type:<br> The type of the tag filter, either `KEY_ONLY`, `VALUE_ONLY`, or `KEY_AND_VALUE`.<br>value:<br> The value of the tag filter. | <pre>list(object({<br> key = string<br> type = string<br> value = string<br> }))</pre> | `null` | no |
| ecs\_service | Configuration block(s) of the ECS services for a deployment group.<br><br>cluster\_name:<br> The name of the ECS cluster. <br>service\_name:<br> The name of the ECS service. | <pre>list(object({<br> cluster_name = string<br> service_name = string<br> }))</pre> | `null` | no |
| enabled | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
| environment | Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
| example | Example variable | `string` | `"hello world"` | no |
| id\_length\_limit | Limit `id` to this many characters (minimum 6).<br>Set to `0` for unlimited length.<br>Set to `null` for default, which is `0`.<br>Does not affect `id_full`. | `number` | `null` | no |
| label\_key\_case | The letter case of label keys (`tag` names) (i.e. `name`, `namespace`, `environment`, `stage`, `attributes`) to use in `tags`.<br>Possible values: `lower`, `title`, `upper`.<br>Default value: `title`. | `string` | `null` | no |
| label\_order | The naming order of the id output and Name tag.<br>Defaults to ["namespace", "environment", "stage", "name", "attributes"].<br>You can omit any of the 5 elements, but at least one must be present. | `list(string)` | `null` | no |
| label\_value\_case | The letter case of output label values (also used in `tags` and `id`).<br>Possible values: `lower`, `title`, `upper` and `none` (no transformation).<br>Default value: `lower`. | `string` | `null` | no |
| load\_balancer\_info | Single configuration block of the load balancer to use in a blue/green deployment, <br>see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/codedeploy_deployment_group#load_balancer_info | `map(any)` | `null` | no |
| minimum\_healthy\_hosts | type:<br> The type can either be `FLEET_PERCENT` or `HOST_COUNT`.<br>value:<br> The value when the type is `FLEET_PERCENT` represents the minimum number of healthy instances <br> as a percentage of the total number of instances in the deployment.<br> When the type is `HOST_COUNT`, the value represents the minimum number of healthy instances as an absolute value. | <pre>object({<br> type = string<br> value = number<br> })</pre> | `null` | no |
| name | Solution name, e.g. 'app' or 'jenkins' | `string` | `null` | no |
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | `string` | `null` | no |
| regex\_replace\_chars | Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.<br>If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
| service\_role\_arn | The service IAM role ARN that allows deployments. | `string` | `null` | no |
| sns\_topic\_arn | The ARN of the SNS topic through which notifications are sent. | `string` | `null` | no |
| stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
| tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | `map(string)` | `{}` | no |
| traffic\_routing\_config | type:<br> Type of traffic routing config. One of `TimeBasedCanary`, `TimeBasedLinear`, `AllAtOnce`.<br>interval:<br> The number of minutes between the first and second traffic shifts of a deployment.<br>percentage:<br> The percentage of traffic to shift in the first increment of a deployment. | <pre>object({<br> type = string<br> interval = number<br> percentage = number<br> })</pre> | `null` | no |
| trigger\_events | The event type or types for which notifications are triggered. <br>Some values that are supported: <br> `DeploymentStart`, `DeploymentSuccess`, `DeploymentFailure`, `DeploymentStop`, <br> `DeploymentRollback`, `InstanceStart`, `InstanceSuccess`, `InstanceFailure`. <br>See the CodeDeploy documentation for all possible values.<br>http://docs.aws.amazon.com/codedeploy/latest/userguide/monitoring-sns-event-notifications-create-trigger.html | `list(string)` | <pre>[<br> "DeploymentFailure"<br>]</pre> | no |

## Outputs

| Name | Description |
|------|-------------|
| example | Example output |
| id | ID of the created example |
| random | Stable random number for this example |

| deployment\_config\_id | The deployment config ID. |
| deployment\_config\_name | The deployment group's config name. |
| group\_id | The application group ID. |
| id | The application ID. |
| name | The application's name. |
<!-- markdownlint-restore -->
115 changes: 112 additions & 3 deletions examples/complete/fixtures.us-east-2.tfvars
Original file line number Diff line number Diff line change
@@ -1,10 +1,119 @@
region = "us-east-2"

namespace = "eg"
availability_zones = ["us-east-2a", "us-east-2b"]

environment = "ue2"
namespace = "cdp"

stage = "test"

name = "example"
name = "ecs-alb"

vpc_cidr_block = "172.16.0.0/16"

ecs_launch_type = "FARGATE"

network_mode = "awsvpc"

ignore_changes_task_definition = true

assign_public_ip = false

propagate_tags = "TASK_DEFINITION"

deployment_minimum_healthy_percent = 100

deployment_maximum_percent = 200

deployment_controller_type = "CODE_DEPLOY"

desired_count = 1

task_memory = 512

task_cpu = 256

container_name = "nginx"

container_image = "nginx:latest"

container_memory = 256

container_memory_reservation = 128

container_cpu = 256

container_essential = true

container_readonly_root_filesystem = false

container_environment = [
{
name = "string_var"
value = "I am a string"
},
{
name = "true_boolean_var"
value = true
},
{
name = "false_boolean_var"
value = false
},
{
name = "integer_var"
value = 42
}
]

container_port_mappings = [
{
containerPort = 80
hostPort = 80
protocol = "tcp"
},
{
containerPort = 443
hostPort = 443
protocol = "tcp"
}
]

internal = false

http_enabled = true

access_logs_enabled = false

alb_access_logs_s3_bucket_force_destroy = true

cross_zone_load_balancing_enabled = true

http2_enabled = true

idle_timeout = 60

ip_address_type = "ipv4"

deletion_protection_enabled = false

deregistration_delay = 15

health_check_path = "/"

health_check_port = "traffic-port"

health_check_timeout = 10

health_check_healthy_threshold = 2

health_check_unhealthy_threshold = 2

health_check_interval = 15

health_check_matcher = "200-399"

target_group_port = 80

target_group_target_type = "ip"

target_group_protocol = "HTTP"
Loading

0 comments on commit 38ecf6c

Please sign in to comment.