Skip to content

Make exclude_folders and exclude_projects use sets and use for_each to avoid unnecessary resource updates #32

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

Conversation

MajorBreakfast
Copy link
Contributor

Currently, when adding new excluded folders or projects in to the middle of the list, Terraform shows unnecessary changes due to index shifts. With this change, this no longer happens. This makes it possible to order the exclusions alphabetically without getting unnecessary changes in the plan.

@MajorBreakfast MajorBreakfast requested review from averbuks, ludoo and a team as code owners March 19, 2020 10:24
@MajorBreakfast MajorBreakfast force-pushed the exlusion-sets-instead-of-lists branch from 391a77b to 57626ca Compare March 19, 2020 10:28
@MajorBreakfast
Copy link
Contributor Author

Could you provide me the details why this does not pass? I don't have access

@MajorBreakfast
Copy link
Contributor Author

@bharathkkb could you maybe have a look again? ^^'

@bharathkkb
Copy link
Member

@MajorBreakfast thanks for the contribution

It is failing due to a problem on our end that we are working to resolve. @morgante PTAL

@MajorBreakfast
Copy link
Contributor Author

Any progress on this? The reshuffling makes it so that we get 409 errors whenever we add an exclusion to the middle of the list. That's inconvenient

@bharathkkb
Copy link
Member

@MajorBreakfast CI problems on our end have been resolved and since tests were not passing I tried debugging- left some comments with my findings.
you can execute the tests locally as described here

@MajorBreakfast
Copy link
Contributor Author

Tests are green now

@bharathkkb
Copy link
Member

@MajorBreakfast LGTM overall. nit: I assume the locals like exclude_folders_list_length are not used anymore? They are still in main.tf

@MajorBreakfast
Copy link
Contributor Author

Yep. The search confirms that they‘re unused. I removed them

@MajorBreakfast
Copy link
Contributor Author

@morgante can you have a look?

@MajorBreakfast
Copy link
Contributor Author

@bharathkkb ping

@bharathkkb
Copy link
Member

@morgante PTAL

Copy link
Contributor

@morgante morgante left a comment

Choose a reason for hiding this comment

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

Sorry for the delay on this.

My main concern here is that by switching to for_each we will make it impossible to reference dynamically created folders/projects. ie it will be impossible to create a folder and apply an org policy to it in the same execution.

@MajorBreakfast
Copy link
Contributor Author

@morgante The old code computed the length via length(compact(var.exclude_folders)) which means the length was also computed before. Are you sure that this change could break in more scenarios? And if so, could you provide an example?

@morgante
Copy link
Contributor

You're right, it should have the same behavior now.

@morgante morgante merged commit 5d552af into terraform-google-modules:master Apr 14, 2020
@MajorBreakfast
Copy link
Contributor Author

MajorBreakfast commented Aug 4, 2020

@morgante This PR might have a problem. The size of the set depends on how many unique values there are. This means the size cannot be known statically if one or more entires are only known dynamically (e.g. in case it comes from a resource attribute). This makes the value not allowed in a for_each. I haven't looked deeply into this, but it I just came across a similar scenario and wanted to mention it here.

@morgante
Copy link
Contributor

morgante commented Aug 5, 2020

Yeah that's unfortunately true. I don't think there's any easy fix though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants