Terraform plugin framework: ListNestedAttribute is treated as required if it's optional and computed

I’m working with the plugin framework and I’m experiencing a weird issue with how computed nested list attributes work. I’m pretty fresh to Terraform, so I’m not really sure whether it’s a problem with the framework or with my mental model of computed attributes :sweat_smile:

I have a nested schema that usesSingleNestedAttribute and ListNestedAttribute that looks something like the snippet below. Notably, “outer” is only optional, but the “inner” is both optional and computed. (Side note: I’m using the latest version of the framework straight from main branch, but it’s also happening in v0.2)

"outer": {
	Optional: true,
	Attributes: tfsdk.SingleNestedAttributes(map[string]tfsdk.Attribute{
		"inner": {
			Optional: true,
			Computed: true,
			Attributes: tfsdk.ListNestedAttributes(
				map[string]tfsdk.Attribute{
					// ...
				},
				tfsdk.ListNestedAttributesOptions{MinItems: 0, MaxItems: 999},
			),
		},
	},
},

If I define my resource like this:

resource "res_type" "res_name" {
  outer = {}
}

It throws the following error, which doesn’t make sense. Isn’t “inner” optional, so it shouldn’t be considered required? This only happens when I use a ListNestedAttributes with Computed set to true.

Error: attribute "outer": attribute "inner": list of object required

I’m not sure where the error is coming from, actually. There’s no error detail, just a summary, and the logs around the error aren’t super helpful (for me, at least)

2021-08-27T20:22:23.632-0700 [TRACE] Re-validating config for "res_type.res_name"
2021-08-27T20:22:23.632-0700 [TRACE] GRPCProvider.v6: ValidateResourceConfig
2021-08-27T20:22:23.633-0700 [TRACE] GRPCProvider.v6: PlanResourceChange
2021-08-27T20:22:23.633-0700 [TRACE] vertex "res_type.res_name": visit complete
2021-08-27T20:22:23.633-0700 [TRACE] vertex "res_type.res_name": dynamic subgraph encountered errors: attribute "outer": attribute "inner": list of object required
2021-08-27T20:22:23.633-0700 [TRACE] vertex "res_type.res_name": visit complete
2021-08-27T20:22:23.633-0700 [TRACE] vertex "res_type.res_name (expand)": dynamic subgraph encountered errors: attribute "outer": attribute "inner": list of object required
2021-08-27T20:22:23.633-0700 [TRACE] vertex "res_type.res_name (expand)": visit complete

Any ideas? If it’s definitely a bug, I can move this over to GitHub issues too :slight_smile:

This seems like a bug to me, and I’m inclined to say in Terraform, not the framework. What version of Terraform are you using? The last few releases have had some bugfixes for nested attributes.