Skip to content

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

@avinashbot

Description

@avinashbot

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/go-cty@v1.9.1/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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions