forked from alphagov/paas-docker-cloudfoundry-tools
-
Notifications
You must be signed in to change notification settings - Fork 3
/
terraform_spec.rb
89 lines (71 loc) · 2.74 KB
/
terraform_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
require 'spec_helper'
require 'docker'
require 'serverspec'
describe "Terraform image" do
before(:all) {
set :docker_image, find_image_id('terraform:latest')
@terraform_version_output = command("terraform version").stdout
}
it "installs Alpine" do
expect(command("cat /etc/issue | head -1").stdout).to include("Alpine Linux")
end
it "installs Root Certificates" do
expect(file("/usr/share/ca-certificates/mozilla/GlobalSign_Root_CA.crt")).to be_file
end
it "installs plugin cache" do
expect(file("/tmp/plugin_cache.tf")).to be_file
end
it "has the expected Terraform version" do
expect(@terraform_version_output).to match("Terraform v0.11.14$")
end
it "installs SSH" do
expect(
command("ssh -V").stderr.strip
).to include("OpenSSH")
end
it "has the plugins already downloaded" do
expect(
command("cd /tmp && terraform init").stdout.strip
).to_not include("Downloading")
end
it "disables interactive Terraform use" do
expect(
command("printenv TF_INPUT").stdout.strip
).to eq("0")
end
context "providers checks" do
let(:expected_plugin_error_message) { "This binary is a plugin. These are not meant to be executed directly.\nPlease execute the program that consumes these plugins, which will\nload any plugins automatically" }
it "validates provider binaries execution" do
provider_binaries=command("cd /.terraform/plugins/linux_amd64; ls terraform-provider-*").stdout.strip
provider_binaries.each_line do |provider|
provider_execution= command("cd /.terraform/plugins/linux_amd64;./#{provider}").stderr.strip
expect(provider_execution).to eq(expected_plugin_error_message)
end
end
it "has the local provider" do
expect(@terraform_version_output).to include("provider.local v1.4.0")
end
it "has the openstack provider" do
expect(@terraform_version_output).to include("provider.openstack v1.25.0")
end
it "has the powerdns provider" do
expect(@terraform_version_output).to include("provider.powerdns v1.3.0")
end
it "has the credhub provider" do
expect(@terraform_version_output).to include("provider.credhub v0.13.0")
end
it "has the cloudfoundry provider" do
expect(@terraform_version_output).to include("provider.cloudfoundry v0.11.2")
end
it "has the uaa provider" do
expect(@terraform_version_output).to include("provider.uaa v0.9")
end
it "has the flexibleengine provider" do
expect(@terraform_version_output).to include("provider.flexibleengine v1.11.1")
end
it "has enough providers" do
EXPECTED_PROVIDER_COUNT = 12
expect(@terraform_version_output.scan('provider.').length).to eq(EXPECTED_PROVIDER_COUNT)
end
end
end