Skip to content

Commit

Permalink
Merge pull request #5 from theothertomelliott/fix_provider_downloads
Browse files Browse the repository at this point in the history
Fix for allow_provider_download
  • Loading branch information
theothertomelliott authored Apr 15, 2024
2 parents f83e78f + 64016c2 commit d18d29e
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protobuf_deps()
load("@tf_modules//terraform:versions.bzl", "register_terraform_version")

register_terraform_version(
"1.2.9",
"1.7.5",
default = True,
)

Expand Down
3 changes: 2 additions & 1 deletion rules/terraform.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ disable_checkpoint = true
TF=$(pwd)/$TF_RELATIVE
cd $WORKING_DIR
mkdir .terraform
mkdir -p .terraform
mkdir -p terraform.d/plugins
touch $TF_LOCK # ensure the lock file exists (older Terraform versions don't create it)
$TF init -backend=false
Expand Down
22 changes: 22 additions & 0 deletions tests/allow_provider_download/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("@tf_modules//rules:module.bzl", "terraform_module")
load("@tf_modules//rules:terraform.bzl", "terraform_working_directory")

terraform_module(
name = "provider",
srcs = ["main.tf"],
visibility = ["//visibility:public"],
)

terraform_working_directory(
name = "terraform",
module = ":provider",
allow_provider_download = True,
)

sh_test(
name = "terraform_test",
size = "small",
srcs = ["test.sh"],
data = [":terraform"],
)

13 changes: 13 additions & 0 deletions tests/allow_provider_download/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
terraform {
required_providers {
local = {
source = "hashicorp/local"
version = ">= 2.4.1"
}
}
}

resource "local_file" "foo" {
content = "foo!"
filename = "${path.module}/foo.bar"
}
25 changes: 25 additions & 0 deletions tests/allow_provider_download/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

OUT=$(./tests/allow_provider_download/terraform plan -no-color)
if [ $? -ne 0 ];
then
echo 'Plan failed';
exit 1
fi

PASS=1

function expect_output() {
if [[ "$OUT" != *"$1"* ]]; then
echo "FAIL: Expected text '$1'"
PASS=0
fi
}

expect_output "+ resource \"local_file\" \"foo\" {"
expect_output "1 to add"

if [[ $PASS == 0 ]]; then
echo "$OUT"
exit 1
fi

0 comments on commit d18d29e

Please sign in to comment.