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

Correctly handle MaxItems: 1 for extractSchemaInputs #1812

Conversation

iwahbe
Copy link
Member

@iwahbe iwahbe commented Mar 29, 2024

Fixes pulumi/pulumi-cloudflare#554

This corrects MaxItems: 1 handling for extractSchemaInputs. As part of that, I have separated the handling of map<string,elem> and object types to their own function. This vastly simplifies the code.

Tests are incoming shortly.

@iwahbe iwahbe self-assigned this Mar 29, 2024
Copy link

codecov bot commented Mar 29, 2024

Codecov Report

Attention: Patch coverage is 93.54839% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 60.19%. Comparing base (3a2ed13) to head (f8c2609).
Report is 20 commits behind head on master.

Files Patch % Lines
pkg/tfbridge/schema.go 93.54% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1812      +/-   ##
==========================================
- Coverage   60.60%   60.19%   -0.42%     
==========================================
  Files         303      310       +7     
  Lines       42348    42771     +423     
==========================================
+ Hits        25667    25745      +78     
- Misses      15208    15554     +346     
+ Partials     1473     1472       -1     

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

@iwahbe iwahbe force-pushed the iwahbe/cloudflare-554/max-item-one-handling-for-extract-schema-inputs branch from 8ffcc83 to 5e453f9 Compare March 29, 2024 16:02
pkg/tfbridge/schema.go Show resolved Hide resolved
Comment on lines +1709 to 1711
// To match previous behavior, we insert the default key for Map types.
//
// TODO: We should probably remove the extraneous defaultsKey here.
v[defaultsKey] = resource.NewArrayProperty([]resource.PropertyValue{})
Copy link
Member Author

Choose a reason for hiding this comment

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

Before this PR, we didn't clearly distinguish between Map and Object very well, so we inserted the defaults list in all cases. To avoid changing a bunch of existing tests, I'm leaving the old behavior as is for now.

Map's can't have field defaults, so I'm pretty sure that this is wrong. Fixing is a followup PR job.

pkg/tfbridge/schema.go Outdated Show resolved Hide resolved
tfs = e
case shim.Resource:
if state.IsObject() {
return resource.NewProperty(
Copy link
Member

Choose a reason for hiding this comment

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

should this be NewObjectProperty to be more type-precise (nit)

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you clarify what you mean by "more type-precise". NewObjectProperty is more explicit, but I don't see why we shouldn't use type inference. NewProperty is fully type safe:

// PropertyValueType enumerates the actual types that may be stored in a PropertyValue.
//
//nolint:lll
type PropertyValueType interface {
	bool | float64 | string | *asset.Asset | *archive.Archive | Computed | Output | *Secret | ResourceReference | []PropertyValue | PropertyMap
}

// NewProperty creates a new PropertyValue.
func NewProperty[T PropertyValueType](v T) PropertyValue {
	return PropertyValue{v}
}

Copy link
Member

Choose a reason for hiding this comment

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

Just out of habit, I'd use least general primitives, in case the underlying type switches to string, that's a bug. But it's purely theoretical so disregard the nit.

@t0yv0
Copy link
Member

t0yv0 commented Mar 29, 2024

Thanks for wrangling this, looking forward to the tests. Not the easiest code to work on.

@iwahbe iwahbe force-pushed the iwahbe/cloudflare-554/max-item-one-handling-for-extract-schema-inputs branch from 459d269 to 39d4dc9 Compare March 29, 2024 17:22
@iwahbe iwahbe force-pushed the iwahbe/cloudflare-554/max-item-one-handling-for-extract-schema-inputs branch from 39d4dc9 to bc6f82a Compare March 29, 2024 17:23
@iwahbe iwahbe requested a review from t0yv0 March 29, 2024 17:26
pkg/tfbridge/schema_test.go Outdated Show resolved Hide resolved
ps = &SchemaInfo{}
}

for IsMaxItemsOne(tfs, ps) {
Copy link
Member

Choose a reason for hiding this comment

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

It's fantastic to get quick fix out! IN the longer term maybe worth looking into abstracting out the traversal using path-based or some such methods, so the codebase deals with these idiosyncrasies in one place and gets it right once and for all.

@iwahbe iwahbe enabled auto-merge (squash) April 1, 2024 09:48
@iwahbe iwahbe disabled auto-merge April 1, 2024 09:48
@iwahbe iwahbe enabled auto-merge (squash) April 1, 2024 09:48
@iwahbe iwahbe force-pushed the iwahbe/cloudflare-554/max-item-one-handling-for-extract-schema-inputs branch from d935eba to f8c2609 Compare April 1, 2024 10:05
@iwahbe iwahbe merged commit b9afd77 into master Apr 1, 2024
9 checks passed
@iwahbe iwahbe deleted the iwahbe/cloudflare-554/max-item-one-handling-for-extract-schema-inputs branch April 1, 2024 10:21
iwahbe added a commit that referenced this pull request Apr 1, 2024
Follow-up to
#1812.

- 6d6bb4f removes an unused parameter.
- 26fc890 refactors
`extractInputsObject` out of `extractInputs`, creating an explicit code
path for objects.
- 12618d5 removes an unused parameter.

This area is under test in the bridge, making it relatively safe to
refactor.
iwahbe added a commit to pulumi/pulumi-cloudflare that referenced this pull request Apr 2, 2024
This resolves the immediate customer pain with
#554.

Fixes #554
iwahbe added a commit to pulumi/pulumi-cloudflare that referenced this pull request Apr 2, 2024
This resolves the immediate customer pain with
#554.

Fixes #554
lumiere-bot bot added a commit to coolguy1771/home-ops that referenced this pull request Apr 3, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@pulumi/cloudflare](https://pulumi.io)
([source](https://togithub.com/pulumi/pulumi-cloudflare)) | dependencies
| minor | [`5.23.0` ->
`5.24.1`](https://renovatebot.com/diffs/npm/@pulumi%2fcloudflare/5.23.0/5.24.1)
|

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>pulumi/pulumi-cloudflare (@&#8203;pulumi/cloudflare)</summary>

###
[`v5.24.1`](https://togithub.com/pulumi/pulumi-cloudflare/releases/tag/v5.24.1)

[Compare
Source](https://togithub.com/pulumi/pulumi-cloudflare/compare/v5.24.0...v5.24.1)

#### Changelog

-
[`b2c32fe`](https://togithub.com/pulumi/pulumi-cloudflare/commit/b2c32fe7)
Bump google.golang.org/protobuf in /examples/record/go
-
[`bcb25f7`](https://togithub.com/pulumi/pulumi-cloudflare/commit/bcb25f74)
Combined dependencies PR
([#&#8203;691](https://togithub.com/pulumi/pulumi-cloudflare/issues/691))
-
[`085504b`](https://togithub.com/pulumi/pulumi-cloudflare/commit/085504bf)
Include
[pulumi/pulumi-terraform-bridge#1812](https://togithub.com/pulumi/pulumi-terraform-bridge/issues/1812)
([#&#8203;708](https://togithub.com/pulumi/pulumi-cloudflare/issues/708))
-
[`06772bf`](https://togithub.com/pulumi/pulumi-cloudflare/commit/06772bf8)
Merge remote-tracking branch
'origin/dependabot/go_modules/examples/record/go/google.golang.org/protobuf-1.33.0'
into combined-pr-branch
-
[`b3b3a65`](https://togithub.com/pulumi/pulumi-cloudflare/commit/b3b3a658)
Upgrade pulumi-terraform-bridge to v3.79.0
([#&#8203;702](https://togithub.com/pulumi/pulumi-cloudflare/issues/702))

###
[`v5.24.0`](https://togithub.com/pulumi/pulumi-cloudflare/releases/tag/v5.24.0)

[Compare
Source](https://togithub.com/pulumi/pulumi-cloudflare/compare/v5.23.0...v5.24.0)

#### Changelog

-
[`5c0da33`](https://togithub.com/pulumi/pulumi-cloudflare/commit/5c0da335)
Mark `cloudflare:Record` as `DeleteBeforeReplace: true`
([#&#8203;693](https://togithub.com/pulumi/pulumi-cloudflare/issues/693))
-
[`19bc5a0`](https://togithub.com/pulumi/pulumi-cloudflare/commit/19bc5a0d)
Remove unused field mappings
([#&#8203;695](https://togithub.com/pulumi/pulumi-cloudflare/issues/695))
-
[`4748d37`](https://togithub.com/pulumi/pulumi-cloudflare/commit/4748d37e)
Update GitHub Actions workflows.
([#&#8203;698](https://togithub.com/pulumi/pulumi-cloudflare/issues/698))
-
[`1b5e3ce`](https://togithub.com/pulumi/pulumi-cloudflare/commit/1b5e3ce3)
Upgrade terraform-provider-cloudflare to v4.28.0
([#&#8203;697](https://togithub.com/pulumi/pulumi-cloudflare/issues/697))
-
[`64ff681`](https://togithub.com/pulumi/pulumi-cloudflare/commit/64ff681a)
falseUpdate GitHub Actions workflows.
([#&#8203;694](https://togithub.com/pulumi/pulumi-cloudflare/issues/694))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yNzMuMCIsInVwZGF0ZWRJblZlciI6IjM3LjI3OS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: lumiere-bot[bot] <98047013+lumiere-bot[bot]@users.noreply.github.com>
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.

Importing RuleSet does not import rules and try to replace
2 participants