Skip to content

Commit

Permalink
Merge pull request #169 from trussworks/ee-cleanup
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
eeeady authored Dec 29, 2020
2 parents ec0b7e7 + f01dab7 commit 942fcba
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 37 deletions.
17 changes: 9 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
references:
circleci_docker: &circleci_docker trussworks/circleci:efb1042e31538677779971798e0912390f699e72
jobs:
terratest:
docker:
- auth:
password: $DOCKER_PASSWORD
username: $DOCKER_USERNAME
image: trussworks/circleci:29ab89fdada1f85c5d8fb685a2c71660f0c5f60c
image: *circleci_docker
steps:
- checkout
- restore_cache:
keys:
- pre-commit-dot-cache-{{ checksum ".pre-commit-config.yaml" }}
- go-mod-sources-v1-{{ checksum "go.sum" }}
- run:
command: "temp_role=$(aws sts assume-role \\\n --role-arn arn:aws:iam::313564602749:role/circleci\
\ \\\n --role-session-name circleci)\nexport AWS_ACCESS_KEY_ID=$(echo\
\ $temp_role | jq .Credentials.AccessKeyId | xargs)\nexport AWS_SECRET_ACCESS_KEY=$(echo\
\ $temp_role | jq .Credentials.SecretAccessKey | xargs)\nexport AWS_SESSION_TOKEN=$(echo\
\ $temp_role | jq .Credentials.SessionToken | xargs)\nmake test\n"
command: |
temp_role=$(aws sts assume-role --role-arn arn:aws:iam::313564602749:role/circleci --role-session-name circleci)
export AWS_ACCESS_KEY_ID=$(echo $temp_role | jq .Credentials.AccessKeyId | xargs)
export AWS_SECRET_ACCESS_KEY=$(echo $temp_role | jq .Credentials.SecretAccessKey | xargs)
export AWS_SESSION_TOKEN=$(echo $temp_role | jq .Credentials.SessionToken | xargs)
make test
name: Assume role, run pre-commit and run terratest
- save_cache:
key: pre-commit-dot-cache-{{ checksum ".pre-commit-config.yaml" }}
Expand All @@ -26,8 +29,6 @@ jobs:
key: go-mod-sources-v1-{{ checksum "go.sum" }}
paths:
- ~/go/pkg/mod
references:
circleci: trussworks/circleci:29ab89fdada1f85c5d8fb685a2c71660f0c5f60c
version: 2.1
workflows:
validate:
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v3.3.0
rev: v3.4.0
hooks:
- id: check-json
- id: check-merge-conflict
Expand All @@ -12,7 +12,7 @@ repos:
- id: trailing-whitespace

- repo: git://github.com/igorshubovych/markdownlint-cli
rev: v0.25.0
rev: v0.26.0
hooks:
- id: markdownlint

Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ Terraform 0.13. Pin module version to ~> 4.0. Submit pull-requests to master bra

Terraform 0.12. Pin module version to ~> 3.0. Submit pull-requests to terraform012 branch.

Terraform 0.11. Pin module version to ~> 1.14. Submit pull-requests to terraform011 branch.

## Usage

### ECS service associated with an Application Load Balancer (ALB)
Expand Down Expand Up @@ -107,14 +105,14 @@ module "app_ecs_service" {

| Name | Version |
|------|---------|
| terraform | ~> 0.13 |
| aws | >= 2.70, < 4.0 |
| terraform | >= 0.13 |
| aws | >= 3.0 |

## Providers

| Name | Version |
|------|---------|
| aws | >= 2.70, < 4.0 |
| aws | >= 3.0 |

## Inputs

Expand Down
2 changes: 1 addition & 1 deletion examples/load-balancer/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ locals {

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 2.50.0"
version = "~> 2.64.0"

name = var.test_name
cidr = "10.0.0.0/16"
Expand Down
6 changes: 3 additions & 3 deletions examples/load-balancer/versions.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
terraform {
required_version = "~> 0.13"
required_version = ">= 0.13"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 2.70, < 4.0"
version = ">= 2.70"
}
}
}
}
2 changes: 1 addition & 1 deletion examples/no-load-balancer/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ locals {

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 2.50.0"
version = "~> 2.64.0"

name = var.test_name
cidr = "10.0.0.0/16"
Expand Down
6 changes: 3 additions & 3 deletions examples/no-load-balancer/versions.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
terraform {
required_version = "~> 0.13"
required_version = ">= 0.13"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 2.70, < 4.0"
version = ">= 2.70"
}
}
}
}
24 changes: 12 additions & 12 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
locals {
awslogs_group = "${var.logs_cloudwatch_group == "" ? "/ecs/${var.environment}/${var.name}" : var.logs_cloudwatch_group}"
target_container_name = "${var.target_container_name == "" ? "${var.name}-${var.environment}" : var.target_container_name}"
cloudwatch_alarm_name = "${var.cloudwatch_alarm_name == "" ? "${var.name}-${var.environment}" : var.cloudwatch_alarm_name}"
awslogs_group = var.logs_cloudwatch_group == "" ? "/ecs/${var.environment}/${var.name}" : var.logs_cloudwatch_group
target_container_name = var.target_container_name == "" ? "${var.name}-${var.environment}" : var.target_container_name
cloudwatch_alarm_name = var.cloudwatch_alarm_name == "" ? "${var.name}-${var.environment}" : var.cloudwatch_alarm_name

# for each target group, allow ingress from the alb to ecs container port
lb_ingress_container_ports = distinct(
Expand Down Expand Up @@ -143,7 +143,7 @@ resource "aws_cloudwatch_metric_alarm" "alarm_mem" {
}

resource "aws_cloudwatch_metric_alarm" "alarm_cpu_no_lb" {
count = var.cloudwatch_alarm_cpu_enable && ! (var.associate_alb || var.associate_nlb) ? 1 : 0
count = var.cloudwatch_alarm_cpu_enable && !(var.associate_alb || var.associate_nlb) ? 1 : 0

alarm_name = "${local.cloudwatch_alarm_name}-cpu"
alarm_description = "Monitors ECS CPU Utilization when no load balancer is attached"
Expand All @@ -164,7 +164,7 @@ resource "aws_cloudwatch_metric_alarm" "alarm_cpu_no_lb" {
}

resource "aws_cloudwatch_metric_alarm" "alarm_mem_no_lb" {
count = var.cloudwatch_alarm_mem_enable && ! (var.associate_alb || var.associate_nlb) ? 1 : 0
count = var.cloudwatch_alarm_mem_enable && !(var.associate_alb || var.associate_nlb) ? 1 : 0

alarm_name = "${local.cloudwatch_alarm_name}-mem"
alarm_description = "Monitors ECS memory Utilization when no load balancer is attached"
Expand Down Expand Up @@ -496,7 +496,7 @@ resource "aws_ecs_service" "main" {
deployment_minimum_healthy_percent = var.tasks_minimum_healthy_percent
deployment_maximum_percent = var.tasks_maximum_percent

dynamic ordered_placement_strategy {
dynamic "ordered_placement_strategy" {
for_each = local.ecs_service_ordered_placement_strategy[local.ecs_service_launch_type]

content {
Expand All @@ -505,7 +505,7 @@ resource "aws_ecs_service" "main" {
}
}

dynamic placement_constraints {
dynamic "placement_constraints" {
for_each = local.ecs_service_placement_constraints[local.ecs_service_launch_type]

content {
Expand All @@ -519,7 +519,7 @@ resource "aws_ecs_service" "main" {
assign_public_ip = var.assign_public_ip
}

dynamic load_balancer {
dynamic "load_balancer" {
for_each = var.lb_target_groups
content {
container_name = local.target_container_name
Expand All @@ -528,7 +528,7 @@ resource "aws_ecs_service" "main" {
}
}

dynamic service_registries {
dynamic "service_registries" {
for_each = var.service_registries
content {
registry_arn = service_registries.value.registry_arn
Expand Down Expand Up @@ -565,7 +565,7 @@ resource "aws_ecs_service" "main_no_lb" {
deployment_minimum_healthy_percent = var.tasks_minimum_healthy_percent
deployment_maximum_percent = var.tasks_maximum_percent

dynamic ordered_placement_strategy {
dynamic "ordered_placement_strategy" {
for_each = local.ecs_service_ordered_placement_strategy[local.ecs_service_launch_type]
# for_each = var.ecs_use_fargate ? [] : ["attribute:ecs.availability-zone", "instanceId"]

Expand All @@ -575,7 +575,7 @@ resource "aws_ecs_service" "main_no_lb" {
}
}

dynamic placement_constraints {
dynamic "placement_constraints" {
for_each = local.ecs_service_placement_constraints[local.ecs_service_launch_type]
# for_each = var.ecs_use_fargate ? [] : ["distinctInstance"]

Expand All @@ -590,7 +590,7 @@ resource "aws_ecs_service" "main_no_lb" {
assign_public_ip = var.assign_public_ip
}

dynamic service_registries {
dynamic "service_registries" {
for_each = var.service_registries
content {
registry_arn = service_registries.value.registry_arn
Expand Down
4 changes: 2 additions & 2 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
terraform {
required_version = "~> 0.13"
required_version = ">= 0.13"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 2.70, < 4.0"
version = ">= 3.0"
}
}
}

0 comments on commit 942fcba

Please sign in to comment.