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

Output variable refresh bug #388

Merged
merged 2 commits into from
Jul 7, 2021
Merged

Output variable refresh bug #388

merged 2 commits into from
Jul 7, 2021

Conversation

bengesoff
Copy link
Contributor

  • Output variable refresh bug: I added a CustomizeDiff function to the service resource to mark the cloned_version and active_version attributes as recomputed when any of the other attributes change (with the exception of name, comment and version_comment). This solves the problem where an output variable referencing these attributes wouldn't be updated after an apply and would require another apply or refresh for this to propagate through.
  • Removed StateFuncs from all of the logging blocks as these were causing unnecessary whitespace diffs for the CustomizeDiffs and forcing the tests to fail with non-empty plans (the version was being marked as recomputed). I couldn't find any adverse effects from doing this, but would appreciate some confirmation here as there were a lot of comments about a known issue and there might have been a good reason that they were added in.

@bengesoff
Copy link
Contributor Author

Rebased onto master, just going to retest

@bengesoff
Copy link
Contributor Author

Full acceptance test suite passing for me ✅

@Integralist Integralist requested review from a team and Integralist and removed request for a team April 6, 2021 08:55
Copy link
Collaborator

@Integralist Integralist left a comment

Choose a reason for hiding this comment

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

LGTM but going to request another Terraform SME who has historical context to take a look as well.

@Integralist Integralist requested review from phamann and mccurdyc April 6, 2021 09:25
@Integralist Integralist added the bug label Apr 6, 2021
@mccurdyc
Copy link
Collaborator

mccurdyc commented Apr 8, 2021

Hmm it's hard to remember why we did this, trying to find context:

@Integralist
Copy link
Collaborator

This was discussed internally.

@bengesoff will attempt to replicate issue with logging blocks, and if is unable to replicate we'll be OK proceeding with the understanding that this PR will include extra documentation to explain to users how to trim whitespace for their keys if this indeed does bubble back up as an issue in the future.

@phamann phamann removed their request for review April 14, 2021 10:00
@bengesoff
Copy link
Contributor Author

Update from my logging whitespace investigations:

As feared, the API handling of whitespace in the PEM blobs doesn’t appear to be consistent. It appears that at least Elasticsearch and Kafka logging both strip the whitespace off, whereas BigQuery and others preserve whatever is given to them. This means that the trimSpaceStateFunc does have some effect, but only in a small proportion of the cases in which it’s used.

The result of this being that we essentially have three options:

  • Stick with the fix of deleting the StateFuncs everywhere and document the need for trimspace() if the strings have whitespace
  • Keep the StateFuncs in and close the PR, which will leave the output variable refresh bug at large (due to CustomiseDiff not being an option in this case)
  • Pass on the inconsistency to the relevant team at Fastly responsible for these APIs and get the best of both worlds

@bengesoff
Copy link
Contributor Author

In addition to the first bullet point of my previous comment: we could also augment the documentation with a ValidateFunc to ensure that trimspace() has been used, e.g.

func validateStringTrimmed(value interface{}, p cty.Path) diag.Diagnostics {
	if value != strings.TrimSpace(value.(string)) {
		return diag.FromErr(p.NewErrorf("string must not contain trailing whitespace"))
	}

	return nil
}

This might be a good alternative to removing the StateFunc altogether as it will lead to a good error message.

@Integralist
Copy link
Collaborator

Hi @bengesoff

I was discussing this in more detail with @phamann and we came to the conclusion that regardless of what we do in the Terraform provider, the backend APIs need to be consistent by trimming excess whitespace.

Additionally Patrick wondered if we could maybe utilise DiffSupressFunc (instead of ValidateFunc) and have the diff function check a trim of the relevant cert/key attribute, i.e. it's comparing a trimmed version of the HCL input against a trimmed version of the state stored value, so we would only show a diff if there was actually a difference.

But again, we'd still need the data to be stored Fastly's side trimmed.

Let me know you thoughts.

@bengesoff
Copy link
Contributor Author

Hi @Integralist

Just to clarify, you guys reckon the direction is to always trim rather than never trim the whitespace?

I did try the DiffSuppressFunc actually, with the same idea but unfortunately it won't work. It comes back to the TypeSet problem where TF thinks the whole block is being created/deleted 😞 certainly an attractive idea though as otherwise we'll still have to push the burden onto the user

@Integralist
Copy link
Collaborator

@bengesoff OK no worries, thanks for that feedback.

re:

always trim rather than never trim the whitespace?

The thinking here is that only the BigQuery and GCS endpoints are different, and so adding trimming to those endpoints is a smaller blast radius than the reverse which would be removing trimming from everywhere. If the APIs do this then it would mean we'd use your ValidateFunc suggestion and have this change as part of a v1 release as this change would be 'breaking' in the sense that we're now forcing the requirement to trim the content back onto users where before it was handled internally by the provider.

@bengesoff
Copy link
Contributor Author

That makes sense, fair enough! Are you waiting for a final decision on this still?

@Integralist
Copy link
Collaborator

That makes sense, fair enough! Are you waiting for a final decision on this still?

Yup! There's an internal ticket that I'm following to see how this progresses. I'll let you know whenever we have an update.

@Integralist
Copy link
Collaborator

@bengesoff FYI - might not affect this PR but the master branch is now named main.

bengesoff added 2 commits July 7, 2021 09:43
…oned_version and active_version attributes will be recomputed

Also had to fiddle with some trimspace() on the BigQuery Logging block as the new custom diffs were failing with the StateFunc there. This needs a more permanent solution but it has got things passing for now.
@Integralist Integralist removed the v1.0.0 label Jul 7, 2021
@Integralist
Copy link
Collaborator

This PR should now be safe without having to wait for our internal API work (thanks to #439).

@Integralist Integralist merged commit ba6a3db into fastly:main Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants