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.9.6.tar.gz" sha256 "2af004ee5a155317e6df0158a5d9121d15aa349202ca7d7dd8321f2d9af2218c" head "https://github.com/hashicorp/terraform.git" bottle do cellar :any_skip_relocation sha256 "f835603d6bea928eb0bdc49212400aeaee122af068c8a49d2402ac7ecd8838f0" => :sierra sha256 "3792c7ee26966a5c64a28edf6e53a350b0a96a1398b8c54e66e4e849fcd62c35" => :el_capitan sha256 "a4f2240132452d6f7162e880827e8c698e9b5ce924cb10ceb813a4b966d46cab" => :yosemite end depends_on "go" => :build conflicts_with "tfenv", :because => "tfenv symlinks terraform binaries" go_resource "github.com/mitchellh/gox" do url "https://github.com/mitchellh/gox.git", :revision => "c9740af9c6574448fd48eb30a71f964014c7a837" end go_resource "github.com/mitchellh/iochan" do url "https://github.com/mitchellh/iochan.git", :revision => "87b45ffd0e9581375c491fef3d32130bb15c5bd7" end go_resource "github.com/kisielk/errcheck" do url "https://github.com/kisielk/errcheck.git", :revision => "23699b7e2cbfdb89481023524954ba2aeff6be90" end go_resource "github.com/kisielk/gotool" do url "https://github.com/kisielk/gotool.git", :revision => "0de1eaf82fa3f583ce21fde859f1e7e0c5e9b220" end go_resource "golang.org/x/tools" do url "https://go.googlesource.com/tools.git", :revision => "5682db0e919ed9cfc6f52ac32e170511a106eb3b" end def install ENV["GOPATH"] = buildpath ENV.prepend_create_path "PATH", buildpath/"bin" dir = buildpath/"src/github.com/hashicorp/terraform" dir.install buildpath.children - [buildpath/".brew_home"] Language::Go.stage_deps resources, buildpath/"src" %w[src/github.com/mitchellh/gox src/golang.org/x/tools/cmd/stringer src/github.com/kisielk/errcheck].each do |path| cd(path) { system "go", "install" } end cd dir 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" arch = MacOS.prefer_64_bit? ? "amd64" : "386" ENV["XC_OS"] = "darwin" ENV["XC_ARCH"] = arch system "make", "test", "vet", "bin" bin.install "pkg/darwin_#{arch}/terraform" zsh_completion.install "contrib/zsh-completion/_terraform" prefix.install_metafiles 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