terrajet icon indicating copy to clipboard operation
terrajet copied to clipboard

no warning or error is produced when creating a referencer for a missing field

Open displague opened this issue 2 years ago • 2 comments

What happened?

While working on an Equinix Metal Terrajet provider, I created a metal_device project field reference, associated with the metal_project identifier.

// config/device/config.go
package device

import "github.com/crossplane-contrib/terrajet/pkg/config"

func Customize(p *config.Provider) {
        p.AddResourceConfigurator("metal_device", func(r *config.Resource) {
                r.Group = "device"
                r.ExternalName = config.IdentifierFromProvider
                r.References["project"] = config.Reference{
                        Type: "github.com/crossplane-contrib/provider-tf-equinixmetal/apis/project/v1alpha1.Project",
                }
        })
}

The problem is that project is not a valid field for metal_device. The field is project_id.

I received no error messages about this typo. make generate succeeded.

When I eventually discovered the typo and set the field name in the map to project_id, an additional file (apis/device/v1alpha1/zz_generated.resolvers.go) was generated.

How can we reproduce it?

https://github.com/crossplane-contrib/provider-tf-equinix-metal/commit/81a6d898d6703cdd63e3d81b174405ac20c7c3d0

displague avatar Nov 13 '21 23:11 displague

That's due to the look-up mechanism we have for this feature where for each field we check whether there is a referencer field, hence no error if nothing hits the given reference entry. One option could be to validate the whole configuration object before starting any operation.

muvaf avatar Jan 04 '22 09:01 muvaf

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 13 '22 00:08 stale[bot]