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

Ensure schema.Set uses custom SetDiff algorithm #366

Merged
merged 62 commits into from
Feb 23, 2021

Conversation

Integralist
Copy link
Collaborator

@Integralist Integralist commented Feb 10, 2021

Background: we implemented SetDiff to identify when two elements across distinct sets have the same key. This helps avoid recreating an element (i.e. DELETE, then CREATE) which only needs an UPDATE.

Problem: not all schema.Set objects are using the SetDiff algorithm.

Caveats: there is a separate concern with some resources being deleted/recreated. Specifically resources that require a lookup key of "name" and who are also expecting the name field to be updated (e.g. updating the name of an ACL). This will be addressed in a separate PR.

Notes: I've not updated block_fastly_waf_configuration_v1_active_rule.go as it appears to be doing some kind of filtering of data which would be incompatible with the SetDiff implementation. Nor have I updated the block_fastly_waf_configuration_v1_exclusion.go as the nested structuring of the resources was quite complicated to follow and so it was safer not to mess with it for now.

@Integralist Integralist requested review from phamann, a team and triblondon and removed request for a team February 10, 2021 14:53
Copy link
Contributor

@triblondon triblondon left a comment

Choose a reason for hiding this comment

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

I'm not qualified to comment on this so if Patrick can review that would be really appreciated!

Copy link
Member

@phamann phamann left a comment

Choose a reason for hiding this comment

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

Hey @Integralist. Thanks for doing this, its been a very long-running need in the project!

I started reviewing but soon realised you haven't added the Update code path for any of the resources just Add and Delete, hence using the current implementation any updates to resources will not be applied and is the core benefit of moving to this pattern - this may also be why you have failing tests.

Use the backend block as the example, specifically these lines: https://github.com/fastly/terraform-provider-fastly/blob/master/fastly/block_fastly_service_v1_backend.go#L75-L92

Hope that helps :)

@Integralist
Copy link
Collaborator Author

FYI @phamann in the latest commit ee842ed I've added some documentation around the caveats I encountered and for which we discussed offline. I didn't want those to get missed in the review as I feel they're important to call out.

@Integralist Integralist force-pushed the integralist/fix_terraform_domain_diff_bug branch from 083299d to a7a87c9 Compare February 11, 2021 15:02
@Integralist Integralist force-pushed the integralist/fix_terraform_domain_diff_bug branch from a7a87c9 to 5892307 Compare February 11, 2021 15:07
@Integralist Integralist force-pushed the integralist/fix_terraform_domain_diff_bug branch from 7d550d0 to 6651cd8 Compare February 11, 2021 18:01
@Integralist Integralist force-pushed the integralist/fix_terraform_domain_diff_bug branch from 6651cd8 to b314973 Compare February 11, 2021 18:02
@Integralist Integralist force-pushed the integralist/fix_terraform_domain_diff_bug branch from b624ac6 to c0b3ac0 Compare February 17, 2021 12:34
@Integralist Integralist force-pushed the integralist/fix_terraform_domain_diff_bug branch from 0238b74 to 3e089e1 Compare February 19, 2021 10:14
@Integralist Integralist requested a review from phamann February 19, 2021 10:27
@Integralist
Copy link
Collaborator Author

@phamann I've updated the PR description to reflect the files I'm not including (for various reasons).

@Integralist
Copy link
Collaborator Author

@pschulte @bridgetlane 👋🏻 I'm looking for other engineers experienced with either our terraform provider or terraform in general to give a review of this PR.

Copy link
Member

@phamann phamann left a comment

Choose a reason for hiding this comment

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

👍🏻 Looking good - there are a couple of minor questions, some things to double check and some inconsistencies. However approving now to unblock you.

I left most comments inline, however a couple of other overarching observations:

  • It seems there is some inconsistency when you've chosen to note in the public documentation about the lack of ability to update a name. For instance non of the logging endpoints have this note - Is this intentional? I'd suggest we do this everywhere if we are going to do it.
  • The original implementation of this pattern in fastly/block_fastly_service_v1_backend.go abstracted the building of the update struct fields to a buildUpdateBackendInput() method, and you've inlined the logic into Process()- I personally feel the former pattern makes process easier to read/grok and enables us to unit test the update logic with mock data if we want in the future.

Co-authored-by: Patrick Hamann <patrick@fastly.com>
@Integralist
Copy link
Collaborator Author

re:

The original implementation of this pattern in fastly/block_fastly_service_v1_backend.go abstracted the building of the update struct fields to a buildUpdateBackendInput() method, and you've inlined the logic into Process()- I personally feel the former pattern makes process easier to read/grok and enables us to unit test the update logic with mock data if we want in the future.

That's reasonable. I've made a ticket for doing this work in a separate PR.

@Integralist Integralist merged commit a072645 into master Feb 23, 2021
@Integralist Integralist deleted the integralist/fix_terraform_domain_diff_bug branch February 23, 2021 17:35
@Integralist Integralist added the enhancement New feature or request label Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants