Skip to content

Commit

Permalink
Add terratest (#21)
Browse files Browse the repository at this point in the history
* Switch to taskfile instead of makefile

* Update basic example

* Remove precommit hook

* Add basic terratests to module
  • Loading branch information
Kristian authored Sep 2, 2019
1 parent 8b3a738 commit 3d4963a
Show file tree
Hide file tree
Showing 15 changed files with 449 additions and 83 deletions.
10 changes: 0 additions & 10 deletions .pre-commit-config.yaml

This file was deleted.

24 changes: 12 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
dist: trusty
sudo: false
language: go

before_install:
- curl -fSL "https://releases.hashicorp.com/terraform/0.12.6/terraform_0.12.6_linux_amd64.zip" -o terraform.zip
- sudo unzip terraform.zip -d /opt/terraform
- sudo ln -s /opt/terraform/terraform /usr/bin/terraform
- rm -f terraform.zip
- curl -fSL https://github.com/wata727/tflint/releases/download/v0.7.0/tflint_linux_amd64.zip -o tflint.zip
- sudo unzip tflint.zip -d /opt/tflint
- sudo ln -s /opt/tflint/tflint /usr/bin/tflint
- rm -f tflint.zip
go:
- 1.12.x

env:
- GO111MODULE=on

notifications:
email: false

install:
- curl -sL https://taskfile.dev/install.sh | sh
- curl -sL https://releases.hashicorp.com/terraform/0.12.7/terraform_0.12.7_linux_amd64.zip -o terraform.zip
- sudo unzip terraform.zip -d /usr/bin && rm -f terraform.zip

script:
- make
- ./bin/task test
39 changes: 0 additions & 39 deletions Makefile

This file was deleted.

55 changes: 55 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
version: '2'

env:
AWS_DEFAULT_REGION: eu-west-1
GO111MODULE: on

tasks:
default:
cmds:
- task: test

test:
desc: Run tests for all terraform directories.
silent: true
env:
DIRECTORIES:
sh: find . -type f -name '*.tf' -not -path "**/.terraform/*" -exec dirname {} \; | sort -u
cmds:
- |
BOLD=$(tput bold)
NORM=$(tput sgr0)
CWD=$PWD
for d in $DIRECTORIES; do
cd $d
echo "${BOLD}$PWD:${NORM}"
if ! terraform fmt -check=true -write=true -list=false -recursive=false; then
echo " ✗ terraform fmt" && exit $?
else
echo " √ terraform fmt"
fi
if ! terraform init -backend=false -input=false -get=true -get-plugins=true -no-color > /dev/null; then
echo " ✗ terraform init" && exit $?
else
echo " √ terraform init"
fi
if ! terraform validate > /dev/null; then
echo " ✗ terraform validate" && exit $?
else
echo " √ terraform validate"
fi
cd $CWD
done
e2e:
desc: Run the end 2 end test suite.
silent: true
cmds:
- go test -v ./... -timeout=1h

3 changes: 3 additions & 0 deletions examples/basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## examples/basic

An example which shows _basic_ usage of the module.
32 changes: 18 additions & 14 deletions examples/default/example.tf → examples/basic/main.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# ----------------------------------------
# Create a ecs service using fargate
# ----------------------------------------

provider "aws" {
region = "eu-west-1"
terraform {
required_version = ">= 0.12"
}

resource "aws_ecs_cluster" "cluster" {
name = "example-ecs-cluster"
provider "aws" {
version = ">= 2.17"
region = var.region
}

data "aws_vpc" "main" {
Expand All @@ -18,19 +18,20 @@ data "aws_subnet_ids" "main" {
vpc_id = data.aws_vpc.main.id
}


module "fargate_alb" {
source = "telia-oss/loadbalancer/aws"
version = "3.0.0"

name_prefix = "example-ecs-cluster"
name_prefix = var.name_prefix
type = "application"
internal = "false"
internal = false
vpc_id = data.aws_vpc.main.id
subnet_ids = data.aws_subnet_ids.main.ids

tags = {
environment = "test"
terraform = "true"
environment = "dev"
terraform = "True"
}
}

Expand Down Expand Up @@ -64,12 +65,17 @@ resource "aws_security_group_rule" "alb_ingress_80" {
ipv6_cidr_blocks = ["::/0"]
}

resource "aws_ecs_cluster" "cluster" {
name = "${var.name_prefix}-cluster"
}

module "fargate" {
source = "../../"

name_prefix = "example-app"
name_prefix = var.name_prefix
vpc_id = data.aws_vpc.main.id
private_subnet_ids = data.aws_subnet_ids.main.ids
lb_arn = module.fargate_alb.arn
cluster_id = aws_ecs_cluster.cluster.id
task_container_image = "crccheck/hello-world:latest"

Expand All @@ -85,10 +91,8 @@ module "fargate" {
}

tags = {
environment = "test"
terraform = "true"
environment = "dev"
terraform = "True"
}

lb_arn = module.fargate_alb.arn
}

11 changes: 11 additions & 0 deletions examples/basic/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
output "cluster_arn" {
value = aws_ecs_cluster.cluster.arn
}

output "service_arn" {
value = module.fargate.service_arn
}

output "endpoint" {
value = module.fargate_alb.dns_name
}
9 changes: 9 additions & 0 deletions examples/basic/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
variable "name_prefix" {
type = string
default = "fargate-basic-example"
}

variable "region" {
type = string
default = "eu-west-1"
}
3 changes: 0 additions & 3 deletions examples/default/README.md

This file was deleted.

4 changes: 0 additions & 4 deletions examples/default/versions.tf

This file was deleted.

17 changes: 17 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module github.com/telia-oss/terraform-aws-ecs-fargate/v3

go 1.12

require (
github.com/aws/aws-sdk-go v1.23.12
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gruntwork-io/terratest v0.18.5
github.com/kr/pretty v0.1.0 // indirect
github.com/magiconair/properties v1.8.1 // indirect
github.com/stretchr/testify v1.4.0
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472 // indirect
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 // indirect
golang.org/x/sys v0.0.0-20190830080133-08d80c9d36de // indirect
golang.org/x/text v0.3.2 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
)
40 changes: 40 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
github.com/aws/aws-sdk-go v1.23.12 h1:2UnxgNO6Y5J1OrkXS8XNp0UatDxD1bWHiDT62RDPggI=
github.com/aws/aws-sdk-go v1.23.12/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gruntwork-io/terratest v0.18.5 h1:qgzApIXcFOH9RhXuu3ICR7WjjiLegdvBSzjux1Y1wVM=
github.com/gruntwork-io/terratest v0.18.5/go.mod h1:NjUn6YXA5Skxt8Rs20t3isYx5Rl+EgvGB8/+RRXddqk=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472 h1:Gv7RPwsi3eZ2Fgewe3CBsuOebPwO27PoXzRpJPsvSSM=
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 h1:k7pJ2yAPLPgbskkFdhRCsA77k2fySZ1zf2zCjvQCiIM=
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190830080133-08d80c9d36de h1:MtIqW4Vp7DcnuoJTsTOgsa2R3jBQnCU0bjwXo7DcNT8=
golang.org/x/sys v0.0.0-20190830080133-08d80c9d36de/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
1 change: 0 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ resource "aws_ecs_task_definition" "task" {
"environment": ${jsonencode(data.null_data_source.task_environment.*.outputs)}
}]
EOF

}

resource "aws_ecs_service" "service" {
Expand Down
Loading

0 comments on commit 3d4963a

Please sign in to comment.