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

resourcemanager/resourceids: adding a Match function #234

Merged
merged 2 commits into from
May 6, 2024

Conversation

tombuildsstuff
Copy link
Member

The Match function takes two instances of the ResourceId type and allows comparing the parsed segments for these.

Whilst this is also possible by comparing the value of .ID() in both instances - that's not case-aware and so will be problematic in the future - hence the need for this function which can account for case-aware comparisons.

This also exposed a feature-flag for treating User Specified Segments as case-insensitive for comparison purposes - however this isn't usable at this time and so must not be exposed as a toggle at this point-in-time, since it'll cause more problems than it solves. However having this internal-only feature flag allows us to built out the surrounding components ahead-of-time and add tests covering both scenarios - therefore this is beneficial to have as an internal toggle today - even if it's not usable for end-users for some time.

There are currently 6 instances of this across the Provider:

Screenshot 2024-05-06 at 13 02 05

in addition to (at least) hashicorp/terraform-provider-azurerm#25809 - therefore we should get ahead of this and switch to using resourceids.Match to enable us to handle this consistently in the future.

The `Match` function takes two instances of the ResourceId type and allows comparing the parsed segments for these.

Whilst this is also possible by comparing the value of `.ID()` in both instances - that's not case-aware and so will be problematic
in the future - hence the need for this function which can account for case-aware comparisons.

This also exposed a feature-flag for treating User Specified Segments as case-insensitive for comparison purposes - however
this isn't usable at this time and so MUST NOT be exposed as a toggle at this point-in-time, since it'll cause more problems
than it solves. However having this internal-only feature flag allows us to built out the surrounding components ahead-of-time
and add tests covering both scenarios - therefore this is beneficial to have as an internal toggle today - even if it's not
usable for end-users for some time.
@tombuildsstuff tombuildsstuff requested a review from a team May 6, 2024 11:09
Copy link
Member

@stephybun stephybun left a comment

Choose a reason for hiding this comment

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

Thanks @tombuildsstuff I have two questions around the case insensitive flag, otherwise LGTM 👍

resourcemanager/features/user_specified_segments.go Outdated Show resolved Hide resolved
//
// There are a number of dependencies to enabling this, including completing the standardiation on the
// `ResourceId` interface and the `ResourceIDReference` schema types - and surrounding updates.
var TreatUserSpecifiedSegmentsAsCaseInsensitive = false
Copy link
Member

Choose a reason for hiding this comment

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

Despite the comment I could still see this creeping into places where it shouldn't in the provider. Would it make sense and/or be possible for this to be accompanied by a check in the provider to flag new additions of this?

Copy link
Member Author

Choose a reason for hiding this comment

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

By this, do you mean a check in the Provider to ensure that we're not doing .ID() ==? If so, yes - that can be added at the same time as fixing the 6 instances above

Copy link
Member

Choose a reason for hiding this comment

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

I actually mean a check in the Provider to ensure we're not setting features.TreatUserSpecifiedSegmentsAsCaseInsensitive = true unless it's been explicitly added to a list of exceptions, like we do with these checks

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, makes sense - we probably want both checks actually.

It's worth noting that since this feature-flag is for the behaviour as a whole (i.e. across the entire Provider) rather than being for individual Resource ID types - we'd only set this one-time rather than in multiple places anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

For info: I've intentionally not included the validation changes in hashicorp/terraform-provider-azurerm#25873 since this wants to be done in a follow up PR - will send that in the morning:

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.

None yet

2 participants