Inappropriate value for attribute ... element ... object required

Hey everyone, I am currently working on migrating a AWS MediaTailor provider to the new framework and I am getting an error when trying to set a value. I have an schema that looks (somewhat) like this:

type sourceLocationModel struct {
    AccessConfiguration                 *resourceSourceLocationAccessConfigurationModel                 `tfsdk:"access_configuration"`
}

type resourceSourceLocationAccessConfigurationModel  struct {
    AccessType                             types.String                                                      `tfsdk:"access_type"`
} 

And the following schema for it:

"access_configuration": schema.MapNestedAttribute{
				Optional: true,
				NestedObject: schema.NestedAttributeObject{
					Attributes: map[string]schema.Attribute{
						"access_type": schema.StringAttribute{
							Required:   true,
							CustomType: types.StringType,
							Validators: []validator.String{
								stringvalidator.OneOf("S3_SIGV4", "SECRETS_MANAGER_ACCESS_TOKEN"),
							},
						},
                                           },
                                       },

when trying to define the access configuration access type, as such:

access_configuration = {
    access_type = "S3_SIGV4"
  }

I get the following error:

 Error: Incorrect attribute value type
│ 
│   on source_location.tf line 3, in resource "awsmt_source_location" "example_source_location":
│    3:   access_configuration = {
│    4:     access_type = "S3_SIGV4"
│    5:   }
│ 
│ Inappropriate value for attribute "access_configuration": element "access_type": object required.

Would anyone know why this error is occurring? or how to fix it? All other nested elements can be defined normally, except for this one.

Thanks in advance!!

I’m not that familiar with the framework, but I think I see what’s going on here…

You have defined a MapNestedAttribute. However, from the configuration you’ve written, it looks like you should have used a SingleNestedAttribute instead.

As long as you’re using a MapNestedAttribute, you’re telling Terraform to expect configuration like:

  access_configuration = {
    bananas = {
      access_type = "S3_SIGV4"
    }
    apples = {
      access_type = "SECRETS_MANAGER_ACCESS_TOKEN"
    }
  }
1 Like

I didn’t include it in the post, but the schema for that object continues with a different nested attribute, like this:


"access_configuration": schema.MapNestedAttribute{
				Optional: true,
				NestedObject: schema.NestedAttributeObject{
					Attributes: map[string]schema.Attribute{
						"access_type": schema.StringAttribute{
							Required:   true,
							CustomType: types.StringType,
							Validators: []validator.String{
								stringvalidator.OneOf("S3_SIGV4", "SECRETS_MANAGER_ACCESS_TOKEN"),
							},
						},
						"smatc": schema.MapNestedAttribute{
							Optional: true,
							NestedObject: schema.NestedAttributeObject{
								Attributes: map[string]schema.Attribute{
									"header_name": schema.StringAttribute{
										Optional:   true,
										CustomType: types.StringType,
									},
									"secret_arn": schema.StringAttribute{
										Optional:   true,
										CustomType: types.StringType,
									},
									"secret_string_key": schema.StringAttribute{
										Optional:   true,
										CustomType: types.StringType,
									},
								},
							},
						},
					},
				},
			},

how would you define just the access configuration on the tf file in this case? I attempted to “”“copy”“” your code in a way and did:

access_configuration = {
    access_type = {
      access_type = "S3_SIGV4"
    }
  }

but it returned:

│ An unexpected error was encountered trying to convert tftypes.Value into awsmt.resourceSourceLocationAccessConfigurationModel. This is always an error in the provider. Please report the
│ following to the provider developer:
│ 
│ cannot reflect tftypes.Map[tftypes.Object["access_type":tftypes.String, "smatc":tftypes.Map[tftypes.Object["header_name":tftypes.String, "secret_arn":tftypes.String,
│ "secret_string_key":tftypes.String]]]] into a struct, must be an object

Terraform is informing you that the definition you have written of the schema, does not match the structure of the Go type you have defined to have easier access to the values.

You haven’t provided the relevant parts of the Go type, so I can’t comment further, but you may find Plugin Development - Framework: Conversion Rules | Terraform | HashiCorp Developer useful to read.