Skip to content

Commit 91ab04f

Browse files
authored
feat: Add container insights (#10)
1 parent b00f349 commit 91ab04f

File tree

8 files changed

+57
-15
lines changed

8 files changed

+57
-15
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
repos:
22
- repo: git://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.27.0
3+
rev: v1.31.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_docs
77
- repo: git://github.com/pre-commit/pre-commit-hooks
8-
rev: v2.5.0
8+
rev: v3.1.0
99
hooks:
1010
- id: check-merge-conflict

README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,31 @@ module "ecs" {
4545
* [Complete ECS](https://github.com/terraform-aws-modules/terraform-aws-ecs/tree/master/examples/complete-ecs)
4646

4747
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
48+
## Requirements
49+
50+
No requirements.
51+
52+
## Providers
53+
54+
| Name | Version |
55+
|------|---------|
56+
| aws | n/a |
57+
4858
## Inputs
4959

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

5667
## Outputs
5768

5869
| Name | Description |
5970
|------|-------------|
60-
| this\_ecs\_cluster\_arn | |
61-
| this\_ecs\_cluster\_id | |
71+
| this\_ecs\_cluster\_arn | n/a |
72+
| this\_ecs\_cluster\_id | n/a |
6273
| this\_ecs\_cluster\_name | The name of the ECS cluster |
6374

6475
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/complete-ecs/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,23 @@ Note that this example may create resources which can cost money (AWS EC2 instan
3939
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.
4040

4141
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
42+
## Requirements
43+
44+
No requirements.
45+
46+
## Providers
47+
48+
| Name | Version |
49+
|------|---------|
50+
| aws | n/a |
51+
| template | n/a |
52+
53+
## Inputs
54+
55+
No input.
56+
57+
## Outputs
58+
59+
No output.
4260

4361
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/complete-ecs/main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ module "vpc" {
3232

3333
#----- ECS --------
3434
module "ecs" {
35-
source = "../../"
36-
name = local.name
35+
source = "../../"
36+
name = local.name
37+
container_insights = true
3738
}
3839

3940
module "ec2-profile" {

examples/complete-ecs/service-hello-world/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ EOF
2727
}
2828

2929
resource "aws_ecs_service" "hello_world" {
30-
name = "hello_world"
31-
cluster = var.cluster_id
30+
name = "hello_world"
31+
cluster = var.cluster_id
3232
task_definition = aws_ecs_task_definition.hello_world.arn
3333

3434
desired_count = 1
3535

36-
deployment_maximum_percent = 100
36+
deployment_maximum_percent = 100
3737
deployment_minimum_healthy_percent = 0
3838
}

main.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,11 @@ resource "aws_ecs_cluster" "this" {
22
count = var.create_ecs ? 1 : 0
33

44
name = var.name
5+
6+
setting {
7+
name = "containerInsights"
8+
value = var.container_insights ? "enabled" : "disabled"
9+
}
10+
511
tags = var.tags
612
}

modules/ecs-instance-profile/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ resource "aws_iam_instance_profile" "this" {
2424
}
2525

2626
resource "aws_iam_role_policy_attachment" "ecs_ec2_role" {
27-
role = aws_iam_role.this.id
27+
role = aws_iam_role.this.id
2828
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"
2929
}
3030

3131
resource "aws_iam_role_policy_attachment" "ecs_ec2_cloudwatch_role" {
32-
role = aws_iam_role.this.id
32+
role = aws_iam_role.this.id
3333
policy_arn = "arn:aws:iam::aws:policy/CloudWatchLogsFullAccess"
3434
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ variable "tags" {
1414
type = map(string)
1515
default = {}
1616
}
17+
18+
variable "container_insights" {
19+
description = "Controls if ECS Cluster has container insights enabled"
20+
type = bool
21+
default = false
22+
}

0 commit comments

Comments
 (0)