Skip to content

Commit

Permalink
0.12upgrade (#21)
Browse files Browse the repository at this point in the history
* Run terraform 0.12upgrade

* Update default example

* Update s3 example

* Update s3-publish example

* Update vpc example

* Use native types

* Use new splat syntax in output

* Replace makefile with taskfile

* Remove abspath usage in examples
  • Loading branch information
Kristian authored Jul 30, 2019
1 parent a9c85d2 commit fa866a3
Show file tree
Hide file tree
Showing 11 changed files with 273 additions and 175 deletions.
24 changes: 13 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
dist: trusty
language: go
sudo: false

before_install:
- curl -fSL "https://releases.hashicorp.com/terraform/0.11.7/terraform_0.11.7_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

before_script:
- 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

script:
- make
- go get -u -v github.com/go-task/task/v2/cmd/task && task test
39 changes: 0 additions & 39 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'

tasks:
default:
cmds:
- task: test

test:
desc: Run tests for all terraform directories.
silent: true
env:
AWS_DEFAULT_REGION: eu-west-1
DIRECTORIES:
sh: find . -type f -name '*.tf' -not -path "**/.terraform/*" -exec dirname {} \; | sort -u
cmds:
- |
BOLD=$(tput bold)
NORM=$(tput sgr0)
for d in $DIRECTORIES; do
echo "${BOLD} $d:${NORM}"
cd $d
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
done
e2e:
desc: Run the end 2 end test suite.
silent: true
cmds:
- go test -v ./... -timeout=1h

18 changes: 12 additions & 6 deletions examples/default/example.tf
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
terraform {
required_version = ">= 0.12"
}

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

module "lambda" {
source = "../../"

name_prefix = "example"
filename = "${path.module}/../example.zip"
policy = "${data.aws_iam_policy_document.lambda.json}"
policy = data.aws_iam_policy_document.lambda.json
runtime = "python3.6"
handler = "example.handler"

environment {
environment = {
TEST = "TEST VALUE"
}

tags {
tags = {
environment = "prod"
terraform = "True"
}
Expand All @@ -38,9 +43,10 @@ data "aws_iam_policy_document" "lambda" {
}

output "lambda_arn" {
value = "${module.lambda.arn}"
value = module.lambda.arn
}

output "lambda_invoke_arn" {
value = "${module.lambda.invoke_arn}"
value = module.lambda.invoke_arn
}

22 changes: 14 additions & 8 deletions examples/s3-publish/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"
}

module "lambda" {
Expand All @@ -8,16 +13,16 @@ module "lambda" {
name_prefix = "example"
s3_bucket = "telia-oss"
s3_key = "hello-world/helloworld.zip"
policy = "${data.aws_iam_policy_document.lambda.json}"
policy = data.aws_iam_policy_document.lambda.json
runtime = "python3.6"
handler = "helloworld.handler"
publish = "true"
publish = true

environment {
environment = {
TEST = "TEST VALUE"
}

tags {
tags = {
environment = "prod"
terraform = "True"
}
Expand All @@ -40,13 +45,14 @@ data "aws_iam_policy_document" "lambda" {
}

output "lambda_arn" {
value = "${module.lambda.arn}"
value = module.lambda.arn
}

output "lambda_invoke_arn" {
value = "${module.lambda.invoke_arn}"
value = module.lambda.invoke_arn
}

output "lambda_qualified_arn" {
value = "${module.lambda.qualified_arn}"
value = module.lambda.qualified_arn
}

34 changes: 20 additions & 14 deletions examples/s3/example.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
terraform {
required_version = ">= 0.12"
}

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

data "aws_vpc" "main" {
default = true
}

data "aws_subnet_ids" "main" {
vpc_id = "${data.aws_vpc.main.id}"
vpc_id = data.aws_vpc.main.id
}

# Basic example which creates a Lambda function from s3 bucket in the default VPC.
Expand All @@ -17,18 +22,18 @@ module "lambda_vpc" {
name_prefix = "example-vpc"
s3_bucket = "telia-oss"
s3_key = "hello-world/helloworld.zip"
policy = "${data.aws_iam_policy_document.lambda_vpc.json}"
policy = data.aws_iam_policy_document.lambda_vpc.json
runtime = "python3.6"
handler = "helloworld.handler"
vpc_id = "${data.aws_vpc.main.id}"
subnet_ids = ["${data.aws_subnet_ids.main.ids}"]
attach_vpc_config = "true"
vpc_id = data.aws_vpc.main.id
subnet_ids = data.aws_subnet_ids.main.ids
attach_vpc_config = true

environment {
environment = {
TEST = "TEST VALUE"
}

tags {
tags = {
environment = "prod"
terraform = "True"
}
Expand All @@ -54,7 +59,7 @@ data "aws_iam_policy_document" "lambda_vpc" {
}

output "lambda_vpc_arn" {
value = "${module.lambda_vpc.arn}"
value = module.lambda_vpc.arn
}

module "lambda" {
Expand All @@ -63,15 +68,15 @@ module "lambda" {
name_prefix = "example"
s3_bucket = "telia-oss"
s3_key = "hello-world/helloworld.zip"
policy = "${data.aws_iam_policy_document.lambda.json}"
policy = data.aws_iam_policy_document.lambda.json
runtime = "python3.6"
handler = "helloworld.handler"

environment {
environment = {
TEST = "TEST VALUE"
}

tags {
tags = {
environment = "prod"
terraform = "True"
}
Expand All @@ -94,9 +99,10 @@ data "aws_iam_policy_document" "lambda" {
}

output "lambda_arn" {
value = "${module.lambda.arn}"
value = module.lambda.arn
}

output "lambda_invoke_arn" {
value = "${module.lambda.invoke_arn}"
value = module.lambda.invoke_arn
}

26 changes: 16 additions & 10 deletions examples/vpc/example.tf
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
terraform {
required_version = ">= 0.12"
}

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

data "aws_vpc" "main" {
default = true
}

data "aws_subnet_ids" "main" {
vpc_id = "${data.aws_vpc.main.id}"
vpc_id = data.aws_vpc.main.id
}

module "lambda" {
source = "../../"

name_prefix = "example-vpc"
filename = "${path.module}/../example.zip"
policy = "${data.aws_iam_policy_document.lambda.json}"
policy = data.aws_iam_policy_document.lambda.json
runtime = "python3.6"
handler = "example.handler"
vpc_id = "${data.aws_vpc.main.id}"
subnet_ids = ["${data.aws_subnet_ids.main.ids}"]
attach_vpc_config = "true"
vpc_id = data.aws_vpc.main.id
subnet_ids = data.aws_subnet_ids.main.ids
attach_vpc_config = true

environment {
environment = {
TEST = "TEST VALUE"
}

tags {
tags = {
environment = "prod"
terraform = "True"
}
Expand All @@ -52,9 +57,10 @@ data "aws_iam_policy_document" "lambda" {
}

output "lambda_arn" {
value = "${module.lambda.arn}"
value = module.lambda.arn
}

output "lambda_invoke_arn" {
value = "${module.lambda.invoke_arn}"
value = module.lambda.invoke_arn
}

Loading

0 comments on commit fa866a3

Please sign in to comment.