Closed turkenh closed 2 years ago
@muvaf, as we discussed offline on possible solutions here, I gave it a try simply appending indexes as long as we could find a unique type name. It worked well at first but then I realized that we are appending Parameter
to the top-level resource spec no matter what we generate as type.
Not being happy to modify the logic there to print the generated type, I gave it a try to another approach, which is always generating the longest possible name instead of starting with shorted and extending as long as it already in use.
@@ -285,9 +290,6 @@ func (g *Builder) buildSchema(sch *schema.Schema, cfg *config.Resource, tfPath [
func (g *Builder) generateTypeName(suffix string, names ...string) (string, error) {
n := names[len(names)-1] + suffix
for i := len(names) - 2; i >= 0; i-- {
- if g.Package.Scope().Lookup(n) == nil {
- return n, nil
- }
n = names[i] + n
}
if g.Package.Scope().Lookup(n) == nil {
This sounded like a solution at least for the resource here, however, I found out that this wouldn't work for another resource in provider-tf-gcp, which fails due to a contention between google_bigquery_dataset and google_bigquery_dataset_access:
panic: cannot generate crd for resource google_bigquery_dataset_access: cannot build types for DatasetAccess: cannot build the types: cannot generate parameters type name of DatasetAccess: could not generate a unique name for DatasetAccessParameters
Hence, falling back to the initial plan and will modify the logic in the CRD template accordingly.
What happened?
While trying to generate
google_compute_subnetwork
together withgoogle_compute_router_nat
resource, Terrajet fails to find a unique name forSubnetworkParameters
:This is because
google_compute_router_nat
resource already have a type namedSubnetworkParameters
generated andgoogle_compute_subnetwork
resource coming after it alphabetically (since we are sorting for stability) fails to generate a type for top level parameter struct.I believe we will need a way to configure type names to handle such cases.
How can we reproduce it?
Try generating both resources together in provider-tf-gcp.