Moving to Docker based Terraform-Test framework (#2)

This commit is contained in:
Vaijanath Angadihiremath 2017-12-08 01:02:47 +00:00 коммит произвёл David Tesar
Родитель e7d71f4a11
Коммит 6e17afd471
5 изменённых файлов: 14 добавлений и 178 удалений

Просмотреть файл

@ -1,48 +1,19 @@
# Build matrix / environment variable are explained on:
# http://about.travis-ci.org/docs/user/build-configuration/
# This file can be validated on:
# http://lint.travis-ci.org/
sudo: true
dist: trusty
sudo: required
language: ruby
rvm:
- 2.3
env:
global:
- TERRAFORM_VERSION=0.11.0
matrix:
- TERRAFORM_OS_ARCH=linux_amd64
matrix:
services:
- docker
jobs:
include:
- os: linux
env: TERRAFORM_OS_ARCH=linux_amd64
# - os: osx
# env: TERRAFORM_OS_ARCH=darwin_amd64
before_install:
# Update Gem.
- gem update --system
- gem --version
# Install GPG for OS X
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew list gpg > /dev/null 2>&1 || brew install gpg; fi
install:
# Import hashicorp's keys.
- curl https://keybase.io/hashicorp/pgp_keys.asc | gpg --import
# Download the binary and signature files.
- curl -Os https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_${TERRAFORM_OS_ARCH}.zip
- curl -Os https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_SHA256SUMS
- curl -Os https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_SHA256SUMS.sig
# Verify the signature file is untampered.
- gpg --verify terraform_${TERRAFORM_VERSION}_SHA256SUMS.sig terraform_${TERRAFORM_VERSION}_SHA256SUMS
# Verify the SHASUM matches the binary.
- shasum -a 256 -c terraform_${TERRAFORM_VERSION}_SHA256SUMS 2>&1 | grep "${TERRAFORM_VERSION}_${TERRAFORM_OS_ARCH}.zip:\sOK"
# Install terraform locally and add into PATH.
- mv terraform_${TERRAFORM_VERSION}_${TERRAFORM_OS_ARCH}.zip terraform.zip
- unzip terraform.zip
- sudo mkdir /usr/local/terraform
- sudo mv terraform /usr/local/terraform
- rm -f terraform && rm -f terraform_hash && rm -f terraform.zip
- export PATH="/usr/local/terraform":$PATH
# Install gems.
- bundle install
script:
- rake build
- stage: rake build
install: true
script:
- docker run -v $PWD:/tf-test/module --rm microsoft/terraform-test rake -f ../Rakefile build
- stage: rake e2e
install: true
script:
- docker run -v $PWD:/tf-test/module -e ARM_CLIENT_ID -e ARM_TENANT_ID -e ARM_SUBSCRIPTION_ID -e ARM_CLIENT_SECRET -e ARM_TEST_LOCATION -e ARM_TEST_LOCATION_ALT --rm microsoft/terraform-test rake -f ../Rakefile e2e

12
Gemfile
Просмотреть файл

@ -1,12 +0,0 @@
ruby "~> 2.3.0"
source 'https://rubygems.org/'
gem 'rake', '~>12.3.0'
group :test do
gem 'colorize', '~>0.8.0'
gem 'kitchen-terraform', '~>3.0.0'
gem 'rspec', '~>3.7.0'
gem 'test-kitchen', '~>1.16.0'
end

Просмотреть файл

@ -1,67 +0,0 @@
require 'colorize'
require 'rspec/core/rake_task'
require_relative 'build/file_utils'
require_relative 'build/static_utils'
namespace :presteps do
task :clean_up do
clean_up_kitchen
clean_up_terraform
end
end
namespace :static do
task :style do
style_tf
end
task :lint do
lint_tf
end
task :format do
format_tf
end
end
namespace :integration do
task :converge do
exit_code = `kitchen converge`
if exit_code != 0
raise "ERROR: Test kitchen converge failed! #{exit_code}\n"
end
end
task :verify do
exit_code = `kitchen verify`
if exit_code != 0
raise "ERROR: Test kitchen verify failed! #{exit_code}\n"
end
end
task :test do
exit_code = `kitchen test`
if exit_code != 0
raise "ERROR: Test kitchen test failed! #{exit_code}\n"
end
end
task :destroy do
exit_code = `kitchen destroy`
if exit_code != 0
raise "ERROR: Test kitchen destroy failed! #{exit_code}\n"
end
end
end
task :prereqs => [ 'presteps:clean_up' ]
task :validate => [ 'static:style', 'static:lint' ]
task :format => [ 'static:format' ]
task :build => [ 'prereqs', 'validate' ]
task :unit => []
task :e2e => [ 'integration:test' ]
task :default => [ 'build' ]
task :full => [ 'build', 'unit', 'e2e']

Просмотреть файл

@ -1,15 +0,0 @@
require 'fileutils'
def clean_up_kitchen
if File.exists? '.kitchen'
print "INFO: Cleaning up the .kitchen folder...\n"
FileUtils.rm_rf('.kitchen')
end
end
def clean_up_terraform
if File.exists? '.terraform'
print "INFO: Cleaning up the .terraform folder...\n"
FileUtils.rm_rf('.terraform')
end
end

Просмотреть файл

@ -1,41 +0,0 @@
require 'colorize'
require 'fileutils'
def lint_tf
# Do the linting on current working folder.
print "INFO: Linting Terraform configurations...\n".yellow
message = `terraform validate -check-variables=false 2>&1`
# Check the linting message.
if not message.empty?
raise "ERROR: Linting Terraform configurations failed!\n#{message}\n".red
else
print "INFO: Done!\n".green
end
end
def style_tf
# Do the style checking on current working folder.
print "INFO: Styling Terraform configurations...\n".yellow
message = `terraform fmt -check=true 2>&1`
# Check the styling message.
if not message.empty?
raise "ERROR: Styling Terraform configurations failed!\n#{message}\n".red
else
print "INFO: Done!\n".green
end
end
def format_tf
# Apply the canonical format and style on current working folder.
print "INFO: Formatting Terraform configurations...\n".yellow
message = `terraform fmt -diff=true 2>&1`
# Check the styling message.
if not message.empty?
raise "ERROR: Formatting Terraform configurations failed!\n#{message}\n".red
else
print "INFO: Done!\n".green
end
end