Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #6 from trussworks/barry-012
Browse files Browse the repository at this point in the history
0.12'ify module
  • Loading branch information
esacteksab authored Jan 6, 2020
2 parents e59c365 + cf141ea commit 9af911e
Show file tree
Hide file tree
Showing 17 changed files with 469 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
validate:
docker:
- image: trussworks/circleci-docker-primary:a18ba9987556eec2e48354848a3c9fb4d5b69ac8
- image: trussworks/circleci-docker-primary:tf12-4c1fd54273446484259597ae3da9deb2806498ed
steps:
- checkout
- restore_cache:
Expand Down
12 changes: 12 additions & 0 deletions .dependabot/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 1
update_configs:
# Keep go modules up to date, batching pull requests weekly
- package_manager: "go:modules"
directory: "/"
update_schedule: "weekly"
# Apply default reviewer @trussworks/waddlers group to PRs
default_reviewers:
- "trussworks/waddlers"
# Apply dependencies label to PRs
default_labels:
- "dependencies"
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
.terraform
terraform.tfstate
terraform.tfstate.backup
terraform.tfstate.*.backup
6 changes: 6 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
linters:
enable:
- gosec
- golint
- gofmt
- goimports
12 changes: 8 additions & 4 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: v2.2.3
rev: v2.4.0
hooks:
- id: check-json
- id: check-merge-conflict
Expand All @@ -12,13 +12,17 @@ repos:
- id: trailing-whitespace

- repo: git://github.com/igorshubovych/markdownlint-cli
rev: v0.17.0
rev: v0.19.0
hooks:
- id: markdownlint

- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.12.0
rev: v1.21.0
hooks:
- id: terraform_docs
- id: terraform_fmt
- id: terraform_validate_no_variables

- repo: git://github.com/golangci/golangci-lint
rev: v1.21.0
hooks:
- id: golangci-lint
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.PHONY: ensure_pre_commit
ensure_pre_commit: .git/hooks/pre-commit ## Ensure pre-commit is installed
.git/hooks/pre-commit: /usr/local/bin/pre-commit
pre-commit install
pre-commit install-hooks

.PHONY: pre_commit_tests
pre_commit_tests: ensure_pre_commit ## Run pre-commit tests
pre-commit run --all-files

.PHONY: test
test: pre_commit_tests
go test -count 1 -v -timeout 90m ./test/...

.PHONY: clean
clean:
rm -f .*.stamp
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Creates an ECS cluster backed by an AutoScaling Group.

The cluster is minimally configured and expects any ECS service added will
Expand Down Expand Up @@ -39,6 +38,14 @@ module "app_ecs_cluster" {
}
```

## Terraform Versions

Terraform 0.12. Pin module version to ~> 2.0. Submit pull-requests to master branch.

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


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

| Name | Description | Type | Default | Required |
Expand All @@ -50,7 +57,7 @@ module "app_ecs_cluster" {
| max\_size | Maxmimum instance count. | string | `"2"` | no |
| min\_size | Minimum instance count. | string | `"2"` | no |
| name | The ECS cluster name this will launching instances for. | string | n/a | yes |
| subnet\_ids | A list of subnet IDs to launch resources in. | list | n/a | yes |
| subnet\_ids | A list of subnet IDs to launch resources in. | list(string) | n/a | yes |
| use\_AmazonEC2ContainerServiceforEC2Role\_policy | Attaches the AWS managed AmazonEC2ContainerServiceforEC2Role policy to the ECS instance role. | string | `"true"` | no |
| vpc\_id | The id of the VPC to launch resources in. | string | n/a | yes |

Expand All @@ -63,3 +70,29 @@ module "app_ecs_cluster" {
| ecs\_instance\_role | The name of the ECS instance role. |

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


## Developer Setup

Install dependencies (macOS)

```shell
brew install pre-commit go terraform terraform-docs
pre-commit install --install-hooks
```

### Testing

[Terratest](https://github.com/gruntwork-io/terratest) is being used for
automated testing with this module. Tests in the `test` folder can be run
locally by running the following command:

```text
make test
```

Or with aws-vault:

```text
AWS_VAULT_KEYCHAIN_NAME=<NAME> aws-vault exec <PROFILE> -- make test
```
39 changes: 39 additions & 0 deletions examples/simple/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
data "aws_ami" "ecs_ami" {
most_recent = true
owners = ["amazon"]

filter {
name = "name"
values = ["amzn-ami-*-amazon-ecs-optimized"]
}
}

module "app_ecs_cluster" {
source = "../../"

name = var.test_name
environment = "test"

image_id = "${data.aws_ami.ecs_ami.image_id}"
instance_type = "t2.micro"

vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets
desired_capacity = 1
max_size = 1
min_size = 1
}

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

name = var.test_name
cidr = "10.0.0.0/16"
azs = var.vpc_azs
private_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
public_subnets = ["10.0.104.0/24", "10.0.105.0/24", "10.0.106.0/24"]

enable_nat_gateway = true
single_nat_gateway = true
}
14 changes: 14 additions & 0 deletions examples/simple/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
output "ecs_instance_role" {
description = "The ECS Instanc Role."
value = module.app_ecs_cluster.ecs_instance_role
}

output "ecs_cluster_name" {
description = "The ECS Cluster Name."
value = module.app_ecs_cluster.ecs_cluster_name
}

output "ecs_cluster_arn" {
description = "The ECS Cluster ARN."
value = module.app_ecs_cluster.ecs_cluster_arn
}
7 changes: 7 additions & 0 deletions examples/simple/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
variable "test_name" {
type = string
}

variable "vpc_azs" {
type = list(string)
}
9 changes: 9 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module github.com/trussworks/terraform-aws-ecs-cluster

go 1.13

require (
github.com/aws/aws-sdk-go v1.23.8
github.com/gruntwork-io/terratest v0.23.0
github.com/stretchr/testify v1.4.0
)
Loading

0 comments on commit 9af911e

Please sign in to comment.