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

Bridge converts empty lists wrong when passing to TF provider #1915

Closed
VenelinMartinov opened this issue Apr 29, 2024 · 0 comments · Fixed by #1971
Closed

Bridge converts empty lists wrong when passing to TF provider #1915

VenelinMartinov opened this issue Apr 29, 2024 · 0 comments · Fixed by #1971
Assignees
Labels
kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed

Comments

@VenelinMartinov
Copy link
Contributor

What happened?

discovered in #1913

Looks like we convert empty lists wrong.

Example

func TestInputsEqualEmptyList(t *testing.T) {
	t.Skip("We misrepresent empty lists")
	for _, maxItems := range []int{0, 1} {
		for _, configMode := range []schema.SchemaConfigMode{schema.SchemaConfigModeAuto, schema.SchemaConfigModeBlock, schema.SchemaConfigModeAttr} {
			name := fmt.Sprintf("MaxItems: %v, ConfigMode: %v", maxItems, configMode)
			t.Run(name, func(t *testing.T) {
				t1 := tftypes.List{ElementType: tftypes.String}
				t0 := tftypes.Object{
					AttributeTypes: map[string]tftypes.Type{
						"f0": t1,
					},
				}
				runCreateInputCheck(t, inputTestCase{
					Resource: &schema.Resource{
						Schema: map[string]*schema.Schema{
							"f0": {
								Optional:   true,
								Type:       schema.TypeList,
								MaxItems:   maxItems,
								ConfigMode: configMode,
								Elem: &schema.Resource{
									Schema: map[string]*schema.Schema{
										"x": {Optional: true, Type: schema.TypeString},
									},
								},
							},
						},
					},
					Config: tftypes.NewValue(
						t0,
						map[string]tftypes.Value{
							"f0": tftypes.NewValue(t1, []tftypes.Value{}),
						},
					),
				})
			})
		}
	}
}

Output of pulumi about

.

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

@VenelinMartinov VenelinMartinov added needs-triage Needs attention from the triage team kind/bug Some behavior is incorrect or out of spec and removed needs-triage Needs attention from the triage team labels Apr 29, 2024
@VenelinMartinov VenelinMartinov changed the title makeTerraformInput converts empty lists wrong Bridge converts empty lists wrong when passing to TF provider May 28, 2024
VenelinMartinov added a commit that referenced this issue Jun 5, 2024
part of #1785

This change adds a normalisation step for collections when recovering
cty values to pass to terraform. This ensures we represent them
similarly to terraform.

In practice this means that all block collections need to be passed to
TF providers as an empty collection instead of nil. This should get rid
of quite a few subtle discrepancies in the data we pass to the TF
provider code. These sometimes result in panics since we pass unexpected
nils.

This gets rid of all known input discrepancies discovered so far through
cross-testing.

The full rules for what is a block are
[here](https://github.com/hashicorp/terraform-plugin-sdk/blob/1f499688ebd9420768f501d4ed622a51b2135ced/helper/schema/core_schema.go#L60).
It is essentially properties with schema: typeList or typeSet with a
Resource Elem.

fixes #1970
fixes #1915
fixes #1964
fixes #1767 
fixes #1762 

TODO: [DONE] remove the MaxItemsOne default hacks introduced in
#1725 (opened
#2049)

---------

Co-authored-by: Anton Tayanovskyy <[email protected]>
Co-authored-by: Ian Wahbe <[email protected]>
@pulumi-bot pulumi-bot added the resolution/fixed This issue was fixed label Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants