<p>Im looking to build a crossplane provider for my organization however im running to issues with the code generation.</p>
<p>Is there a way to manipulate how the resource names get generated? The Upjet code generations tools do not seem to respect the naming format for certain resources.</p>
<p>for example:</p>
<p>We have a terraform resource with this format.
<code>provider_load_balancer</code> after adding the resource and running <code>make generate</code>
the resource gets generated. However, the following gets generated.</p>
<pre><code>├── apis
│   ├── generate.go
│   ├── load
│   │   └── v1alpha1
│   │       ├── zz_balancer_types.go
│   │       ├── zz_generated.deepcopy.go
│   │       ├── zz_generated.managed.go
│   │       ├── zz_generated.managedlist.go
│   │       ├── zz_generated_terraformed.go
│   │       └── zz_groupversion_info.go

├── examples-generated
│   ├── load
│   │   └── balancer.yaml
</code></pre>
<p>The CRDS, yamls and file structure get generated incorrectly. Ideally, the directories and CRDS should not split the resource name but rather have them as one string <code>loadbalancer</code></p>
<p>Below we see even the deepcopy methods get generated with the wrong name. These Should be <code>loadbalancer</code> not <code>balancer</code></p>
<pre><code>// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Balancer) DeepCopyInto(out *Balancer) {
    *out = *in
    out.TypeMeta = in.TypeMeta
    in.ObjectMeta.DeepCopyInto(&amp;out.ObjectMeta)
    in.Spec.DeepCopyInto(&amp;out.Spec)
    in.Status.DeepCopyInto(&amp;out.Status)
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Balancer.
func (in *Balancer) DeepCopy() *Balancer {
    if in == nil {
        return nil
    }
    out := new(Balancer)
    in.DeepCopyInto(out)
    return out
}

</code></pre>
<p>Any ideas about what I can do here?</p>

mondragonfx
<p>You can customize the group for an individual generated resource by adding a <code>ResourceConfigurator</code> for it. This is mentioned briefly in the GitHub provider example in the upjet <a href="https://github.com/upbound/upjet/blob/main/docs/generating-a-provider.md?plain=1#L127" rel="nofollow noreferrer">docs</a>.</p>
<pre class="lang-bash prettyprint-override"><code>   cat &lt;&lt;EOF &gt; config/repository/config.go
   package repository

   import &quot;github.com/upbound/upjet/pkg/config&quot;

   // Configure configures individual resources by adding custom ResourceConfigurators.
   func Configure(p *config.Provider) {
       p.AddResourceConfigurator(&quot;github_repository&quot;, func(r *config.Resource) {
           // We need to override the default group that upjet generated for
           // this resource, which would be &quot;github&quot;
           r.ShortGroup = &quot;repository&quot;
       })
   }
   EOF
</code></pre>
<p>For a more significant example of customization, have a look at provider-aws, which uses a <a href="https://github.com/upbound/provider-aws/blob/main/config/groups.go#L39" rel="nofollow noreferrer">custom mapping and trimming function</a> to map from certain terraform resource names into specific Groups and Kinds.</p>
<pre class="lang-golang prettyprint-override"><code>// GroupKindOverrides overrides the group and kind of the resource if it matches
// any entry in the GroupMap.
func GroupKindOverrides() config.ResourceOption {
    return func(r *config.Resource) {
        if f, ok := GroupMap[r.Name]; ok {
            r.ShortGroup, r.Kind = f(r.Name)
        }
    }
}

// KindOverrides overrides the kind of the resources given in KindMap.
func KindOverrides() config.ResourceOption {
    return func(r *config.Resource) {
        if k, ok := KindMap[r.Name]; ok {
            r.Kind = k
        }
    }
}
</code></pre>
<p>This is then added into <a href="https://github.com/upbound/provider-aws/blob/main/config/provider.go#L138" rel="nofollow noreferrer">config/provider.go</a> to customize the behavior of the generator.</p>
<pre class="lang-golang prettyprint-override"><code>// GetProvider returns provider configuration
func GetProvider() *config.Provider {
    modulePath := &quot;github.com/upbound/provider-aws&quot;
    pc := config.NewProvider([]byte(providerSchema), &quot;aws&quot;,
        modulePath, providerMetadata,
        config.WithShortName(&quot;aws&quot;),
        config.WithRootGroup(&quot;aws.upbound.io&quot;),
...
        config.WithDefaultResourceOptions(
            GroupKindOverrides(),
            KindOverrides(),        
...
        ),
        config.WithMainTemplate(hack.MainTemplate),
    )
...
</code></pre>
