crossplane-contrib / provider-upjet-aws

Official AWS Provider for Crossplane by Upbound.
https://marketplace.upbound.io/providers/upbound/provider-aws
Apache License 2.0
137 stars 112 forks source link

Only add singleton list API converters for the existing APIs #1367

Closed ulucinar closed 2 weeks ago

ulucinar commented 2 weeks ago

Description of your changes

Only apply the CRD API conversions for converting between singleton list & embedded object APIs for the already existing resources with the generated singleton list CRD APIs.

When we try to add a new Terraform resource with a singleton list in its schema, currently, we need to do a manual configuration such as the following:

p.AddResourceConfigurator("azurerm_pim_active_role_assignment", func(r *config.Resource) {
        r.PreviousVersions = nil
        r.Version = "v1beta1"
        r.Conversions = nil
        r.TerraformConversions = []config.TerraformConversion{
            config.NewTFSingletonConversion(),
        }
    })

, so that the API converters registered are removed and versioning starts with v1beta1 instead of v1beta2 (for such new resources, the v1beta1 version does not already exist).

This PR records the names of resources with previous CRD APIs containing (now converted) singleton lists so that the API converters are only registered for them. This makes adding new resources with singleton lists in their Terraform schemas easier by removing the need to do a manual configuration like shown above.

The newly introduced list should mostly be immutable (it records a set of existing resources with a specific condition at a point in time). Bugs may result in exceptions where we may need to update this list. In other words, new resources should normally be never added to this list, doing so will result in an invalid configuration.

I have:

How has this code been tested

Via the following uptest runs:

ulucinar commented 2 weeks ago

/test-examples="examples/firehose/v1beta2/deliverystream.yaml"

ulucinar commented 2 weeks ago

/test-examples="examples/opensearchserverless/v1beta1/securityconfig.yaml"

ulucinar commented 2 weeks ago

/test-examples="examples/eks/v1beta2/nodegroup.yaml"

ulucinar commented 2 weeks ago

/test-examples="examples/firehose/v1beta2/deliverystream.yaml"