Skip to content

Commit

Permalink
Merge pull request #14 from telia-oss/add-terratest
Browse files Browse the repository at this point in the history
Add terratest for examples
  • Loading branch information
Kristian authored Jul 16, 2019
2 parents af4d752 + 190bb52 commit 94cba67
Show file tree
Hide file tree
Showing 32 changed files with 481 additions and 423 deletions.
104 changes: 0 additions & 104 deletions .ci/pipeline.yml

This file was deleted.

9 changes: 0 additions & 9 deletions .ci/tasks/apply/task.sh

This file was deleted.

25 changes: 0 additions & 25 deletions .ci/tasks/apply/task.yml

This file was deleted.

6 changes: 0 additions & 6 deletions .ci/tasks/destroy/task.sh

This file was deleted.

19 changes: 0 additions & 19 deletions .ci/tasks/destroy/task.yml

This file was deleted.

3 changes: 0 additions & 3 deletions .ci/tasks/test/task.sh

This file was deleted.

19 changes: 0 additions & 19 deletions .ci/tasks/test/task.yml

This file was deleted.

22 changes: 12 additions & 10 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:
go:
- 1.12.x

env:
- GO111MODULE=on AWS_REGION=eu-west-1

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

notifications:
email: false

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.

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

vars:
DIRECTORIES:
sh: find . -type f -name '*.tf' -not -path "**/.terraform/*" -exec dirname {} \; | sort -u
FILES:
sh: find . -type f -name '*.tf' -not -path "**/.terraform/*"

tasks:
default:
cmds:
- task: test

test:
desc: Run all tests.
silent: true
cmds:
- task: fmt
- task: validate

tidy:
desc: Tidy all the things.
silent: true
cmds:
- go mod tidy
- |
for f in $(echo "{{.FILES}}"); do
sed -i '' -E "s/^([ ]*version[ ]*=[ ]*)\"([^\"]*)\"/\\1\"{{.PROVIDER_VERSION}}\"/g" $f
sed -i '' -E "s/^([ ]*required_version[ ]*=[ ]*)\"([^\"]*)\"/\\1\"{{.TERRAFORM_VERSION}}\"/g" $f
done
vars:
TERRAFORM_VERSION: '>= 0.12'
PROVIDER_VERSION: '>= 2.17'

fmt:
desc: Check formatting of all terraform files.
silent: true
cmds:
- task: command
vars:
COMMAND: terraform fmt
ARGS: -check=true -write=true -list=false -recursive=false
PIPE:

validate:
desc: Validate all terraform directories.
silent: true
cmds:
- task: command
vars:
COMMAND: terraform init
ARGS: -backend=false -input=false -get=true -get-plugins=true -no-color
PIPE: '> /dev/null'
- task: command
vars:
COMMAND: terraform validate
ARGS:
PIPE: '> /dev/null'

e2e:
desc: Run the end 2 end test suite.
cmds:
- go test -v ./... -timeout=1h

command:
desc: Run a command on the terraform directories.
silent: true
cmds:
- |
BOLD=$(tput bold)
NORM=$(tput sgr0)
CODE=0
echo "${BOLD} {{.COMMAND}}:${NORM}"
for d in $(echo "{{.DIRECTORIES}}"); do
if ! {{.COMMAND}} {{.ARGS}} $d {{.PIPE}}; then
echo " ✗ $d" && exit $?
else
echo " √ $d"
fi
done
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.
18 changes: 18 additions & 0 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
terraform {
required_version = ">= 0.12"
}

provider "aws" {
version = ">= 2.17"
region = "${var.region}"
}

module "vpc" {
source = "../../"
name_prefix = var.name_prefix

tags = {
terraform = "True"
environment = "dev"
}
}
3 changes: 3 additions & 0 deletions examples/basic/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "vpc_id" {
value = module.vpc.vpc_id
}
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 = "vpc-basic-example"
}

variable "region" {
type = string
default = "eu-west-1"
}
3 changes: 3 additions & 0 deletions examples/complete/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## examples/complete

An example which shows a more _complete_ usage of the module.
Loading

0 comments on commit 94cba67

Please sign in to comment.