Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: mark invalid UUIDs as known#148

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ethanndickson merged 2 commits intomainfromethan/uuid-fix
Nov 28, 2024
Merged

Conversation

ethanndickson
Copy link
Member

@ethanndicksonethanndickson commentedNov 27, 2024
edited
Loading

When I first implemented the UUID Terraform type, I followed the example fromterraform-provider-aws for durations:Source. This example doesn't quite make sense, or at the least isn't applicable to our use-case, and since it was used as a base for our custom data type, resulted in UUIDs not being validated when written as strings in a configuration.

i.e. This function is called by the plugin SDK, when reading the config.

func (t durationType) ValueFromString(_ context.Context, in types.String) (basetypes.StringValuable, diag.Diagnostics) {       [...]valueString := in.ValueString()if _, err := time.ParseDuration(valueString); err != nil {return DurationUnknown(), diags // Must not return validation errors}       [...]}

Meanwhile, this function is called duringvalidate/plan/apply:

func (v Duration) ValidateAttribute(ctx context.Context, req xattr.ValidateAttributeRequest, resp *xattr.ValidateAttributeResponse) {if v.IsNull() || v.IsUnknown() {return}}

This means if the duration couldn't be parsed, the value becomes unknown, and then is never validated, and so the provider just sees an Unknown value instead of an error diagnostic.

It's worth noting that youcannot remove theIsUnknown check from a validate function, as Terraform purposefully calls validate functions with unknown values when the attribute is set using a variable. The idea being to validate a config before and after any variables are populated. Therefore the only solution here is to return aknown,valid value, if the UUID couldn't be parsed, as to let the validator handle it.

A similar data type is implemented in such a way that meets our use case forarn interraform-provider-aws, which has been used as a guide for this fix:Source. In this provider, if an ARN can't be parsed, a valid & known value is returned fromValueFromString.

More importantly, I made the mistake of not testing the UUID type failing to parse in the context of a resource / data source. I only wrote internal unit tests for the type. This PR adds a test that ensures an error diagnostic is returned if an invalid UUID is provided to a resource/data-source UUID attribute, which tells us the problem is fixed.

@ethanndicksonGraphite App
Copy link
MemberAuthor

This stack of pull requests is managed byGraphite. Learn more aboutstacking.

@ethanndicksonethanndickson merged commitf7eec90 intomainNov 28, 2024
14 checks passed
@ethanndicksonethanndickson deleted the ethan/uuid-fix branchNovember 28, 2024 05:27
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@aslilacaslilacaslilac approved these changes

@deansheatherdeansheatherAwaiting requested review from deansheather

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@ethanndickson@aslilac

[8]ページ先頭

©2009-2025 Movatter.jp