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

"panic: value is not an object" when MapNestedAttributes contains more than one computed attribute #29473

Closed
avinashbot opened this issue Aug 29, 2021 · 1 comment · Fixed by #29482
Assignees

Comments

@avinashbot
Copy link

When working with the terraform plugin framework, defining an attribute with MapNestedAttributes that contains more than one computed attribute crashes terraform before a plan/apply. I couldn't find any mention of the panic message (panic: value is not an object) anywhere in the issues before. The stacktrace points here in go-cty.

I saw this happening in my provider, but I can also reproduce it with the hashicups starter template. I've attached the relevant minimal reproduction code below.

Terraform Version

Terraform v1.0.5
on linux_amd64

Terraform Configuration Files

Implementation:

func (r resourceOrderType) GetSchema(_ context.Context) (schema.Schema, []*tfprotov6.Diagnostic) {
	return schema.Schema{
		Attributes: map[string]schema.Attribute{
			"items": {
				Required: true,
				Attributes: schema.MapNestedAttributes(
					map[string]schema.Attribute{
						"id": {
							Type:     types.NumberType,
							Optional: true,
						},
						"name": {
							Type:     types.StringType,
							Optional: true,
							Computed: true, // <- first computed
						},
						"description": {
							Type:     types.StringType,
							Optional: true,
							Computed: true, // <- second computed
						},
					},
					schema.MapNestedAttributesOptions{},
				),
			},
		},
	}, nil
}

Config:

The crash happens when the "items" are present in the config, but the actual content doesn't matter.

resource "hashicups_order" "edu" {
  items = {
    "one" : {
      id = 1
    }
    "two" : {
      id = 2
    }
  }
}

Debug Output

2021-08-29T01:26:37.501-0700 [DEBUG] refresh: hashicups_order.edu: no state, so not refreshing
2021-08-29T01:26:37.501-0700 [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState to refreshState for hashicups_order.edu
2021-08-29T01:26:37.501-0700 [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState: removing state object for hashicups_order.edu
2021-08-29T01:26:37.501-0700 [TRACE] Re-validating config for "hashicups_order.edu"
2021-08-29T01:26:37.501-0700 [TRACE] GRPCProvider.v6: ValidateResourceConfig
2021-08-29T01:26:37.501-0700 [TRACE] GRPCProvider.v6: PlanResourceChange
2021-08-29T01:26:37.502-0700 [TRACE] vertex "hashicups_order.edu": visit complete
panic: value is not an object

goroutine 79 [running]:
github.com/zclconf/go-cty/cty.Value.GetAttr(0x2b44678, 0xc000122369, 0x2269840, 0xc000be2f90, 0xc0007822a0, 0xb, 0x8d851d, 0x2b44720, 0xc00058dab0, 0x2b44720)
	/home/circleci/go/pkg/mod/github.com/zclconf/[email protected]/cty/value_ops.go:744 +0x44e
github.com/hashicorp/terraform/internal/plans/objchange.assertPlannedAttrValid(0xc0007822a0, 0xb, 0xc0004addc0, 0x2b44720, 0xc000be3150, 0x0, 0x0, 0x2b44678, 0xc000122369, 0x2269840, ...)
	/home/circleci/project/project/internal/plans/objchange/plan_valid.go:248 +0x85
github.com/hashicorp/terraform/internal/plans/objchange.assertPlannedAttrsValid(0xc000517530, 0x2b44720, 0xc000be3150, 0x0, 0x0, 0x2b44678, 0xc000122369, 0x2269840, 0xc000be2570, 0x2b44678, ...)
	/home/circleci/project/project/internal/plans/objchange/plan_valid.go:241 +0x214
github.com/hashicorp/terraform/internal/plans/objchange.assertPlannedObjectValid(0xc00094e580, 0x2b44720, 0xc000be3110, 0x0, 0x0, 0x2b44758, 0xc000b3ca40, 0x233e560, 0xc000328b40, 0x2b44758, ...)
	/home/circleci/project/project/internal/plans/objchange/plan_valid.go:394 +0x7db
github.com/hashicorp/terraform/internal/plans/objchange.assertPlannedObjectValid(0xc00094e580, 0x0, 0x0, 0x0, 0x0, 0x2b44720, 0xc000b3caa0, 0x233e560, 0xc000328c00, 0x2b44720, ...)
	/home/circleci/project/project/internal/plans/objchange/plan_valid.go:427 +0x154e
github.com/hashicorp/terraform/internal/plans/objchange.assertPlannedValueValid(0xc0004add80, 0x0, 0x0, 0x0, 0x0, 0x2b44720, 0xc000b3caa0, 0x233e560, 0xc000328c00, 0x2b44720, ...)
	/home/circleci/project/project/internal/plans/objchange/plan_valid.go:293 +0x986
github.com/hashicorp/terraform/internal/plans/objchange.assertPlannedAttrValid(0xc000782248, 0x5, 0xc0004add80, 0x2b44758, 0xc000be2830, 0x0, 0x0, 0x2b44758, 0xc000b3cab0, 0x233e560, ...)
	/home/circleci/project/project/internal/plans/objchange/plan_valid.go:256 +0x332
github.com/hashicorp/terraform/internal/plans/objchange.assertPlannedAttrsValid(0xc000516bd0, 0x2b44758, 0xc000be2830, 0x0, 0x0, 0x2b44758, 0xc000b3cab0, 0x233e560, 0xc000328c30, 0x2b44758, ...)
	/home/circleci/project/project/internal/plans/objchange/plan_valid.go:241 +0x214
github.com/hashicorp/terraform/internal/plans/objchange.assertPlanValid(0xc000517500, 0x2b44758, 0xc000be2830, 0x0, 0x0, 0x2b44758, 0xc000b3cab0, 0x233e560, 0xc000328c30, 0x2b44758, ...)
	/home/circleci/project/project/internal/plans/objchange/plan_valid.go:57 +0x41c
github.com/hashicorp/terraform/internal/plans/objchange.AssertPlanValid(...)
	/home/circleci/project/project/internal/plans/objchange/plan_valid.go:36
github.com/hashicorp/terraform/internal/terraform.(*NodeAbstractResourceInstance).plan(0xc0005d0a80, 0x2b74d00, 0xc0006fe8c0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/home/circleci/project/project/internal/terraform/node_resource_abstract_instance.go:783 +0x17e5
github.com/hashicorp/terraform/internal/terraform.(*NodePlannableResourceInstance).managedResourceExecute(0xc0007ad740, 0x2b74d00, 0xc0006fe8c0, 0x40ac08, 0x269fd80, 0xc00099dc50)
	/home/circleci/project/project/internal/terraform/node_resource_plan_instance.go:196 +0x8cb
github.com/hashicorp/terraform/internal/terraform.(*NodePlannableResourceInstance).Execute(0xc0007ad740, 0x2b74d00, 0xc0006fe8c0, 0x7faeb1660302, 0xc00099dce8, 0x40bb05, 0x2387b80)
	/home/circleci/project/project/internal/terraform/node_resource_plan_instance.go:54 +0xb3
github.com/hashicorp/terraform/internal/terraform.(*ContextGraphWalker).Execute(0xc0001a7040, 0x2b74d00, 0xc0006fe8c0, 0x7faeb16603d8, 0xc0007ad740, 0x0, 0x0, 0x0)
	/home/circleci/project/project/internal/terraform/graph_walk_context.go:129 +0xbf
github.com/hashicorp/terraform/internal/terraform.(*Graph).walk.func1(0x269fd80, 0xc0007ad740, 0x0, 0x0, 0x0)
	/home/circleci/project/project/internal/terraform/graph.go:59 +0xbd3
github.com/hashicorp/terraform/internal/dag.(*Walker).walkVertex(0xc000091200, 0x269fd80, 0xc0007ad740, 0xc0007bcc80)
	/home/circleci/project/project/internal/dag/walk.go:381 +0x288
created by github.com/hashicorp/terraform/internal/dag.(*Walker).Update
	/home/circleci/project/project/internal/dag/walk.go:304 +0x1246

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Crash Output

https://gist.github.com/avinashbot/b1ce31f9cfb0501b8f349135a6bb9bda

Expected Behavior

Terraform doesn't crash on me.

Actual Behavior

Terraform crashed on me.

Steps to Reproduce

  1. terraform init
  2. terraform plan

Additional Context

References

@github-actions
Copy link

github-actions bot commented Oct 1, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants