-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optional SingleNestedAttribute not treated as optional if nested attributes are required #1075
Comments
Hey there @kenny-statsig 👋🏻 , thanks for reporting the issue and sorry you're running into trouble here. This error message is being generated by Specifically, the code path that is called right before this error message is the My suspicion is that the
You can see the pattern of embedding in a custom type, then offloading the majority of the |
@austinvalle Thanks for the response! Here is the full implementation of BTW these are all generated using the OpenAPI provider spec generator. But I do see similar null value handling implemented. func (t ActiveReviewType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) {
if in.Type() == nil {
return NewActiveReviewValueNull(), nil
}
if !in.Type().Equal(t.TerraformType(ctx)) {
return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type())
}
if !in.IsKnown() {
return NewActiveReviewValueUnknown(), nil
}
if in.IsNull() {
return NewActiveReviewValueNull(), nil
}
attributes := map[string]attr.Value{}
val := map[string]tftypes.Value{}
err := in.As(&val)
if err != nil {
return nil, err
}
for k, v := range val {
a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v)
if err != nil {
return nil, err
}
attributes[k] = a
}
return NewActiveReviewValueMust(ActiveReviewValue{}.AttributeTypes(ctx), attributes), nil
} I did also find a similar issue but for SingleNestedBlocks here. However, i'm not sure if it's relevant to attributes as well. |
Thanks for providing the full custom type code! I was able to recreate the bug and it's actually originating from The current implementation of func (v ActiveReviewValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) {
var diags diag.Diagnostics
objVal, diags := types.ObjectValue(
map[string]attr.Type{
"description": basetypes.StringType{},
"review_id": basetypes.StringType{},
"review_status": basetypes.StringType{},
},
map[string]attr.Value{
"description": v.Description,
"review_id": v.ReviewId,
"review_status": v.ReviewStatus,
})
// This always is a known object with null values, regardless of what `v` is
return objVal, diags
} The actual implementation should look something like: func (v ActiveReviewValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) {
var diags diag.Diagnostics
if v.IsNull() {
return types.ObjectNull(v.AttributeTypes(ctx)), nil
}
if v.IsUnknown() {
return types.ObjectUnknown(v.AttributeTypes(ctx)), nil
}
objVal, diags := types.ObjectValue(
map[string]attr.Type{
"description": basetypes.StringType{},
"review_id": basetypes.StringType{},
"review_status": basetypes.StringType{},
},
map[string]attr.Value{
"description": v.Description,
"review_id": v.ReviewId,
"review_status": v.ReviewStatus,
})
return objVal, diags
} |
Module version
Relevant provider source code
Schema generated from OpenAPI spec
Relevant part of OpenAPI spec
Terraform Configuration Files
Debug Output
https://gist.github.com/kenny-statsig/37655ad084167fe70fd327da27bb72ae
Expected Behavior
I expected the attribute
active_review
to be treated as optional. And only if provided in the configuration, would the attributesdescription
,review_id
,review_status
be required.Actual Behavior
My acceptance test failed due to the missing attributes
active_review.description
,active_review.review_id
,active_review.review_status
supposedly marked as required by my provider.Steps to Reproduce
Provider is still in development so cannot be reproduced externally.
But it's a simple acceptance test
References
The text was updated successfully, but these errors were encountered: