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

Normalize Read result for empty collections #2069

Closed
wants to merge 6 commits into from

Conversation

t0yv0
Copy link
Member

@t0yv0 t0yv0 commented Jun 6, 2024

This workaround is aimed to reduce dirty refresh incidence on diffs between empty and null collections that is benign in TF but projects worse to Pulumi.

t0yv0 added 2 commits June 6, 2024 15:42
This workaround is aimed to reduce dirty refresh incidence on diffs between empty and null collections that is benign in
TF but projects worse to Pulumi.
Copy link

codecov bot commented Jun 6, 2024

Codecov Report

Attention: Patch coverage is 58.33333% with 10 lines in your changes missing coverage. Please review.

Project coverage is 61.20%. Comparing base (b012fa8) to head (437997b).

Files Patch % Lines
pkg/tfshim/sdk-v2/provider2.go 58.33% 9 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2069      +/-   ##
==========================================
- Coverage   61.21%   61.20%   -0.01%     
==========================================
  Files         337      337              
  Lines       45177    45200      +23     
==========================================
+ Hits        27654    27666      +12     
- Misses      16003    16013      +10     
- Partials     1520     1521       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@t0yv0
Copy link
Member Author

t0yv0 commented Jun 6, 2024

At this point it's making TestAccBucketPy pass dirty refresh check in AWS. The change has to be scoped down to PlanResourceChange path because rolling it out generally in the bridge introduces more dirty refresh than we had before. This is pretty interesting, we might need to go super-surgical.

@VenelinMartinov suggested the correction may only be needed for maps, let me check lists and sets shortly.

continue
}

if _, ok := sch.Elem.(*schema.Resource); ok || sch.ConfigMode == schema.SchemaConfigModeBlock {
Copy link
Member Author

Choose a reason for hiding this comment

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

What's the best way to decide if it's a block or attr these days @VenelinMartinov

Copy link
Contributor

Choose a reason for hiding this comment

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

You can get the attributes of a resource from res.CoreConfigSchema().Attributes

Copy link
Contributor

Choose a reason for hiding this comment

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

Something like this:

	sch := res.CoreConfigSchema()
	for key, attr := range sch.Attributes {
		if !attr.Type.IsCollectionType() {
			continue
		}

		if config.IsSet(key) {
			continue
		}

		stateVal, ok := m[key]
		if !ok {
			continue
		}
		if !(stateVal.Type().IsCollectionType() && !stateVal.IsNull() && stateVal.LengthInt() == 0) {
			continue
		}

		m[key] = cty.NullVal(attr.Type)
	}

Copy link
Contributor

Choose a reason for hiding this comment

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

I've continued this in #2065

@t0yv0
Copy link
Member Author

t0yv0 commented Jun 6, 2024

Guessing based on the investigation in #2063 that this needs to be scoped to non-computed collections. The best end to end test here would be to cover the idea that we get a clean refresh for these attributes.

// To compensate for this problem, this method corrects the Pulumi Read result during `pulumi refresh` to also erase
// empty collections from the Read result if the old input is missing or null.
//
// This currently only handles top-level properties.
Copy link
Contributor

Choose a reason for hiding this comment

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

We likely need to handle this for every block, right

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds like it, but I don't have an e2e example handy.

@t0yv0
Copy link
Member Author

t0yv0 commented Jun 12, 2024

Closing in favor of #2073

@t0yv0 t0yv0 closed this Jun 12, 2024
@t0yv0 t0yv0 deleted the t0yv0/normalize-empty-collections-read branch February 5, 2025 05:14
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.

2 participants