From 91ab04ff79c468b40c0bdaa0eae631538e9137f3 Mon Sep 17 00:00:00 2001 From: Ilia Lazebnik Date: Mon, 29 Jun 2020 14:28:20 +0300 Subject: [PATCH] feat: Add container insights (#10) --- .pre-commit-config.yaml | 4 ++-- README.md | 23 ++++++++++++++----- examples/complete-ecs/README.md | 18 +++++++++++++++ examples/complete-ecs/main.tf | 5 ++-- .../complete-ecs/service-hello-world/main.tf | 6 ++--- main.tf | 6 +++++ modules/ecs-instance-profile/main.tf | 4 ++-- variables.tf | 6 +++++ 8 files changed, 57 insertions(+), 15 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0285452..2308d6f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/README.md b/README.md index cde67a4..4e2659a 100644 --- a/README.md +++ b/README.md @@ -45,20 +45,31 @@ module "ecs" { * [Complete ECS](https://github.com/terraform-aws-modules/terraform-aws-ecs/tree/master/examples/complete-ecs) +## 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 | `` | 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 | diff --git a/examples/complete-ecs/README.md b/examples/complete-ecs/README.md index 21f4b9a..dd7b009 100644 --- a/examples/complete-ecs/README.md +++ b/examples/complete-ecs/README.md @@ -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. +## Requirements + +No requirements. + +## Providers + +| Name | Version | +|------|---------| +| aws | n/a | +| template | n/a | + +## Inputs + +No input. + +## Outputs + +No output. diff --git a/examples/complete-ecs/main.tf b/examples/complete-ecs/main.tf index b03e7c5..578adcf 100644 --- a/examples/complete-ecs/main.tf +++ b/examples/complete-ecs/main.tf @@ -32,8 +32,9 @@ module "vpc" { #----- ECS -------- module "ecs" { - source = "../../" - name = local.name + source = "../../" + name = local.name + container_insights = true } module "ec2-profile" { diff --git a/examples/complete-ecs/service-hello-world/main.tf b/examples/complete-ecs/service-hello-world/main.tf index ea88a85..91a2953 100644 --- a/examples/complete-ecs/service-hello-world/main.tf +++ b/examples/complete-ecs/service-hello-world/main.tf @@ -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 } diff --git a/main.tf b/main.tf index 314f1bb..2143b08 100644 --- a/main.tf +++ b/main.tf @@ -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 } diff --git a/modules/ecs-instance-profile/main.tf b/modules/ecs-instance-profile/main.tf index 031d666..45f8940 100644 --- a/modules/ecs-instance-profile/main.tf +++ b/modules/ecs-instance-profile/main.tf @@ -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" } diff --git a/variables.tf b/variables.tf index f975ae3..ac7c658 100644 --- a/variables.tf +++ b/variables.tf @@ -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 +}