tfmodtest 0.0.1.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +88 -0
- data/.travis.yml +17 -0
- data/Gemfile +4 -0
- data/LICENSE +13 -0
- data/README.md +118 -0
- data/Rakefile +3 -0
- data/lib/tfmodtest.rb +4 -0
- data/lib/tfmodtest/module_helper.rb +47 -0
- data/lib/tfmodtest/module_tasks.rb +2 -0
- data/lib/tfmodtest/module_test.rb +53 -0
- data/lib/tfmodtest/version.rb +3 -0
- data/tfmodtest.gemspec +28 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0ec2e150dfac98056bc676c0c88aa04619bca081
|
4
|
+
data.tar.gz: 1f371aa7bdbf6deace4dab3960b98f0681e99e61
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 63b15f889ae62fe0e9df9a2ef79abbdf2c8040bd0a98a0d16de6d38f3ed7125bca131b2b5631039089d442788ad4e80446f81020ec9c93214d1931f2ff4015ac
|
7
|
+
data.tar.gz: e15f514af6e455aaab3569beef421f39f795867ffca008616acbc2e4c4fe384ed77f1018dd09b24b7e442d7278b44d40cca1a4fa355bb9db85d0ea52d15dc7d0
|
data/.gitignore
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
|
2
|
+
# Created by https://www.gitignore.io/api/vim,terraform,visualstudiocode,ruby
|
3
|
+
|
4
|
+
### Ruby ###
|
5
|
+
*.gem
|
6
|
+
*.rbc
|
7
|
+
/.config
|
8
|
+
/coverage/
|
9
|
+
/InstalledFiles
|
10
|
+
/pkg/
|
11
|
+
/spec/reports/
|
12
|
+
/spec/examples.txt
|
13
|
+
/test/tmp/
|
14
|
+
/test/version_tmp/
|
15
|
+
/tmp/
|
16
|
+
|
17
|
+
# Used by dotenv library to load environment variables.
|
18
|
+
# .env
|
19
|
+
|
20
|
+
## Specific to RubyMotion:
|
21
|
+
.dat*
|
22
|
+
.repl_history
|
23
|
+
build/
|
24
|
+
*.bridgesupport
|
25
|
+
build-iPhoneOS/
|
26
|
+
build-iPhoneSimulator/
|
27
|
+
|
28
|
+
## Specific to RubyMotion (use of CocoaPods):
|
29
|
+
#
|
30
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
31
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
32
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
33
|
+
#
|
34
|
+
# vendor/Pods/
|
35
|
+
|
36
|
+
## Documentation cache and generated files:
|
37
|
+
/.yardoc/
|
38
|
+
/_yardoc/
|
39
|
+
/doc/
|
40
|
+
/rdoc/
|
41
|
+
|
42
|
+
## Environment normalization:
|
43
|
+
/.bundle/
|
44
|
+
/vendor/bundle
|
45
|
+
/lib/bundler/man/
|
46
|
+
|
47
|
+
# for a library or gem, you might want to ignore these files since the code is
|
48
|
+
# intended to run in multiple environments; otherwise, check them in:
|
49
|
+
Gemfile.lock
|
50
|
+
# .ruby-version
|
51
|
+
# .ruby-gemset
|
52
|
+
|
53
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
54
|
+
.rvmrc
|
55
|
+
|
56
|
+
### Terraform ###
|
57
|
+
# Compiled files
|
58
|
+
*.tfstate
|
59
|
+
*.tfstate.backup
|
60
|
+
|
61
|
+
# Module directory
|
62
|
+
.terraform/
|
63
|
+
|
64
|
+
### Terraform Patch ###
|
65
|
+
*.tfvars
|
66
|
+
### Vim ###
|
67
|
+
# swap
|
68
|
+
[._]*.s[a-v][a-z]
|
69
|
+
[._]*.sw[a-p]
|
70
|
+
[._]s[a-v][a-z]
|
71
|
+
[._]sw[a-p]
|
72
|
+
# session
|
73
|
+
Session.vim
|
74
|
+
# temporary
|
75
|
+
.netrwhist
|
76
|
+
*~
|
77
|
+
# auto-generated tag files
|
78
|
+
tags
|
79
|
+
|
80
|
+
### VisualStudioCode ###
|
81
|
+
.vscode/*
|
82
|
+
!.vscode/settings.json
|
83
|
+
!.vscode/tasks.json
|
84
|
+
!.vscode/launch.json
|
85
|
+
!.vscode/extensions.json
|
86
|
+
.history
|
87
|
+
|
88
|
+
# End of https://www.gitignore.io/api/vim,terraform,visualstudiocode,ruby
|
data/.travis.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
rvm:
|
4
|
+
- 2.1.6
|
5
|
+
before_install:
|
6
|
+
- gem install bundler -v 1.14.6
|
7
|
+
os:
|
8
|
+
- linux
|
9
|
+
- osx
|
10
|
+
deploy:
|
11
|
+
provider: rubygems
|
12
|
+
api_key:
|
13
|
+
secure: cEI9LKkhADHmTGsiCsqUwhjVAW/qtWd7NhPMPsgEvPbHFB6qO/zmocbceEWIcQT3WKp9i/RzSF5zrD3cmCEMmjs7e4XaVFn0NOoDFBQIZgWk5PfbGMlVaCArGJ80tbhCFLFfVqyw7pR4OtP5ov6nULi8HBdfq5ffmjC92Pg0phWDTsyKGHesXuvMUjyx8y61hZOaXkkYd5T8MaN/9ahdM0r6hp2XX5RZDWm0712b2qKO/9gBH1WUaYyiawiNmHtLsUwgobZC6s8i5EObqAY0EbFBr69vUy7mQvJtWUGQJP89RdZ9jpqOHFoSsYuBWhYixWUOmgoV2z4jBUYGGIU+Il+57SjQPB4bH5FK3OvSD6ctN7kbEWnenYhJsn2UnVtR68PrXu/xvrCmfKcQ5NgNb+eJLInjeE42OH3+Oqx2RAjGRB8yV8a+WW7rymXZ89UHYODZd8dhbRwMH8nkfblMa6f7uZXeUF9wtahh2d12xj4APLvQLN24EMX46/TXiP2IjYzeYQf4loG0SnDjds94g9aTX4SdybiIdSrThyKcgNwlrQtKq4Gp0/yfCQxtfhqcZDoPVOU3Rts3uITiqV4/jqyF2UeFPfdhZuEaAsy9OlnA9fgfN9L70b/ylhHbJfkyzVIUP8o/7VZzMqyiyXctYM9+XM4408GALFdqPwdDFM4=
|
14
|
+
gem: tfmodtest
|
15
|
+
on:
|
16
|
+
tags: true
|
17
|
+
repo: vistaprint/tfmodtest
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2017 Cimpress
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
# Terraform Module Testing
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/vistaprint/tfmodtest.svg?branch=master)](https://travis-ci.org/vistaprint/tfmodtest)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/tfmodtest.svg)](https://badge.fury.io/rb/tfmodtest)
|
5
|
+
|
6
|
+
Terraform Module Testing is a set of rake tasks to easily enable testing for Terraform Module developement. It allows developers to specify tests in a rake task to test remote infrastructure is created as expected when using a module. It then destroys the environment after the test has run.
|
7
|
+
|
8
|
+
Currently this repository is tightly coupled with AWS and has not been tested to work with other providers. We are actively working to change this and hope to have a more generic solution soon. If you would like to see support for your favourite cloud provider please have submit a pull request implementing support and we will be more than happy to merge your changes in.
|
9
|
+
|
10
|
+
# Installation
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
`gem 'tfmodtest'`
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
`$ bundle`
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
`$ gem install tfmodtest`
|
22
|
+
|
23
|
+
## Getting started
|
24
|
+
|
25
|
+
### A Minimal Rakefile
|
26
|
+
|
27
|
+
In the root of your repository add a `Rakefile` with the following contents:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'tfmodtest/module_tasks'
|
31
|
+
```
|
32
|
+
|
33
|
+
# Adding tests
|
34
|
+
|
35
|
+
In your repository create `test/<my_module>/Rakefile` and add:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
namespace '<your_modules_namespace>' do
|
39
|
+
# Required: Import TerraformDevKit base rake tasks.
|
40
|
+
# Set the root path of our tests to our location.
|
41
|
+
# TerraformDevKit uses this path as the base from where
|
42
|
+
# all operations are run.
|
43
|
+
ROOT_PATH = File.dirname(File.expand_path(__FILE__))
|
44
|
+
spec = Gem::Specification.find_by_name 'TerraformDevKit'
|
45
|
+
load "#{spec.gem_dir}/tasks/devkit.rake"
|
46
|
+
|
47
|
+
# Optional: Use RSpec to run tests.
|
48
|
+
begin
|
49
|
+
require 'rspec/core/rake_task'
|
50
|
+
RSpec::Core::RakeTask.new(:spec)
|
51
|
+
rescue LoadError
|
52
|
+
raise 'Rspec not found'
|
53
|
+
end
|
54
|
+
|
55
|
+
# Required: Add a hook into TerraformDevKit to
|
56
|
+
# run tests for your module.
|
57
|
+
task :custom_test, [:env] => :spec
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
The `custom_test` task is a hook in TerraformDevKit that is called once all the infrastructure is created. You can see a full list of useful hooks in TerraformDevKit [here](https://github.com/vistaprint/TerraformDevKit#tasks-and-hooks)
|
62
|
+
|
63
|
+
Create `test/<my_module>/config/config-dev.yml` that contains:
|
64
|
+
|
65
|
+
```yml
|
66
|
+
terraform-version: 0.11.0
|
67
|
+
project-name: my module tests
|
68
|
+
aws:
|
69
|
+
profile: <profile>
|
70
|
+
region: <region>
|
71
|
+
|
72
|
+
```
|
73
|
+
|
74
|
+
This configuration determines where Terraform will create the infrastructure during test execution.
|
75
|
+
|
76
|
+
Finally to create your infrastructure under test place a `main.tf.mustache` file in `test/<my_module>`. This is the file TerraformDevKit will use to create you infrastructure.
|
77
|
+
|
78
|
+
```hcl
|
79
|
+
provider "aws" {
|
80
|
+
# Use the profile specified in config/config-dev.yml
|
81
|
+
profile = "{{Profile}}"
|
82
|
+
region = "us-east-1"
|
83
|
+
}
|
84
|
+
|
85
|
+
resource "aws_s3_bucket" "b" {
|
86
|
+
# Use the Environment name as part of the bucket name
|
87
|
+
bucket = "{{Environment}}my-tf-test-bucket"
|
88
|
+
acl = "private"
|
89
|
+
|
90
|
+
tags {
|
91
|
+
Name = "My bucket"
|
92
|
+
Environment = "Dev"
|
93
|
+
}
|
94
|
+
}
|
95
|
+
```
|
96
|
+
|
97
|
+
## Optional but recommended
|
98
|
+
|
99
|
+
[`awspec`](https://github.com/k1LoW/awspec) is a Ruby gem for running `rspec` tests against AWS infrastructure. It eases the pain of running tests against AWS:
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
describe cloudwatch_alarm("www.example.com-5xxErrorRate") do
|
103
|
+
it { should exist }
|
104
|
+
it { should belong_to_metric('5xxErrorRate').namespace('AWS/CloudFront') }
|
105
|
+
end
|
106
|
+
```
|
107
|
+
|
108
|
+
To start using `awspec` follow the [Getting Started ](https://github.com/k1LoW/awspec#getting-started)
|
109
|
+
|
110
|
+
# Requirements
|
111
|
+
|
112
|
+
* Terraform 0.11.0 or above
|
113
|
+
|
114
|
+
# Development
|
115
|
+
|
116
|
+
To install this gem locally run `rake install` You should then be able to reference it in your local projects.
|
117
|
+
|
118
|
+
|
data/Rakefile
ADDED
data/lib/tfmodtest.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
require 'tfmodtest'
|
5
|
+
|
6
|
+
TMT = TFModTest
|
7
|
+
|
8
|
+
HOSTNAME = Socket.gethostname
|
9
|
+
DATE = Time.new.strftime('%y%m%d%H%M%S')
|
10
|
+
DEFAULT_PREFIX = "TMT#{HOSTNAME}#{DATE}".freeze
|
11
|
+
|
12
|
+
module TFModTest
|
13
|
+
class ModuleHelper
|
14
|
+
include Rake::DSL if defined? Rake::DSL
|
15
|
+
|
16
|
+
class << self
|
17
|
+
def install_tasks
|
18
|
+
new.install
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def install
|
23
|
+
task default: [:preflight]
|
24
|
+
|
25
|
+
def run_task(task_name)
|
26
|
+
TMT::ModuleTestRepository.each do |m|
|
27
|
+
m.run_task(task_name)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
desc 'Runs all the tests'
|
32
|
+
task :preflight do
|
33
|
+
run_task('preflight')
|
34
|
+
end
|
35
|
+
|
36
|
+
desc 'Destroy any remaining infrastructure'
|
37
|
+
task :destroy do
|
38
|
+
run_task('destroy')
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'Cleans up the project (after destroying infrastructure)'
|
42
|
+
task :clean do
|
43
|
+
run_task('clean')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'TerraformDevKit'
|
2
|
+
|
3
|
+
module TFModTest
|
4
|
+
TDK = TerraformDevKit
|
5
|
+
|
6
|
+
class ModuleTest
|
7
|
+
def initialize(module_name)
|
8
|
+
@module_name = module_name
|
9
|
+
end
|
10
|
+
|
11
|
+
def run_task(task_name)
|
12
|
+
puts("=== Running task #{task_name} for module #{@module_name} ===")
|
13
|
+
module_path = File.join('test', @module_name)
|
14
|
+
run_task_in_directory(task_name, module_path)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def run_task_in_directory(task_name, dir)
|
20
|
+
Dir.chdir(dir) do
|
21
|
+
load 'Rakefile'
|
22
|
+
begin
|
23
|
+
Rake::Task["#{@module_name}:#{task_name}"].invoke(DEFAULT_PREFIX)
|
24
|
+
rescue RuntimeError => e
|
25
|
+
puts e.message
|
26
|
+
puts e.backtrace.join("\n")
|
27
|
+
Rake::Task["#{@module_name}:clean"].invoke(DEFAULT_PREFIX)
|
28
|
+
raise "Error testing module #{@module_name}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class ModuleTestRepository
|
35
|
+
def self.each
|
36
|
+
modules_path = Rake::FileList.new('test/*')
|
37
|
+
modules_path.each do |path|
|
38
|
+
module_name = File.basename(path)
|
39
|
+
yield ModuleTest.new(module_name) unless excluded?(module_name)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private_class_method
|
44
|
+
def self.excluded?(module_name)
|
45
|
+
excluded_modules.include?(module_name)
|
46
|
+
end
|
47
|
+
|
48
|
+
private_class_method
|
49
|
+
def self.excluded_modules
|
50
|
+
ENV.fetch('TM_EXCLUDE_MODULES', '').split(',')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/tfmodtest.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'tfmodtest/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'tfmodtest'
|
9
|
+
spec.version = TFModTest::VERSION
|
10
|
+
spec.authors = ['Victor Jimenez', 'Daniel Baker']
|
11
|
+
spec.email = ['vjimenez@vistaprint.com', 'dbaker@vistaprint.com']
|
12
|
+
|
13
|
+
spec.summary = 'Set of scripts to ease testing od Terraform modules.'
|
14
|
+
spec.homepage = 'https://github.com/vistaprint/TerraformModuleTesting'
|
15
|
+
spec.license = 'Apache-2.0'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
|
27
|
+
spec.add_runtime_dependency 'TerraformDevKit', '~> 0.2'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tfmodtest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.rc2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Victor Jimenez
|
8
|
+
- Daniel Baker
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2017-12-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.14'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.14'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: TerraformDevKit
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0.2'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0.2'
|
56
|
+
description:
|
57
|
+
email:
|
58
|
+
- vjimenez@vistaprint.com
|
59
|
+
- dbaker@vistaprint.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- lib/tfmodtest.rb
|
71
|
+
- lib/tfmodtest/module_helper.rb
|
72
|
+
- lib/tfmodtest/module_tasks.rb
|
73
|
+
- lib/tfmodtest/module_test.rb
|
74
|
+
- lib/tfmodtest/version.rb
|
75
|
+
- tfmodtest.gemspec
|
76
|
+
homepage: https://github.com/vistaprint/TerraformModuleTesting
|
77
|
+
licenses:
|
78
|
+
- Apache-2.0
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">"
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.3.1
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.6.13
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Set of scripts to ease testing od Terraform modules.
|
100
|
+
test_files: []
|