{"record":{"id":"5f0e08121113dcc9","repo":"hashicorp/terraform","slug":"newresourceconfigshimmed-given-v-an-object-type","errorCode":null,"errorMessage":"NewResourceConfigShimmed given %#v; an object type is required","messagePattern":"NewResourceConfigShimmed given %#v; an object type is required","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/legacy/terraform/resource.go","lineNumber":139,"sourceCode":"\t\tConfig: cfg,\n\n\t\tComputedKeys: newResourceConfigShimmedComputedKeys(v, \"\"),\n\t}\n}\n\n// NewResourceConfigShimmed wraps a cty.Value of object type in a legacy\n// ResourceConfig object, so that it can be passed to older APIs that expect\n// this wrapping.\n//\n// The returned ResourceConfig is already interpolated and cannot be\n// re-interpolated. It is, therefore, useful only to functions that expect\n// an already-populated ResourceConfig which they then treat as read-only.\n//\n// If the given value is not of an object type that conforms to the given\n// schema then this function will panic.\nfunc NewResourceConfigShimmed(val cty.Value, schema *configschema.Block) *ResourceConfig {\n\tif !val.Type().IsObjectType() {\n\t\tpanic(fmt.Errorf(\"NewResourceConfigShimmed given %#v; an object type is required\", val.Type()))\n\t}\n\tret := &ResourceConfig{}\n\n\tlegacyVal := hcl2shim.ConfigValueFromHCL2Block(val, schema)\n\tif legacyVal != nil {\n\t\tret.Config = legacyVal\n\n\t\t// Now we need to walk through our structure and find any unknown values,\n\t\t// producing the separate list ComputedKeys to represent these. We use the\n\t\t// schema here so that we can preserve the expected invariant\n\t\t// that an attribute is always either wholly known or wholly unknown, while\n\t\t// a child block can be partially unknown.\n\t\tret.ComputedKeys = newResourceConfigShimmedComputedKeys(val, \"\")\n\t} else {\n\t\tret.Config = make(map[string]interface{})\n\t}\n\tret.Raw = ret.Config\n","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/legacy/terraform/resource.go#L121-L157","documentation":"Panics in NewResourceConfigShimmed (resource.go:139). It wraps a cty.Value into a legacy ResourceConfig and requires val.Type().IsObjectType(); passing a non-object value (primitive, list, map, tuple) panics. The docstring states it will panic if the value is not an object type.","triggerScenarios":"Calling NewResourceConfigShimmed with a cty.Value that is not an object — e.g. passing a single attribute value (cty.StringVal) or a list/tuple where a block-level object is expected.","commonSituations":"Provider/plugin integration code shimming cty values incorrectly, or passing a nested attribute value instead of the full block object.","solutions":["Pass a cty.Value of object type built to conform to the schema block (use cty.ObjectVal or configschema-derived types).","Check val.Type().IsObjectType() before calling, and wrap/convert when needed.","Use hcl2shim.ConfigValueFromHCL2Block to produce the correct object shape."],"exampleFix":"// before\ncfg := NewResourceConfigShimmed(cty.StringVal(\"hi\"), schema)\n// after\ncfg := NewResourceConfigShimmed(cty.ObjectVal(map[string]cty.Value{\"name\": cty.StringVal(\"hi\")}), schema)","handlingStrategy":"type-guard","validationCode":"func shimConfigSafe(val cty.Value, schema *configschema.Block) (*terraform.ResourceConfig, error) {\n    if !val.Type().IsObjectType() {\n        return nil, fmt.Errorf(\"expected object type, got %s\", val.Type().FriendlyName())\n    }\n    return terraform.NewResourceConfigShimmed(val, schema), nil\n}","typeGuard":"func isCtyObject(v cty.Value) bool { return v.Type().IsObjectType() }","tryCatchPattern":null,"preventionTips":["Always pass object-typed cty values to NewResourceConfigShimmed.","Build values with cty.ObjectVal or configschema helpers.","Validate IsObjectType at call sites that may receive primitives."],"tags":["terraform","cty","resource-config","legacy","panic"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}