homebrew-core/Formula/terraform.rb
2018-08-20 13:39:50 +02:00

88 lines
2.6 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/v0.11.8.tar.gz"
sha256 "c0d7a0b726579574bcfee2ae141be4e82d1c9ab4a339cc6f86f9ec38de9130fb"
head "https://github.com/hashicorp/terraform.git"
bottle do
cellar :any_skip_relocation
sha256 "5d338c6e0f2c066366fc67ce1508a4cc3f0f86fd203cdee1d2289ba04a32080f" => :mojave
sha256 "41f7d4f65268d67205f3cad6cfb80e3e7b1da543fb133a2874f6683c27fd3d93" => :high_sierra
sha256 "b268de0cd459f3a2cda89a312da6033c8960b0ab1d4c2d81a330c1e2f1e26b0e" => :sierra
sha256 "6ac1f8e358e1abcd05f7cd86fd450b36981d79a5a7b2fe7b9114c68c177a69b3" => :el_capitan
end
depends_on "go" => :build
depends_on "gox" => :build
conflicts_with "tfenv", :because => "tfenv symlinks terraform binaries"
# stringer is a build tool dependency
go_resource "golang.org/x/tools" do
url "https://go.googlesource.com/tools.git",
:branch => "release-branch.go1.10"
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"
cd "src/golang.org/x/tools/cmd/stringer" do
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", "bin"
bin.install "pkg/darwin_#{arch}/terraform"
prefix.install_metafiles
end
end
test do
minimal = testpath/"minimal.tf"
minimal.write <<~EOS
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", "init"
system "#{bin}/terraform", "graph"
end
end