diff --git a/.travis.yml b/.travis.yml index 4e82260..9dd026c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ --- rvm: - - 2.3.1 + - 2.4.2 sudo: true diff --git a/Gemfile b/Gemfile index 8617c21..82bd821 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,10 @@ + +ruby '2.4.2' + source 'https://rubygems.org/' do - gem 'kitchen-terraform', "~> 4.0" + gem 'aws-sdk', '~> 3.0.1' + gem 'awspec', '~> 1.4.0' + gem 'kitchen-terraform', '~> 3.1' + gem 'kitchen-verifier-awspec', '~> 0.1.1' + gem 'rhcl', '~> 0.1.0' end diff --git a/kitchen.yml b/kitchen.yml index e843724..1a2e262 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -10,7 +10,7 @@ verifier: name: terraform platforms: - - name: coreos + - name: aws verifier: systems: - name: remote @@ -23,3 +23,7 @@ platforms: suites: - name: default + verifier: + name: awspec + patterns: + - test/integration/unit_tests/test_vpc.rb diff --git a/test/fixtures/wrapper/test.tf b/test/fixtures/wrapper/test.tf index 4d79ad3..4699a09 100644 --- a/test/fixtures/wrapper/test.tf +++ b/test/fixtures/wrapper/test.tf @@ -1,5 +1,5 @@ locals { - "name_prefix" = "test-tf-vpc-module-" + name_prefix = "test-tf-vpc-module-" } module "vpc" { diff --git a/test/integration/unit_tests/test_vpc.rb b/test/integration/unit_tests/test_vpc.rb new file mode 100644 index 0000000..b6d0775 --- /dev/null +++ b/test/integration/unit_tests/test_vpc.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require 'awspec' +require 'aws-sdk' +require 'rhcl' + +# should strive to randomize the region for more robust testing +test_tf = Rhcl.parse(File.open('test/fixtures/wrapper/test.tf')) +vpc_name = test_tf['module']['vpc']['name'] +user_tag = test_tf['module']['vpc']['tags']['Owner'] +environment_tag = test_tf['module']['vpc']['tags']['Environment'] +state_file = 'terraform.tfstate.d/kitchen-terraform-default-aws/terraform.tfstate' +tf_state = JSON.parse(File.open(state_file).read) +region = tf_state['modules'][0]['outputs']['region']['value'] +ENV['AWS_REGION'] = region + +ec2 = Aws::EC2::Client.new(region: region) +azs = ec2.describe_availability_zones +zone_names = azs.to_h[:availability_zones].first(2).map { |az| az[:zone_name] } + +describe vpc(vpc_name.to_s) do + it { should exist } + it { should be_available } + it { should have_tag('Name').value(vpc_name.to_s) } + it { should have_tag('Owner').value(user_tag.to_s) } + it { should have_tag('Environment').value(environment_tag.to_s) } + it { should have_route_table("#{vpc_name}-public") } + zone_names.each do |az| + it { should have_route_table("#{vpc_name}-private-#{az}") } + end +end + +zone_names.each do |az| + describe subnet("#{vpc_name}-public-#{az}") do + it { should exist } + it { should be_available } + it { should belong_to_vpc(vpc_name.to_s) } + it { should have_tag('Name').value("#{vpc_name}-public-#{az}") } + it { should have_tag('Owner').value(user_tag.to_s) } + it { should have_tag('Environment').value(environment_tag.to_s) } + end +end +