Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should add I was confused by the above logic for returning early if 'unknown' as the attribute has to be marked as both computed and optional so that the user can configure a value while the provider can set a value if none is provided by the user, and so the PlanValue will naturally be 'unknown' or 'known'.
If it's known (e.g. the user provided a value), then of course return early and don't set a value. But if the value is 'unknown' (e.g. the user didn't provide a value), then returning early here will mean you have to programmatically check in the resource's
Create
method and set the default there (making this whole implementation sort of pointless from a 'I need to set a default' perspective).So for myself I modified the value like so:
Integralist/terraform-provider-fastly-framework@35d10ec#diff-5dba0fe3376c40571fbc1323ead12e5626199bed5a36e4c9f217e3d9aced8cabR36-R37
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unknown values can come from two main sources:
Computed
attributes with a null configuration value during planning to prevent a class ofinconsistent result after apply
Terraform errorsIt can be incorrect in the latter scenario to unilaterally change the planned value to a default value when the planned value is unknown, since it may be an artifact of the way the configuration is written. Terraform would raise an error if the plan was set to the default and the incoming configuration value was different.
This code example might be best served with an update to check
!req.ConfigValue.IsNull()
for clarity (and to allow prior plan modification to set a null plan value successfully), but it might be best to create a separate issue/PR to discuss this type of example change further.