Loading...
Loading...
### Terraform Version ```shell 1.0.11, 1.8.5, 1.10.5 (doesn't occur in Terraform 0.12.31) ``` ### Terraform Configuration Files I have a custom Terraform resource and Terraform provider, let's call it `custom_resource_dbinstance`. In schema, it has multiple properties, like `database_id`, `engine_version`, `db_version`. I treat `database_id` and `engine_version` as inputs, and `db_version` property as output - it has `Computed: true` set in schema configuration, and I update its value in ReadContext, CreateContext and UpdateContext. Then, with the use of the custom provider, I have the Terraform configuration as below. In `main.tf`, I have: ```terraform resource "custom_resource_dbinstance" "db" { database_id = "agatest" engine_version = "14.0.0" } ``` In `outputs.tf`, I have: ```terraform output "DBVersion" { value = custom_resource_dbinstance.db.db_version } output "DatabaseEngineVersion" { value = custom_resource_dbinstance.db.engine_version } ``` After apply, `DBVersion` output is set to `14.12` (so far, as expected, computed correctly and has the same value as `db_version` property in tf state), and `DatabaseEngineVersion` is set to `14.0.0`. Then, I change the Terraform configuration below and perform terraform apply. In `main.tf`, I have: ```terraform resource "custom_resource_dbinstance" "db" { database_id = "agatest" engine_version = "14.1.0" } ``` In `outputs.tf`, I have: ```terraform output "DBVersion" { value = custom_resource_dbinstance.db.db_version } output "DatabaseEngineVersion" { value = custom_resource_dbinstance.db.engine_version } ``` Underneath, my computation changes `db_version` property in tf state to `14.15`. However, after apply, `DBVersion` output is still set to `14.12` (I expected it to be set to `14.15`, the same as `db_version` property in tf state), and `DatabaseEngineVersion` is set to `14.1.0` (ok). ### Debug Output ``` ...debug output, or link to a gist... ``` ### Expected Behavior After the second apply, I would expect `DBVersion` output value to be `14.15`, the same as `db_version` property value in tf state. This is how Terraform 0.12.31 behaved for me (I recently upgraded to 1.8.5). ### Actual Behavior After the second apply, the `DBVersion` output value is `14.12`, which is the same as the pervious `db_version` property value in tf state. Only when I execute third `terraform apply`, Terraform sees the difference and tries to update the output value. ``` Changes to Outputs: ~ DBVersion = "14.12" -> "14.15" ``` It seems that the output values are determined at the start of `terraform apply`, not at the end, when my `custom_resource_dbinstance` resource is updated. ### Steps to Reproduce 1. `terraform init` 2. `terraform apply` 3. Change `engine_version` input value. 4. `terraform apply` 5. `custom_resource_dbinstance.db.db_version` computed value changes and is visible in terraform state, but the output value based on `custom_resource_dbinstance.db.db_version` is still the same as after point 2. ### Additional Context _No response_ ### References _No response_ ### Generative AI / LLM assisted development? ChatGPT 3.5. My question: "Terraform 1.0 doesn't seem to treat computed properties of a resource as dependencies for the output. What would you suggest to do so that the output value is updated correctly after "terraform apply"?" Meaningful parts of the response: 1. Direct Reference: Ensure that your output is directly referencing the computed property. If the computed property itself changes, this should trigger an update to the output. ```terraform resource "aws_instance" "example" { # resource configuration } output "computed_property" { value = aws_instance.example.some_computed_property } ``` 2. Custom Null Resource: Create a null_resource that triggers when you expect changes, and reference this in your output. This can force Terraform to reevaluate the output when the null_resource changes. ```terraform resource "null_resource" "trigger" { triggers = { always_run = "${timestamp()}" } } output "computed_property" { value = aws_instance.example.some_computed_property depends_on = [null_resource.trigger] } ``` 3. Use of depends_on : If your output relies on a resource or module that might not directly change but could affect the output, you can use depends_on to force the output to wait for certain resources to complete. ```terraform output "example_output" { value = module.some_module.some_output depends_on = [aws_instance.example] } ``` None of the above worked.
Click on a version to see all relevant bugs
Terraform Integration
Learn more about where this data comes from
Bug Scrub Advisor
Streamline upgrades with automated vendor bug scrubs
BugZero Enterprise
Wish you caught this bug sooner? Get proactive today.