Skip to content

Commit

Permalink
Fix deprecation warnings for tags
Browse files Browse the repository at this point in the history
  • Loading branch information
qbart committed Mar 11, 2022
1 parent f8f43d0 commit 2b77004
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 224 deletions.
9 changes: 1 addition & 8 deletions DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,9 @@ go get github.com/terraform-docs/terraform-docs

Generate documentation:
```
mkdir -p tmp/
terraform-docs markdown modules/ecs-service/ > tmp/ecs-service.md
terraform-docs markdown modules/ecs-background-job/ > tmp/ecs-background-job.md
terraform-docs markdown modules/ecs-cluster/ > tmp/ecs-cluster.md
terraform-docs markdown modules/load-balancer/ > tmp/load-balancer.md
./generate-docs.sh
```

then copy the output to appropriate README(s).

## Releasing

Make sure to update changelog.
Expand Down
110 changes: 110 additions & 0 deletions examples/basic-ecs-setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,113 @@ or module specific documentation:
* [ECS service](https://registry.terraform.io/modules/Selleo/backend/aws/latest/submodules/ecs-service)
* [Load balancer](https://registry.terraform.io/modules/Selleo/backend/aws/latest/submodules/load-balancer)


### ecs-service

Cluster:

```tf
module "ecs_cluster" {
source = "Selleo/backend/aws//modules/ecs-cluster"
version = "0.6.1"
name_prefix = "my-cluster"
region = "eu-central-1"
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.public_subnets
instance_type = "t3.small"
security_groups = []
loadbalancer_sg_id = module.lb.loadbalancer_sg_id
autoscaling_group = {
min_size = 1
max_size = 2
desired_capacity = 1
}
}
```

Optional cloudinit config:

```tf
module "ecs_cluster" {
# ...
cloudinit_parts = [
{
filename = "hello.sh"
content_type = "text/x-shellscript"
content = <<SH
#!/usr/bin/env bash
echo "Hello World" > /home/ec2-user/hello
SH
}
]
# ...
}
```

### load-balancer

```tf
module "load_balancer" {
source = "Selleo/backend/aws//modules/load-balancer"
version = "0.6.1"
name = "ecs-lb"
vpc_id = module.vpc.vpc_id # "vpc-1234"
subnet_ids = module.vpc.public_subnets # ["10.0.101.0/24", "10.0.102.0/24"]
}
```

### ecs-service

```tf
module "ecs_service" {
source = "Selleo/backend/aws//modules/ecs-service"
version = "0.6.1"
name = "rails-api"
vpc_id = module.vpc.vpc_id
ecs_cluster_id = module.ecs_cluster.ecs_cluster_id
desired_count = 1
instance_role = module.ecs_cluster.instance_role
container_definition = {
cpu_units = 256
mem_units = 512
command = ["bundle", "exec", "ruby", "main.rb"],
image = "qbart/hello-ruby-sinatra:latest",
container_port = 4567
envs = {
"APP_ENV" = "production"
}
}
}
```

### ecs-background-job


```tf
module "ecs_background_job" {
source = "Selleo/backend/aws//modules/ecs-background-job"
version = "0.6.1"
name = "shoryuken"
ecs_cluster_id = module.ecs_cluster.ecs_cluster_id
desired_count = 1
instance_role = module.ecs_cluster.instance_role
container_definition = {
cpu_units = 256
mem_units = 512
command = ["bundle", "exec", "shoryuken", "-C", "config/shoryuken.yml", "-R"]
image = "${aws_ecr_repository.your_repo.repository_url}:latest"
envs = {
MY_ENV = "sth"
}
}
}
```
7 changes: 7 additions & 0 deletions generate-docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
set -e

terraform-docs markdown modules/ecs-service/ > modules/ecs-service/README.md
terraform-docs markdown modules/ecs-background-job/ > modules/ecs-background-job/README.md
terraform-docs markdown modules/ecs-cluster/ > modules/ecs-cluster/README.md
terraform-docs markdown modules/load-balancer/ > modules/load-balancer/README.md
56 changes: 0 additions & 56 deletions modules/ecs-background-job/README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,3 @@
# ECS background job

This folder contains a Terraform module to create an ECS background job.

## Usage

Define background job:

```tf
module "ecs_background_job" {
source = "Selleo/backend/aws//modules/ecs-background-job"
version = "0.6.0"
name = "shoryuken"
ecs_cluster_id = module.ecs_cluster.ecs_cluster_id
desired_count = 1
instance_role = module.ecs_cluster.instance_role
container_definition = {
cpu_units = 256
mem_units = 512
command = ["bundle", "exec", "shoryuken", "-C", "config/shoryuken.yml", "-R"]
image = "${aws_ecr_repository.your_repo.repository_url}:latest"
envs = {
MY_ENV = "sth"
}
}
}
```

ECS background job module requires ECS cluster to be set up.
It is recommended to use [ecs-cluster](https://registry.terraform.io/modules/Selleo/backend/aws/latest/submodules/ecs-cluster) module.

For more details and options see source files.

## What's included in this module?

### Cloudwatch log group

Module creates a log group that is used by ECS background job task.

### ECS background job with task definition

Module configures ECS background job with task that runs docker image.

Currently placement strategy is configured as follows:

1. spread / AZS
2. spread / instance
3. binpack / memory
4. binpack / cpu

### IAM

Module defines a policy for instance role for logging.

## Requirements

| Name | Version |
Expand Down
72 changes: 0 additions & 72 deletions modules/ecs-cluster/README.md
Original file line number Diff line number Diff line change
@@ -1,75 +1,3 @@
# ECS cluster

This folder contains a Terraform module to create an ECS cluster with Autoscaling Group.

## Usage

Define cluster:

```tf
module "ecs_cluster" {
source = "Selleo/backend/aws//modules/ecs-cluster"
version = "0.6.0"
name_prefix = "my-cluster"
region = "eu-central-1"
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.public_subnets
instance_type = "t3.small"
security_groups = []
loadbalancer_sg_id = module.lb.loadbalancer_sg_id
autoscaling_group = {
min_size = 1
max_size = 2
desired_capacity = 1
}
}
```

Optional cloudinit config:
```tf
module "ecs_cluster" {
# ...
cloudinit_parts = [
{
filename = "hello.sh"
content_type = "text/x-shellscript"
content = <<SH
#!/usr/bin/env bash
echo "Hello World" > /home/ec2-user/hello
SH
}
]
# ...
}
```

ECS cluster module requires VPC and subnets already set up as well load balancer with security group.
It is recommended to use [load-balancer](https://registry.terraform.io/modules/Selleo/backend/aws/latest/submodules/load-balancer) module.

For more details and options see source files.

## What's included in this module?

By default all resources names contain random prefix.

### ECS cluster with AWS autoscaling group

Module defines AWS Autoscaling Group with launch configuration template that configures ECS cluster.
Placement strategy is set to spread and termination policy is `OldestInstance`.
By default the latest ECS-optimized AMI for a given region is used unless specified otherwise.

### Security group

Instance security group allows ingress traffic on ephemeral port range.

### IAM

Module defines permissions for EC2 instance that allows managing application lifecycle on ECS.

## Requirements

| Name | Version |
Expand Down
17 changes: 12 additions & 5 deletions modules/ecs-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,20 @@ resource "aws_autoscaling_group" "portal_autoscaling_group" {
health_check_grace_period = 15
health_check_type = "EC2"

tags = [
for k, v in merge({Name: random_id.prefix.hex}, var.tags) : {
key = k
value = v
tag {
key = "Name"
value = random_id.prefix.hex
propagate_at_launch = true
}

dynamic "tag" {
for_each = var.tags
content {
key = tag.key
value = tag.value
propagate_at_launch = true
}
]
}

force_delete = false

Expand Down
61 changes: 0 additions & 61 deletions modules/ecs-service/README.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,3 @@
# ECS service

This folder contains a Terraform module to create an ECS service.

## Usage

Define service:

```tf
module "ecs_service" {
source = "Selleo/backend/aws//modules/ecs-service"
version = "0.6.0"
name = "rails-api"
vpc_id = module.vpc.vpc_id
ecs_cluster_id = module.ecs_cluster.ecs_cluster_id
desired_count = 1
instance_role = module.ecs_cluster.instance_role
container_definition = {
cpu_units = 256
mem_units = 512
command = ["bundle", "exec", "ruby", "main.rb"],
image = "qbart/hello-ruby-sinatra:latest",
container_port = 4567
envs = {
"APP_ENV" = "production"
}
}
}
```

ECS service module requires ECS cluster to be set up.
It is recommended to use [ecs-cluster](https://registry.terraform.io/modules/Selleo/backend/aws/latest/submodules/ecs-cluster) module.

For more details and options see source files.

## What's included in this module?

### Cloudwatch log group

Module creates a log group that is used by ECS service task.

### ECS service with task definition

Module configures ECS service with task that runs docker image.
Task is connected to load balancer using target group with default HTTP healthcheck at `/`.
Task definition uses dynamic port mapping - you define container port and AWS will assign host port from ephemeral range.

Currently placement strategy is configured as follows:

1. spread / AZS
2. spread / instance
3. binpack / cpu
4. binpack / memory

### IAM

Module defines permissions that allow ECS service to be used with Load Balancer.
Additionally it creates a policy for instance role for logging.

## Requirements

| Name | Version |
Expand Down
22 changes: 0 additions & 22 deletions modules/load-balancer/README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
# Load balancer

This folder contains a Terraform module to create an application load balancer with default security group configuration allowing web traffic.
In order to use this module you need to have networking set up - you can use official [Hashicorp AWS VPC module](https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws/latest) to do that.

## Usage

Define application load balancer:

```tf
module "load_balancer" {
source = "Selleo/backend/aws//modules/load-balancer"
version = "0.6.0"
name = "ecs-lb"
vpc_id = module.vpc.vpc_id # "vpc-1234"
subnet_ids = module.vpc.public_subnets # ["10.0.101.0/24", "10.0.102.0/24"]
}
```

For more details and options see source files.

## Requirements

| Name | Version |
Expand Down

0 comments on commit 2b77004

Please sign in to comment.