homebrew-core/Formula/terraform.rb
2016-10-20 23:51:59 -04:00

113 lines
3.4 KiB
Ruby

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/0.7.7.tar.gz"
sha256 "2e63e0855bc3b7296335b54a2140d4c2425ccd9424157cf69e708f6f5a2d30a2"
head "https://github.com/hashicorp/terraform.git"
bottle do
cellar :any_skip_relocation
sha256 "30becae3593d68bf5cbde65adfad4305c811cde307d6c8e994b95be6a540452e" => :sierra
sha256 "53e8d44fc572ea831909d97b5c6e1591ad9b2934673c5a161f8e523a8c2559a6" => :el_capitan
sha256 "2e4da1c7bccfc819a0211b34ea045bfdb342af2e117a8c0bb2daae1bd4ca2e46" => :yosemite
end
depends_on "go" => :build
terraform_deps = %w[
github.com/mitchellh/gox c9740af9c6574448fd48eb30a71f964014c7a837
github.com/mitchellh/iochan 87b45ffd0e9581375c491fef3d32130bb15c5bd7
github.com/kisielk/errcheck 9c1292e1c962175f76516859f4a88aabd86dc495
github.com/kisielk/gotool 5e136deb9b893bbe6c8f23236ff4378b7a8a0dbb
]
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 => "26c35b4dcf6dfcb924e26828ed9f4d028c5ce05a"
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
ENV.deparallelize { system "go", "build" }
buildpath.install "stringer"
end
cd "src/github.com/kisielk/errcheck" do
system "go", "build"
buildpath.install "errcheck"
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"
# Runs format check and test suite via makefile
ENV.deparallelize { system "make", "test", "vet" }
# Generate release binary
arch = MacOS.prefer_64_bit? ? "amd64" : "386"
ENV["XC_OS"] = "darwin"
ENV["XC_ARCH"] = arch
system "make", "bin"
# Install release binary
bin.install "pkg/darwin_#{arch}/terraform"
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