Skip to content

Commit

Permalink
Merge pull request #28 from telia-oss/use-templatefile-function
Browse files Browse the repository at this point in the history
Prepare for v2 release
  • Loading branch information
neilh456 authored Sep 10, 2019
2 parents ed049de + f39b655 commit 784d4bc
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 48 deletions.
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.3/terraform_0.12.3_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
27 changes: 0 additions & 27 deletions Makefile

This file was deleted.

48 changes: 48 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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
6 changes: 5 additions & 1 deletion examples/default/example.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
terraform {
required_version = ">= 0.12"
}

provider "aws" {
version = ">= 1.33.0"
version = ">= 2.17"
region = "eu-west-1"
}

Expand Down
7 changes: 6 additions & 1 deletion examples/graceful-shutdown/example.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
terraform {
required_version = ">= 0.12"
}

provider "aws" {
region = "eu-west-1"
version = ">= 2.17"
region = "eu-west-1"
}

data "aws_vpc" "main" {
Expand Down
7 changes: 6 additions & 1 deletion examples/volumes/example.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
terraform {
required_version = ">= 0.12"
}

provider "aws" {
region = "eu-west-1"
version = ">= 2.17"
region = "eu-west-1"
}

data "aws_vpc" "main" {
Expand Down
10 changes: 4 additions & 6 deletions modules/cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ resource "aws_cloudwatch_log_group" "main" {
retention_in_days = var.log_retention_in_days
}

data "template_file" "main" {
template = file("${path.module}/cloud-config.yml")

vars = {
locals {
cloud_config = templatefile("${path.module}/cloud-config.yml", {
stack_name = "${var.name_prefix}-cluster-asg"
region = data.aws_region.current.name
log_group_name = aws_cloudwatch_log_group.main.name
ecs_cluster_name = aws_ecs_cluster.main.name
ecs_log_level = var.ecs_log_level
}
})
}

data "aws_iam_policy_document" "permissions" {
Expand Down Expand Up @@ -76,7 +74,7 @@ module "asg" {
source = "telia-oss/asg/aws"
version = "v3.0.1"
name_prefix = "${var.name_prefix}-cluster"
user_data = coalesce(var.user_data, data.template_file.main.rendered)
user_data = coalesce(var.user_data, local.cloud_config)
vpc_id = var.vpc_id
subnet_ids = var.subnet_ids
await_signal = "true"
Expand Down

0 comments on commit 784d4bc

Please sign in to comment.