Having a trouble referencing a json file that is to be generated by null-resource local-exec.
Here is the snippet of the resource creating the file:
resource "null_resource" "clusterDO" {
provisioner "local-exec" {
command = "cat > DO_template.json <<EOL\n ${module.bigip.onboard_do}\nEOL"
}
depends_on = [module.bigip.onboard_do]
}
Here is the snippet of the definition causing the error:
resource "bigip_do" "do-example" {
do_json = "${file("DO_template.json")}"
timeout = 120
depends_on = [module.bigip_module]
}
Here is a snippet of the error:
Invalid value for "path" parameter: no file exists at "DO_template.json"; this function works only with files that are distributed as part of the configuration source code, so if this file will be
│ created by a resource in this configuration you must instead obtain this result from an attribute of that resource.
I understand from the error that I can't reference the filename as is, not sure how to make it work, can someone provide an operational example?
Attempted to create the filename as a triggers in the null_resource and then reference it, but I'm getting the same error
You can fix this by using the
templatefilebuilt-in function [1] andlocal_file[2] instead:Then, you would need to slightly adjust the JSON template (now called
DO_template.json.tpl):[1] https://developer.hashicorp.com/terraform/language/functions/templatefile
[2] https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file#schema