Using the new terraform-plugin-go SDK and I basically have the following tftypes.Type
Object{
AttributeTypes: map[string]Type{
"id": Number,
"name": String,
"description": String,
"role": Map{AttributeType: Object{
AttributeTypes: map[string]Type{
"id": Number,
"description": String,
},
OptionalTypes: map[string]struct{}{
"description": struct{}{},
},
},
},
OptionalTypes: map[string]struct{}[
"description": struct{}{},
]
}
I used this type when importing, resulting in a state like this:
"id": 1,
"name": "foo",
"role": {
"owner": {
"description": "owner role",
"id": 2
},
}
Running a plan requires you to call RawState.Unmarshall(type)
, so it seems obivous I should supply the same type as I did when importing (defined above). However, it panics with this this error (expanded for clarity):
ElementKeyString("owner"): cant use
tftypes.Object["id":tftypes.Number, "description":tftypes.String]
as
tftypes.Object["id":tftypes.Number, "description":tftypes.String?]
Where did it get the idea that description
was not optional? I definitely passed in a type marking it as optional so I am not sure how it is possible inferring otherwise.
If I make description
non-optional (post-import), it generates a healthy plan and doesn’t panic.
PS: I would open an issue in the repo tracker but seems like its pointing me here but I am unsure if its a bug or if I am using it wrong.