'Terraform - data depends-on data
I am using data external and data local_file in my terraform code. data external executes a script and create a json file. Now my data local_file has to read the json file.
data "external" "example" {
program = ["python", "XXXXX.py", "${var.fileName}"]
}
data "local_file" "dashboard" {
filename = "${path.module}/dashboardData.json"
}
Here data local_file is dependent on data external for the json file.
Is there a work aroud ?
Solution 1:[1]
If you want to force terraform to defer evaluating one value until after another is known, and there isn't an existing data source that covers your use case, you can use null_data_source as a stand-in.
data "null_data_source" "dashboard_file" {
depends_on = [ "data.external.example.result" ]
inputs = {
name = "${path.module}/dashboardData.json"
}
}
When the dependencies are met, terraform will evaluate all the inputs of the null_data_source, do nothing, and then expose all the results as outputs.
Now, you can refer to data.null_data_source.dashboard_file.outputs.name, and terraform knows that it must first compute data.external.example.result before it's allowed to use that value.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
