Created
November 6, 2023 13:22
-
-
Save WhatsARanjit/6577c98e9bfc81a667f0f2d77efbe124 to your computer and use it in GitHub Desktop.
TF conditional provisioner
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
variable "switch" { | |
default = true | |
} | |
locals { | |
prov_cmd = var.switch ? "echo 'YES'" : "echo 'NO'" | |
} | |
resource "null_resource" "test" { | |
provisioner "local-exec" { | |
command = local.prov_cmd | |
} | |
} |
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
$ TF_VAR_switch=false terraform apply --auto-approve | |
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.test will be created | |
+ resource "null_resource" "test" { | |
+ id = (known after apply) | |
} | |
Plan: 1 to add, 0 to change, 0 to destroy. | |
null_resource.test: Creating... | |
null_resource.test: Provisioning with 'local-exec'... | |
null_resource.test (local-exec): Executing: ["/bin/sh" "-c" "echo 'NO'"] | |
null_resource.test (local-exec): NO | |
null_resource.test: Creation complete after 0s [id=8525017274064731153] |
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
$ terraform apply --auto-approve | |
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.test will be created | |
+ resource "null_resource" "test" { | |
+ id = (known after apply) | |
} | |
Plan: 1 to add, 0 to change, 0 to destroy. | |
null_resource.test: Creating... | |
null_resource.test: Provisioning with 'local-exec'... | |
null_resource.test (local-exec): Executing: ["/bin/sh" "-c" "echo 'YES'"] | |
null_resource.test (local-exec): YES | |
null_resource.test: Creation complete after 0s [id=1591540309584719601] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment