crossplane / upjet

A code generation framework and runtime for Crossplane providers
Apache License 2.0
302 stars 86 forks source link

Ability to reference multiple types / generate resources multiple times #414

Open Breee opened 4 months ago

Breee commented 4 months ago

What problem are you facing?

How could Upjet help solve your problem?

type GenericClient interface { OpenIDClient | SamlCLient }


- Also: as i see there is no working way to generate the same resource twice, which would be ugly but feasible (and loopable):  Both do not work
p.AddResourceConfigurator("keycloak_generic_protocol_mapper", func(r *config.Resource) {
    r.ShortGroup = "client"
    r.Name = "keycloak_generic_protocol_mapper"
    r.Kind = "OpenIDProtocolMapper"
    r.References["client_scope_id"] = config.Reference{
        Type: "github.com/crossplane-contrib/provider-keycloak/apis/openidclient/v1alpha1.ClientScope",
    }
})

p.AddResourceConfigurator("keycloak_generic_protocol_mapper", func(r *config.Resource) {
    r.ShortGroup = "client"
    r.Name = "keycloak_generic_protocol_mapper"
    r.Kind = "SamlProtocolMapper"
    r.References["client_scope_id"] = config.Reference{
        Type: "github.com/crossplane-contrib/provider-keycloak/apis/samlclient/v1alpha1.ClientScope",
    }
})
// Configure keycloak_generic_protocol_mapper for OpenIdProtocolMapper
openIdConfigurator := ujconfig.ResourceConfiguratorFn(func(r *ujconfig.Resource) {
    r.ShortGroup = Group
    r.Name = "keycloak_generic_protocol_mapper"
    r.Kind = "OpenIdProtocolMapper"
    r.References["client_scope_id"] = ujconfig.Reference{
        Type: "github.com/crossplane-contrib/provider-keycloak/apis/openid/v1alpha1.ClientScope",
    }
})
// Configure keycloak_generic_protocol_mapper for SamlProtocolMapper
samlConfigurator := ujconfig.ResourceConfiguratorFn(func(r *ujconfig.Resource) {
    r.ShortGroup = Group
    r.Name = "keycloak_generic_protocol_mapper"
    r.Kind = "SamlProtocolMapper"
    r.References["client_scope_id"] = ujconfig.Reference{
        Type: "github.com/crossplane-contrib/provider-keycloak/apis/saml/v1alpha1.ClientScope",
    }
})

p.SetResourceConfigurator("keycloak_generic_protocol_mapper", ujconfig.ResourceConfiguratorChain{openIdConfigurator, samlConfigurator})


code is also on this branch: https://github.com/crossplane-contrib/provider-keycloak/blob/dfacf3ae92d66b1df511884113858be1636b1327/config/mapper/config.go#L59
yordis commented 3 months ago

@Breee could this help me with https://github.com/crossplane-contrib/provider-upjet-digitalocean/issues/36 as well? I am trying to figure out what is the best strategy to deal with more than one type for a given resource field

yordis commented 3 months ago

Also Type is deprecated so it would be TerraformName

Breee commented 3 months ago

I'm not sure, maybe maintainers @muvaf or @ulucinar can tell us if that is even possible