crossplane / terrajet

Generate Crossplane Providers from any Terraform Provider
https://crossplane.io
Apache License 2.0
289 stars 38 forks source link

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

Open displague opened 2 years ago

displague commented 2 years ago

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

muvaf commented 2 years ago

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.

stale[bot] commented 1 year ago

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.