diff --git a/WORKSPACE b/WORKSPACE index bf36589..d16a4dc 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -27,9 +27,6 @@ container_pull( repository = "distroless/static-debian10", ) -http_archive( - name = "terraform_0.13.0_linux_amd64", - build_file_content = "exports_files([\"terraform\"])", - sha256 = "9ed437560faf084c18716e289ea712c784a514bdd7f2796549c735d439dbe378", - urls = ["https://releases.hashicorp.com/terraform/0.13.0/terraform_0.13.0_linux_amd64.zip"], -) +load("//terraform:terraform.bzl", "terraform_binaries") + +terraform_binaries() diff --git a/terraform/BUILD.bazel b/terraform/BUILD.bazel index 64d2e6e..505e845 100644 --- a/terraform/BUILD.bazel +++ b/terraform/BUILD.bazel @@ -1,21 +1,3 @@ -load("@io_bazel_rules_docker//container:container.bzl", "container_image", "container_push") +load(":terraform.bzl", "terraform_images") -container_image( - name = "0.13.0", - base = "@distroless//image", - cmd = "help", - directory = "/bin/", - entrypoint = ["/bin/terraform"], - files = ["@terraform_0.13.0_linux_amd64//:terraform"], - mode = "0o755", - repository = "quay.io/hadrienpatte", -) - -container_push( - name = "0.13.0_push", - format = "Docker", - image = ":0.13.0", - registry = "quay.io", - repository = "hadrienpatte/{}".format(package_name()), - tag = "0.13.0", -) +terraform_images() diff --git a/terraform/terraform.bzl b/terraform/terraform.bzl new file mode 100644 index 0000000..75d37f7 --- /dev/null +++ b/terraform/terraform.bzl @@ -0,0 +1,54 @@ +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@io_bazel_rules_docker//container:container.bzl", "container_image", "container_push") + +TERRAFORM_RELEASES = [ + { + "version": "0.13.5", + "sha256": "f7b7a7b1bfbf5d78151cfe3d1d463140b5fd6a354e71a7de2b5644e652ca5147", + }, + { + "version": "0.13.4", + "sha256": "a92df4a151d390144040de5d18351301e597d3fae3679a814ea57554f6aa9b24", + }, + { + "version": "0.13.3", + "sha256": "35c662be9d32d38815cde5fa4c9fa61a3b7f39952ecd50ebf92fd1b2ddd6109b", + }, + { + "version": "0.13.0", + "sha256": "9ed437560faf084c18716e289ea712c784a514bdd7f2796549c735d439dbe378", + }, +] + +def terraform_binaries(): + for release in TERRAFORM_RELEASES: + maybe( + http_archive, + name = "terraform_{}_linux_amd64".format(release["version"]), + build_file_content = "exports_files([\"terraform\"])", + sha256 = release["sha256"], + urls = ["https://releases.hashicorp.com/terraform/{}/terraform_{}_linux_amd64.zip".format(release["version"], release["version"])], + ) + +def terraform_images(): + for release in TERRAFORM_RELEASES: + container_image( + name = release["version"], + base = "@distroless//image", + cmd = "help", + directory = "/bin/", + entrypoint = ["/bin/terraform"], + files = ["@terraform_{}_linux_amd64//:terraform".format(release["version"])], + mode = "0o755", + repository = "quay.io/hadrienpatte", + ) + + container_push( + name = "{}_push".format(release["version"]), + format = "Docker", + image = ":{}".format(release["version"]), + registry = "quay.io", + repository = "hadrienpatte/terraform", + tag = release["version"], + )