Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: Add support for unknown value refinement data to all types #1062

Draft
wants to merge 41 commits into
base: main
Choose a base branch
from

Conversation

austinvalle
Copy link
Member

@austinvalle austinvalle commented Dec 3, 2024

Closes #869

Ref: hashicorp/terraform#30937
Ref: hashicorp/terraform-plugin-go#448


This PR introduces value refinement support to the basetypes Go package, which allows Framework providers to communicate unknown value refinements to/from Terraform core (first introduced in Terraform 1.6).

Value refinements are additional constraints that can be applied to unknown values in Terraform that can be used to produce known results from unknown values. For example, with value refinements, providers can now indicate specific attributes will "definitely not be null" during PlanResourceChange, which would allow Terraform core to successfully evaluate expressions like count during plan:

resource "examplecloud_thing" "a" {
  # Has a computed attribute (id) where the final value will not be null
}
resource "examplecloud_thing" "b" {
  // Will successfully evaluate during plan with a "not null" refinement on "id"
  count = examplecloud_thing.a.id != null ? 1 : 0
}

Without unknown value refinements, the above config will return an error when running terraform plan:

│ Error: Invalid count argument
│
│ ...
│
│ The "count" value depends on resource attributes that cannot be
│ determined until apply, so Terraform cannot predict how many
│ instances will be created. To work around this, use the -target
│ argument to first apply only the resources that the count depends
│ on.

No changes to existing provider code will be necessary as partially unknown values will still evaluate the same as a wholly unknown value today.

TODOs left on this PR

  • Design is still under review
  • Couple open items to investigate
    • Double check the Dynamic paths with refinements. There shouldn't be any changes needed since it's just a container (and dynamic itself cannot have a refinement)
    • Double check the int vs. float refinements (int attributes could possible receive a floating point number in a refinement, need to determine how we should handle that)
  • Website documentation
  • Update to use released version of terraform-plugin-go, once that's ready
  • Changelogs

@austinvalle austinvalle added enhancement New feature or request types Issues and pull requests about our types abstraction and implementations. labels Dec 3, 2024
@@ -6,7 +6,7 @@ toolchain go1.22.7

require (
github.com/google/go-cmp v0.6.0
github.com/hashicorp/terraform-plugin-go v0.25.0
github.com/hashicorp/terraform-plugin-go v0.25.1-0.20241126200214-bd716fcfe407
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: update with released version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request types Issues and pull requests about our types abstraction and implementations.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider allowing providers to refine unknown values as "definitely not null"
1 participant