Single nested atribute not accepting optional

Hello,

I have a problem in my terraform, I have defined following schema:

"requiered_atributes": schema.SingleNestedAttribute{

                Optional: true,

                Attributes: map[string]schema.Attribute{

                    "some_tags": schema.ListAttribute{

                        ElementType: types.StringType,

                        Optional:    true,

                    },

                    "some_metadata": schema.MapAttribute{

                        ElementType: types.StringType,

                        Optional:    true,

                    },

                    "labels": schema.MapAttribute{

                        ElementType: types.StringType,

                        Optional:    true,

                    },

                },

            },

Now the problem is as follows.

1.OK - In tf spec once I remove some of the attributes since they have tag optional= true all is ok.
2. NOT-OK - If I remove entire requiered_atributes I get error for some reason.

for example

requiered_atributes= {

    labels = {

      labelsone = "labels1",

      labelstwo = "labels2"

    }

   some_metadata = {

      metadataone     = "metadata1",

      testmetadatatwo = "metadata2",

    }

  some_tags = ["sometags10", "sometags20"]

  }

OK - If I where to remove some_tags completely all would be ok.
FAILED - if I where to remove requiered_atributes there is and error.

The error is as follows: Failed with status: invalid character ‘N’ after top-level value.

Hi there @stankomaksimovic2510 :wave: ,

The schema and config you shared both look valid and I wasn’t able to re-create any validation error by omitting the top-level SingleNestedAttribute in the config, as you mentioned.

To level-set myself, are you encountering a validation error that you can re-create by running terraform validate? If not, the error may be surfacing somewhere else in your resource code, like in the Create / Read / Update / Delete methods.

The error message does look suspiciously like something you’d see returned from the Go standard library JSON package when attempting to Unmarshal invalid JSON: encoding/json

Here’s a live example of what I mean. (I’m not 100% sure that’s your problem, but thought I’d mention it)