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

Encountering Panic: inconsistent list element types #1932

Closed
zbuchheit opened this issue May 7, 2024 · 3 comments · Fixed by pulumi/pulumi-aws#3908
Closed

Encountering Panic: inconsistent list element types #1932

zbuchheit opened this issue May 7, 2024 · 3 comments · Fixed by pulumi/pulumi-aws#3908
Assignees
Labels
impact/panic This bug represents a panic or unexpected crash kind/bug Some behavior is incorrect or out of spec p1 A bug severe enough to be the next item assigned to an engineer resolution/fixed This issue was fixed
Milestone

Comments

@zbuchheit
Copy link

What happened?

When using the pulumi-terraform-bridge I am encountering a panic

panic: inconsistent list element types (cty.Object(map[string]cty.Type{"resource_type":cty.String, "tags":cty.String}) then cty.Object(map[string]cty.Type{"resource_type":cty.String, "tags":cty.Map(cty.String)}))

I will attach the full stack trace separately.

Example

n/a

Output of pulumi about

pulumi-terraform-bridge 3.80.0

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).

@zbuchheit zbuchheit added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels May 7, 2024
@zbuchheit
Copy link
Author

zbuchheit commented May 8, 2024

Repro:

package main

import (
	"fmt"

	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/s3"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {

		bucket, err := s3.NewBucket(ctx, "my-bucket", nil)
		if err != nil {
			return err
		}

		template, err := ec2.NewLaunchTemplate(ctx, "zbuchheit-launch-template", &ec2.LaunchTemplateArgs{
			ImageId: pulumi.String("dummyImageIdBecauseItIsAPreview"),
			TagSpecifications: &ec2.LaunchTemplateTagSpecificationArray{
				&ec2.LaunchTemplateTagSpecificationArgs{
					ResourceType: pulumi.String("resourceType1"),
					Tags: pulumi.StringMap{
						"Name": pulumi.Sprintf("BucketArn %s", bucket.Arn),
					},
				},
				&ec2.LaunchTemplateTagSpecificationArgs{
					ResourceType: pulumi.String("resourceType2"),
					Tags: pulumi.StringMap{
						"Name": pulumi.String("Bucket Arn"), // If you make this an output also, the panic will go away
					},
				},
			},
		},
		)
		if err != nil {
			return err
		}

		ctx.Export("bucket", bucket)
		ctx.Export("template", template)
		return nil
	})
}

@corymhall corymhall self-assigned this May 8, 2024
@mikhailshilkov mikhailshilkov added impact/panic This bug represents a panic or unexpected crash p1 A bug severe enough to be the next item assigned to an engineer labels May 8, 2024
@mikhailshilkov mikhailshilkov added this to the 0.104 milestone May 8, 2024
corymhall added a commit that referenced this issue May 8, 2024
@corymhall corymhall mentioned this issue May 8, 2024
@corymhall corymhall removed the needs-triage Needs attention from the triage team label May 8, 2024
@corymhall
Copy link
Contributor

Looks like this is due to us rolling out PlanResourceChange to the launch template resource in pulumi/pulumi-aws#3687.

  1. We will go ahead and revert that PR since the bug that was fixing was a diff bug which is less critical than this p1.
  2. We need to rewrite the objectFromCtyValue function. We will need to implement our own transform function to handle converting the cty value to a JSON map.

@t0yv0
Copy link
Member

t0yv0 commented May 8, 2024

CC @VenelinMartinov @iwahbe - we might have a fix here FYI.

t0yv0 pushed a commit to pulumi/pulumi-aws that referenced this issue May 8, 2024
This reverts commit 670b38d.

This is a temporary revert in order to fix
pulumi/pulumi-terraform-bridge#1932. Once we
have a permanent fix, we will restore this.
@pulumi-bot pulumi-bot added the resolution/fixed This issue was fixed label May 8, 2024
@corymhall corymhall reopened this May 9, 2024
corymhall added a commit that referenced this issue May 9, 2024
When `PlanResourceChange` is enabled, the schema that is passed to
`MakeTerraformOutputs` is a `cty.Value`. We then have to convert this
into a JSON object as part of `objectFromCtyValue` before eventually
converting to Pulumi values. We were relying on a couple of functions
from other packages to do this conversion between `cty.Value` and a JSON
object which led to issues like #1932.

For example, if we have a map value like this:
```json
{
  "tagSpecifications": [
    {
      "tags": {
        "Name": "04da6b54-80e4-46f7-96ec-b56ff0331ba9"
      }
    }
    {
      "tags": {
        "Name": "Bucket Arn"
      }
    }
  ]
}
```

The first `tags` map contains an `unknown` sentinel so it will be
converted by `PlanResourceChange` into something like this:

```
{
  "tagSpecifications": [
    {
      "tags": UnknownMapValue
    }
    {
      "tags": {
        "Name": "Bucket Arn"
      }
    }
  ]
}
```

As part of the conversion we were using the `cty.Transform` function
which performs some type checking to ensure that every item in the list
is of the same type.

Since all we want from this function is to convert `cty.Value` to a JSON
object, I've taken the underlying `cty.marshal` function and modified it
to handle unknown values.

fixes #1943, re #1932
corymhall added a commit that referenced this issue May 10, 2024
…#1947)

When `PlanResourceChange` is enabled, the schema that is passed to
`MakeTerraformOutputs` is a `cty.Value`. We then have to convert this
into a JSON object as part of `objectFromCtyValue` before eventually
converting to Pulumi values. We were relying on a couple of functions
from other packages to do this conversion between `cty.Value` and a JSON
object which led to issues like #1932.

For example, if we have a map value like this:
```json
{
  "tagSpecifications": [
    {
      "tags": {
        "Name": "04da6b54-80e4-46f7-96ec-b56ff0331ba9"
      }
    }
    {
      "tags": {
        "Name": "Bucket Arn"
      }
    }
  ]
}
```

The first `tags` map contains an `unknown` sentinel so it will be
converted by `PlanResourceChange` into something like this:

```
{
  "tagSpecifications": [
    {
      "tags": UnknownMapValue
    }
    {
      "tags": {
        "Name": "Bucket Arn"
      }
    }
  ]
}
```

As part of the conversion we were using the `cty.Transform` function
which performs some type checking to ensure that every item in the list
is of the same type.

Since all we want from this function is to convert `cty.Value` to a JSON
object, I've taken the underlying `cty.marshal` function and modified it
to handle unknown values.

fixes #1943, re #1932
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact/panic This bug represents a panic or unexpected crash kind/bug Some behavior is incorrect or out of spec p1 A bug severe enough to be the next item assigned to an engineer resolution/fixed This issue was fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants