homebrew-core/Formula/terraform.rb

70 lines
2.3 KiB
Ruby

class Terraform < Formula
desc "Tool to build, change, and version infrastructure"
homepage "https://www.terraform.io/"
url "https://github.com/hashicorp/terraform/archive/v0.14.7.tar.gz"
sha256 "8d411d067d35660f7e2622dacb5be87e108929321b6732c6770ec89ebe07231d"
license "MPL-2.0"
head "https://github.com/hashicorp/terraform.git"
livecheck do
url "https://releases.hashicorp.com/terraform/"
regex(%r{href=.*?v?(\d+(?:\.\d+)+)/?["' >]}i)
end
bottle do
sha256 cellar: :any_skip_relocation, arm64_big_sur: "2bb26dbc3ac635d36fb0d1131cdd99a02bdc55caaf28ef5f2f9ba6b593dc1beb"
sha256 cellar: :any_skip_relocation, big_sur: "e8c27c9aafd1742d15066ca175b47a74451628426f8ab718946821e21b773ca4"
sha256 cellar: :any_skip_relocation, catalina: "11c046443572c73446007f4c4eb146f978c06ac6edb080935a8f272bee7514b8"
sha256 cellar: :any_skip_relocation, mojave: "fc77affe5f26ad1b8710e8f656b25f59e3ec1d7c5c356300f06d969b16c9c7b8"
end
depends_on "go" => :build
conflicts_with "tfenv", because: "tfenv symlinks terraform binaries"
def install
# 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"
# resolves issues fetching providers while on a VPN that uses /etc/resolv.conf
# https://github.com/hashicorp/terraform/issues/26532#issuecomment-720570774
ENV["CGO_ENABLED"] = "1"
system "go", "build", *std_go_args, "-ldflags", "-s -w"
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 = var.aws_amis[var.aws_region]
count = 4
}
EOS
system "#{bin}/terraform", "init"
system "#{bin}/terraform", "graph"
end
end