forked from dvulpe/bazel-terraform-rules
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for creating backend files at runtime
Add a "reconfigure" param for working directories that force an init for each command. Add a provider for working directories to provide paths to the actual module.
- Loading branch information
1 parent
d18d29e
commit 2a80a25
Showing
4 changed files
with
109 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
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, | ||
reconfigure = True, | ||
) | ||
|
||
sh_test( | ||
name = "terraform_test", | ||
size = "small", | ||
srcs = ["test.sh"], | ||
data = [":terraform"], | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash | ||
|
||
STATE_DIR=$(mktemp -d) | ||
|
||
MODULE_DIR=./tests/backend_init/terraform_working/tests/backend_init | ||
|
||
BACKEND_FILE="$MODULE_DIR/local_backend.tf" | ||
cat > "$BACKEND_FILE" <<-EOF | ||
terraform { | ||
backend "local" { | ||
path = "$STATE_DIR/terraform.tfstate" | ||
} | ||
} | ||
EOF | ||
|
||
if [ -f $STATE_DIR/terraform.tfstate ]; then | ||
echo "Temp tfstate file should not exist before apply" | ||
exit 1 | ||
fi | ||
|
||
OUT=$(./tests/backend_init/terraform apply -auto-approve -no-color) | ||
if [ $? -ne 0 ]; | ||
then | ||
echo 'Apply 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 | ||
|
||
if [ ! -f $STATE_DIR/terraform.tfstate ]; then | ||
echo "Temp tfstate file should exist after apply" | ||
exit 1 | ||
fi |