upjet icon indicating copy to clipboard operation
upjet copied to clipboard

Ability to reference multiple types / generate resources multiple times

Open Breee opened this issue 8 months ago • 3 comments

What problem are you facing?

  • The keycloak provider is generated via upjet
  • I'm currently facing the issue that the terraform provider uses generic types under the hood, for example for Clients
  • In reality we have OpenID Client and Saml Client and sadly no Generic Client available as resource.
  • This leads to problems when i have to create references for resources which just reference a Client, which can be both OpenId Client or Saml Client
  • The upstream Terraform provider is dying and is unmaintained

How could Upjet help solve your problem?

  • I'm looking for a way to have references to either a Generic Type or multiple Types OR just generate a resource multiple times with different Kinds + References
  • simplified example:
r.References["client_id"] = config.Reference{
	Type:  []{"github.com/crossplane-contrib/provider-keycloak/apis/openidclient/v1alpha1.Client", "github.com/crossplane-contrib/provider-keycloak/apis/samlclient/v1alpha1.Client},
	}
  • Or allow to do something like:
package v1alpha

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

Breee avatar Jun 02 '24 09:06 Breee