-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathterraform.rb
106 lines (89 loc) · 3.31 KB
/
terraform.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
require "language/go"
class Terraform < Formula
desc "Tool to build, change, and version infrastructure"
homepage "https://www.terraform.io/"
# url "https://github.com/hashicorp/terraform/archive/v0.6.15.tar.gz"
# sha256 "5dc7cb1d29dee3de9ed9efacab7e72aa447052c96ae8269d932f6a979871a852"
# head "https://github.com/hashicorp/terraform.git"
version '0.6.16-ens.20'
url "https://github.com/Ensighten/terraform/archive/v#{version}.tar.gz"
sha256 "8d1aae2cf26986a7f5c1211849b09230caf641bb7cd0bd703bf2721106f2b668"
# To test a particular revision before release, set the head attribute's repo & revision, then:
# `brew install ./terraform.rb --HEAD`
# head "https://github.com/Ensighten/terraform.git", revision: "v0.6.16-ens"
depends_on "go" => :build
terraform_deps = %w[
github.com/mitchellh/gox 770c39f64e66797aa46b70ea953ff57d41658e40
github.com/mitchellh/iochan 87b45ffd0e9581375c491fef3d32130bb15c5bd7
]
terraform_deps.each_slice(2) do |x, y|
go_resource x do
url "https://#{x}.git", :revision => y
end
end
go_resource "golang.org/x/tools" do
url "https://go.googlesource.com/tools.git", :revision => "977844c7af2aa555048a19d28e9fe6c392e7b8e9"
end
def install
ENV["GOPATH"] = buildpath
# For the gox buildtool used by terraform, which doesn't need to
# get installed permanently
ENV.append_path "PATH", buildpath
terrapath = buildpath/"src/github.com/hashicorp/terraform"
terrapath.install Dir["*"]
Language::Go.stage_deps resources, buildpath/"src"
cd "src/github.com/mitchellh/gox" do
system "go", "build"
buildpath.install "gox"
end
cd "src/golang.org/x/tools/cmd/stringer" do
system "go", "build"
buildpath.install "stringer"
end
cd terrapath do
# v0.6.12 - source contains tests which fail if these environment variables are set locally.
ENV.delete "AWS_ACCESS_KEY"
ENV.delete "AWS_SECRET_KEY"
terraform_files = `go list ./...`.lines.map { |f| f.strip unless f.include? "/vendor/" }.compact
# FIXME: 0.6.16 release has a broken test, disable tests until next release
# system "go", "test", *terraform_files
mkdir "bin"
arch = Hardware::CPU.is_64_bit? ? "amd64" : "386"
system "gox",
"-arch", arch,
"-os", "darwin",
"-output", "bin/terraform-{{.Dir}}", *terraform_files
bin.install "bin/terraform-terraform" => "terraform"
bin.install Dir["bin/*"]
zsh_completion.install "contrib/zsh-completion/_terraform"
end
end
test do
minimal = testpath/"minimal.tf"
minimal.write <<-EOS.undent
variable "aws_region" {
default = "us-west-2"
}
variable "aws_amis" {
default = {
eu-west-1 = "ami-b1cf19c6"
us-east-1 = "ami-de7ab6b6"
us-west-1 = "ami-3f75767a"
us-west-2 = "ami-21f78e11"
}
}
# Specify the provider and access details
provider "aws" {
access_key = "this_is_a_fake_access"
secret_key = "this_is_a_fake_secret"
region = "${var.aws_region}"
}
resource "aws_instance" "web" {
instance_type = "m1.small"
ami = "${lookup(var.aws_amis, var.aws_region)}"
count = 4
}
EOS
system "#{bin}/terraform", "graph", testpath
end
end