Created
August 16, 2023 16:39
-
-
Save WhatsARanjit/ca112c164ad8598f48fb5aebe9f5a0b9 to your computer and use it in GitHub Desktop.
Terraform external data source
This file contains hidden or 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
if [ -f "dontdoit" ]; then | |
RESULT="true" | |
else | |
RESULT="false" | |
fi | |
echo "{ \"check\": \"$RESULT\" }" |
This file contains hidden or 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
data "external" "check_for_file" { | |
program = [ "bash", "check.sh" ] | |
} | |
resource "null_resource" "helloworld" { | |
count = data.external.check_for_file.result.check == "true" ? 0:1 | |
} |
This file contains hidden or 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
$ terraform plan | |
data.external.check_for_file: Reading... | |
data.external.check_for_file: Read complete after 0s [id=-] | |
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: | |
+ create | |
Terraform will perform the following actions: | |
# null_resource.helloworld[0] will be created | |
+ resource "null_resource" "helloworld" { | |
+ id = (known after apply) | |
} | |
Plan: 1 to add, 0 to change, 0 to destroy. | |
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── | |
Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now. | |
$ touch dontdoit | |
$ terraform plan | |
data.external.check_for_file: Reading... | |
data.external.check_for_file: Read complete after 0s [id=-] | |
No changes. Your infrastructure matches the configuration. | |
Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed. | |
$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment