This is my schema for the resource:
func (r *clusterResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"cluster": schema.SingleNestedAttribute{
Required: true,
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Computed: true,
Description: "ID of the cluster",
},
"name": schema.StringAttribute{
Required: true,
Description: "Name of the cluster",
},
"aws": schema.SingleNestedAttribute{
Optional: true,
Attributes: map[string]schema.Attribute{
"role_arn": schema.StringAttribute{
Optional: true,
Description: "Role ARN of the AWS cluster",
},
"key_pair": schema.StringAttribute{
Optional: true,
Description: "Key pair of the AWS cluster",
},
"tags": schema.MapAttribute{
ElementType: types.StringType,
Optional: true,
Description: "Tags of the AWS cluster",
},
},
},
},
},
},
}
}
schema for data source:
func (c *clustersDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"clusters": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Computed: true,
Description: "ID of the cluster",
},
"name": schema.StringAttribute{
Required: true,
Description: "Name of the cluster",
},
"aws": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"role_arn": schema.StringAttribute{
Computed: true,
Description: "Role ARN of the AWS cluster",
},
"key_pair": schema.StringAttribute{
Computed: true,
Description: "Key pair of the AWS cluster",
},
"tags": schema.MapAttribute{
ElementType: types.StringType,
Computed: true,
Description: "Tags of the AWS cluster",
},
},
},
},
},
},
},
}
}
This is the struct for both data source and resourc:
type ClusterDetails struct {
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Aws AWS `tfsdk:"aws"`
}
type AWS struct {
RoleARN types.String `tfsdk:"role_arn"`
KeyPair types.String `tfsdk:"key_pair"`
Tags types.Map `tfsdk:"tags"`
}
When I try terraform plan
it works just as expected without any error but for TF_LOG=INFO terraform apply
im getting this error:
│ Received null value, however the target type cannot handle null values. Use
│ the corresponding `types` package type, a pointer type or a custom type that
│ handles null values.
│
│ Path: cluster.aws
│ Target Type: provider.AWS
│ Suggested `types` Type: basetypes.ObjectValue
│ Suggested Pointer Type: *provider.AWS