Skip to content

Commit

Permalink
feat: Add container insights (terraform-aws-modules#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
DrFaust92 authored Jun 29, 2020
1 parent b00f349 commit 91ab04f
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
repos:
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.27.0
rev: v1.31.0
hooks:
- id: terraform_fmt
- id: terraform_docs
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
rev: v3.1.0
hooks:
- id: check-merge-conflict
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,31 @@ module "ecs" {
* [Complete ECS](https://github.com/terraform-aws-modules/terraform-aws-ecs/tree/master/examples/complete-ecs)

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

No requirements.

## Providers

| Name | Version |
|------|---------|
| aws | n/a |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| create\_ecs | Controls if ECS should be created | string | `"true"` | no |
| name | Name to be used on all the resources as identifier, also the name of the ECS cluster | string | n/a | yes |
| tags | A map of tags to add to ECS Cluster | map | `<map>` | no |
|------|-------------|------|---------|:--------:|
| container\_insights | Controls if ECS Cluster has container insights enabled | `bool` | `false` | no |
| create\_ecs | Controls if ECS should be created | `bool` | `true` | no |
| name | Name to be used on all the resources as identifier, also the name of the ECS cluster | `string` | n/a | yes |
| tags | A map of tags to add to ECS Cluster | `map(string)` | `{}` | no |

## Outputs

| Name | Description |
|------|-------------|
| this\_ecs\_cluster\_arn | |
| this\_ecs\_cluster\_id | |
| this\_ecs\_cluster\_arn | n/a |
| this\_ecs\_cluster\_id | n/a |
| this\_ecs\_cluster\_name | The name of the ECS cluster |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Expand Down
18 changes: 18 additions & 0 deletions examples/complete-ecs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,23 @@ Note that this example may create resources which can cost money (AWS EC2 instan
Current version creates an high-available VPC with instances that are attached to ECS. ECS tasks can be run on these instances but they are not exposed to anything.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

No requirements.

## Providers

| Name | Version |
|------|---------|
| aws | n/a |
| template | n/a |

## Inputs

No input.

## Outputs

No output.

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
5 changes: 3 additions & 2 deletions examples/complete-ecs/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ module "vpc" {

#----- ECS --------
module "ecs" {
source = "../../"
name = local.name
source = "../../"
name = local.name
container_insights = true
}

module "ec2-profile" {
Expand Down
6 changes: 3 additions & 3 deletions examples/complete-ecs/service-hello-world/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ EOF
}

resource "aws_ecs_service" "hello_world" {
name = "hello_world"
cluster = var.cluster_id
name = "hello_world"
cluster = var.cluster_id
task_definition = aws_ecs_task_definition.hello_world.arn

desired_count = 1

deployment_maximum_percent = 100
deployment_maximum_percent = 100
deployment_minimum_healthy_percent = 0
}
6 changes: 6 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@ resource "aws_ecs_cluster" "this" {
count = var.create_ecs ? 1 : 0

name = var.name

setting {
name = "containerInsights"
value = var.container_insights ? "enabled" : "disabled"
}

tags = var.tags
}
4 changes: 2 additions & 2 deletions modules/ecs-instance-profile/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ resource "aws_iam_instance_profile" "this" {
}

resource "aws_iam_role_policy_attachment" "ecs_ec2_role" {
role = aws_iam_role.this.id
role = aws_iam_role.this.id
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"
}

resource "aws_iam_role_policy_attachment" "ecs_ec2_cloudwatch_role" {
role = aws_iam_role.this.id
role = aws_iam_role.this.id
policy_arn = "arn:aws:iam::aws:policy/CloudWatchLogsFullAccess"
}
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ variable "tags" {
type = map(string)
default = {}
}

variable "container_insights" {
description = "Controls if ECS Cluster has container insights enabled"
type = bool
default = false
}

0 comments on commit 91ab04f

Please sign in to comment.