docs(webhook,work-pool): example for jsonencoding file input #350
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.
resolves #259
in #340, @mitchnielsen updated our baseJobTemplate handling to rely on the json.NormalizedType semantic equality checking. By definition, this type should do the following:
however, there is an edge case with
file()
+ resource imports, as our provider logic's equality checking only kicks in after the provider framework computes plan diffs (diff check = compare HCL to State object). Therefore, when importing a resource + usingfile()
, you will still get plan diffs from inconsequential whitespace changes:when we use
file()
, the framework interprets this input as raw, non-normalized byte strings. so when we import a resource:Read()
the existing API object, save the value to State - this includes thebase_job_template
string for example as ajson.NormalizedType
terraform plan
will read our HCL, which usesfile()
- this is pulled in as the raw byte string, without any knowledge that this is normalized JSONjson.NormalizedType
semantic equality check can be performed and deemed a no-opThis diff behavior is better explained by this comment in the TF core repo, stating that
file()
inputs can only be evaluated via exact character matching due to how different OS-es handled file encodingshashicorp/terraform#23928 (comment)
If we want to be able to treat
file()
as semantically equal to their JSON representations in a remote environment, there's a few ways to do this via PlanModifiers. But, I'd like to first expand our documented cases to suggest wrappingfile()
with ajsonencode(jsondecode(file(...)))
chain, which achieves this same effect for our users. This is a pattern surfaced in one of the AWS providershashicorp/terraform-provider-aws#25340 (comment)
Essentially, we're coercing the file input to be normalized JSON via
jsonencode()
-- this will allow our underlying type system to do what we'd expect moving forward, and result in a no-op after an import