Skip to content

Validate result from UpgradeResourceIdentity matches current schema #1488

@ansgarm

Description

@ansgarm

Currently there are no safe-guards when resource identity upgrade functions are called. This mirrors the existing design for state upgrade functions that have the exact same problem.

This means that an erroneous implementation in the provider can lead to parts of the identity being accidentally set as null values if no new value is set (i.e. if the new identity version has new fields). This happens because Terraform doesn't validate the identity against its schema anymore.

We could add some validation to the upgradeJSONIdentity function

func (s *GRPCProviderServer) upgradeJSONIdentity(ctx context.Context, version int64, m map[string]interface{}, res *Resource) (map[string]interface{}, error) {
var err error
for _, upgrader := range res.Identity.IdentityUpgraders {
if version != upgrader.Version {
continue
}
m, err = upgrader.Upgrade(ctx, m, s.provider.Meta())
if err != nil {
return nil, err
}
version++
}
return m, nil
}
to show an error instead. This error would then tell the user that this is a bug in the provider and should be reported to its maintainer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions