Skip to content

Instantly share code, notes, and snippets.

@WhatsARanjit
Created August 16, 2023 16:39
Show Gist options
  • Save WhatsARanjit/ca112c164ad8598f48fb5aebe9f5a0b9 to your computer and use it in GitHub Desktop.
Save WhatsARanjit/ca112c164ad8598f48fb5aebe9f5a0b9 to your computer and use it in GitHub Desktop.
Terraform external data source
if [ -f "dontdoit" ]; then
RESULT="true"
else
RESULT="false"
fi
echo "{ \"check\": \"$RESULT\" }"
data "external" "check_for_file" {
program = [ "bash", "check.sh" ]
}
resource "null_resource" "helloworld" {
count = data.external.check_for_file.result.check == "true" ? 0:1
}
$ 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