From bbac0a6bdd8836a8c6d65690526e38cc4ca61f4d Mon Sep 17 00:00:00 2001 From: Alper Rifat Ulucinar Date: Fri, 26 Jan 2024 19:10:25 +0300 Subject: [PATCH] Add the --api-group-override command-line option to the resolver transformation to be able to override the generated API group names. - Add the --api-resolver-package command-line option to the resolver transformation to properly configure the package of the GetManagedResource function. Signed-off-by: Alper Rifat Ulucinar --- cmd/resolver/main.go | 4 +- pkg/transformers/resolver.go | 51 +- pkg/transformers/resolver_test.go | 26 +- ...pigatewayv2.resolvers.withoverrides.go.txt | 1032 +++++++++++++++++ 4 files changed, 1107 insertions(+), 6 deletions(-) create mode 100644 pkg/transformers/testdata/apigatewayv2.resolvers.withoverrides.go.txt diff --git a/cmd/resolver/main.go b/cmd/resolver/main.go index ccf8b1c2..6b769747 100644 --- a/cmd/resolver/main.go +++ b/cmd/resolver/main.go @@ -20,12 +20,14 @@ func main() { var ( app = kingpin.New(filepath.Base(os.Args[0]), "Transformer for the generated resolvers by the crossplane-tools so that cross API-group imports are removed.").DefaultEnvars() apiGroupSuffix = app.Flag("apiGroupSuffix", "Resource API group suffix, such as aws.upbound.io. The resource API group names are suffixed with this to get the canonical API group name.").Short('g').Required().String() + apiGroupOverride = app.Flag("apiGroupOverride", "API group overrides").Short('o').StringMap() + apiResolverPackage = app.Flag("apiResolverPackage", "The package that contains the implementation for the GetManagedResource function, such as github.com/upbound/provider-aws/internal/apis.").Short('a').Required().String() pattern = app.Flag("pattern", "List patterns for the packages to process, such as ./...").Short('p').Default("./...").Strings() resolverFilePattern = app.Flag("resolver", "Name of the generated resolver files to process.").Short('r').Default("zz_generated.resolvers.go").String() ignorePackageLoadErrors = app.Flag("ignoreLoadErrors", "Ignore errors encountered while loading the packages.").Short('s').Bool() ) kingpin.MustParse(app.Parse(os.Args[1:])) logger := logging.NewLogrLogger(zap.New().WithName("transformer-resolver")) - r := transformers.NewResolver(afero.NewOsFs(), *apiGroupSuffix, *ignorePackageLoadErrors, logger) + r := transformers.NewResolver(afero.NewOsFs(), *apiGroupSuffix, *apiResolverPackage, *ignorePackageLoadErrors, logger, transformers.WithAPIGroupOverrides(*apiGroupOverride)) kingpin.FatalIfError(r.TransformPackages(*resolverFilePattern, *pattern...), "Failed to transform the resolver files in the specified packages.") } diff --git a/pkg/transformers/resolver.go b/pkg/transformers/resolver.go index 9a0ff9e9..8078616b 100644 --- a/pkg/transformers/resolver.go +++ b/pkg/transformers/resolver.go @@ -42,6 +42,21 @@ type Resolver struct { // managed resources, such as aws.upbound.io. Then a sample // API group for a resource is ec2.aws.upbound.io. apiGroupSuffix string + // API group overrides for the provider. Certain providers need + // to rename the short API group names they use, breaking the + // convention that the short group name matches the package name. + // An example is upbound/provider-azure, where the ResourceGroup.azure + // resource's short API group is the empty string. This map allows such + // providers to control the names of the generated API group names by this + // Resolver transformer. + apiGroupOverrides map[string]string + // the API resolver package that contains the + // `GetManagedResource("group", "version", "kind", "listKind")` + // function. This function is used to initialize a managed resource and + // its list type, owned by the provider, with the given API group, version, + // kind and list kind. Signature of the resolver function is as follows: + // func GetManagedResource(group, version, kind, listKind string) (xpresource.Managed, xpresource.ManagedList, error) + apiResolverPackage string // When set, any errors encountered while loading the source packages is // silently ignored if a logger is not configured, // or logged via the configured logger. @@ -54,13 +69,14 @@ type Resolver struct { } // NewResolver initializes a new Resolver with the specified configuration. -func NewResolver(fs afero.Fs, apiGroupSuffix string, ignorePackageLoadErrors bool, logger logging.Logger, opts ...ResolverOption) *Resolver { +func NewResolver(fs afero.Fs, apiGroupSuffix, apiResolverPackage string, ignorePackageLoadErrors bool, logger logging.Logger, opts ...ResolverOption) *Resolver { if logger == nil { logger = logging.NewNopLogger() } r := &Resolver{ fs: fs, apiGroupSuffix: apiGroupSuffix, + apiResolverPackage: apiResolverPackage, ignorePackageLoadErrors: ignorePackageLoadErrors, logger: logger, config: &packages.Config{ @@ -83,6 +99,17 @@ func WithLoaderConfig(c *packages.Config) ResolverOption { } } +// WithAPIGroupOverrides configures the API group overrides for a Resolver. +// Certain providers need to rename the short API group names they use, +// breaking the convention that the short group name matches the package name. +// An example is upbound/provider-azure, where the ResourceGroup.azure +// resource's short API group is the empty string. +func WithAPIGroupOverrides(overrides map[string]string) ResolverOption { + return func(r *Resolver) { + r.apiGroupOverrides = overrides + } +} + // TransformPackages applies the dynamic resolver transformation to // the resolver modules loaded from the specified patterns and // implemented in the specified resolver files. If `r.ignorePackageLoadErrors` @@ -324,6 +351,8 @@ func (r *Resolver) transformResolverFile(fset *token.FileSet, node *ast.File, fi version = tokens[len(tokens)-1] // e.g., ec2.aws.upbound.io group = fmt.Sprintf("%s.%s", tokens[len(tokens)-2], apiGroupSuffix) + // apply any configured group name overrides + group = r.overrideGroupName(group) // extract the kind and list kind names from the field // selector. if sexpr.Sel != nil { @@ -346,6 +375,8 @@ func (r *Resolver) transformResolverFile(fset *token.FileSet, node *ast.File, fi version = tokens[len(tokens)-2] // e.g., cur.aws.upbound.io group = fmt.Sprintf("%s.%s", tokens[len(tokens)-3], apiGroupSuffix) + // apply any configured group name overrides + group = r.overrideGroupName(group) if ident, ok := cl.Type.(*ast.Ident); ok { if key == "List" { listKind = ident.Name @@ -389,7 +420,7 @@ func (r *Resolver) transformResolverFile(fset *token.FileSet, node *ast.File, fi // get the statements including the import statements we need to make // calls to the type registry. - mrImports, stmts := getManagedResourceStatements(group, version, kind, listKind) + mrImports, stmts := getManagedResourceStatements(group, version, kind, listKind, r.apiResolverPackage) // insert the statements that implement type registry lookups if !insertStatements(stmts, block, assign) { inspectErr = errors.Errorf("failed to insert the type registry lookup statements for Group: %q, Version: %q, Kind: %q, List Kind: %q", group, version, kind, listKind) @@ -532,7 +563,7 @@ func addMRVariableDeclarations(f *ast.File) map[string]string { } } -func getManagedResourceStatements(group, version, kind, listKind string) (map[string]string, []ast.Stmt) { +func getManagedResourceStatements(group, version, kind, listKind, apiResolverPackage string) (map[string]string, []ast.Stmt) { // prepare the assignment statement: // `m, l, err = apisresolver.GetManagedResource("group", "version", "kind", "listKind")` assignStmt := &ast.AssignStmt{ @@ -590,6 +621,18 @@ func getManagedResourceStatements(group, version, kind, listKind string) (map[st }, } return map[string]string{ - `"github.com/upbound/provider-aws/internal/apis"`: "apisresolver", + // TODO: we may need to parameterize the import alias in the future, if + // any provider that uses the transformer has an import alias collision + // which is not very likely. + fmt.Sprintf(`"%s"`, apiResolverPackage): "apisresolver", }, []ast.Stmt{assignStmt, ifStmt} } + +func (r *Resolver) overrideGroupName(group string) string { + g, ok := r.apiGroupOverrides[group] + // we need to allow overrides with an empty string + if !ok { + return group + } + return g +} diff --git a/pkg/transformers/resolver_test.go b/pkg/transformers/resolver_test.go index 8feb2b30..efd6f949 100644 --- a/pkg/transformers/resolver_test.go +++ b/pkg/transformers/resolver_test.go @@ -19,6 +19,8 @@ func TestTransformPackages(t *testing.T) { // args struct to define input arguments for each test case type args struct { apiGroupSuffix string + apiResolverPackage string + apiGroupOverrides map[string]string resolverFilePattern string ignorePackageLoadErrors bool patterns []string @@ -44,6 +46,7 @@ func TestTransformPackages(t *testing.T) { reason: "Transformation of the source file that has been generated by crossplane-tool's angryjet succeeds with the expected transformed file.", args: args{ apiGroupSuffix: "aws.upbound.io", + apiResolverPackage: "github.com/upbound/provider-aws/internal/apis", resolverFilePattern: "zz_generated.resolvers.go", inputFilePath: "testdata/apigatewayv2.resolvers.go.txt", ignorePackageLoadErrors: true, @@ -57,6 +60,7 @@ func TestTransformPackages(t *testing.T) { reason: "The applied transformation is idempotent, i.e., applying the transformer on an already transformed file does not change the transformed file.", args: args{ apiGroupSuffix: "aws.upbound.io", + apiResolverPackage: "github.com/upbound/provider-aws/internal/apis", resolverFilePattern: "zz_generated.resolvers.go", inputFilePath: "testdata/apigatewayv2.resolvers.transformed.go.txt", ignorePackageLoadErrors: true, @@ -70,6 +74,7 @@ func TestTransformPackages(t *testing.T) { reason: "The transformation source is not a valid angryjet-generated resolver file: List type is missing for a resolution source.", args: args{ apiGroupSuffix: "aws.upbound.io", + apiResolverPackage: "github.com/upbound/provider-aws/internal/apis", resolverFilePattern: "zz_generated.resolvers.go", inputFilePath: "testdata/missing_list_type.resolvers.go.txt", ignorePackageLoadErrors: true, @@ -85,6 +90,23 @@ func TestTransformPackages(t *testing.T) { }, }, }, + "SuccessfulTransformationWithGroupOverrides": { + reason: "Transformation of the source file with a group overrides configuration succeeds with the expected transformed file.", + args: args{ + apiGroupSuffix: "aws.upbound.io", + apiResolverPackage: "github.com/upbound/provider-aws/internal/resolver", + apiGroupOverrides: map[string]string{ + "ec2.aws.upbound.io": "replacedec2.aws.upbound.io", + }, + resolverFilePattern: "zz_generated.resolvers.go", + inputFilePath: "testdata/apigatewayv2.resolvers.go.txt", + ignorePackageLoadErrors: true, + patterns: []string{"./testdata"}, + }, + want: want{ + transformedPath: "testdata/apigatewayv2.resolvers.withoverrides.go.txt", + }, + }, } for name, tc := range cases { @@ -101,7 +123,9 @@ func TestTransformPackages(t *testing.T) { transformedFilePath := filepath.Join(exported.Temp(), "fake", "testdata", tc.args.resolverFilePattern) writeFile(t, memFS, transformedFilePath, []byte(inputFileContents), tc.reason) - r := NewResolver(memFS, tc.args.apiGroupSuffix, tc.args.ignorePackageLoadErrors, nil, WithLoaderConfig(exported.Config)) + r := NewResolver(memFS, tc.args.apiGroupSuffix, tc.args.apiResolverPackage, tc.args.ignorePackageLoadErrors, nil, + WithLoaderConfig(exported.Config), + WithAPIGroupOverrides(tc.args.apiGroupOverrides)) err := r.TransformPackages("zz_generated.resolvers.go", tc.args.patterns...) var wantErr error if tc.want.errFunc != nil { diff --git a/pkg/transformers/testdata/apigatewayv2.resolvers.withoverrides.go.txt b/pkg/transformers/testdata/apigatewayv2.resolvers.withoverrides.go.txt new file mode 100644 index 00000000..fcf1d5d8 --- /dev/null +++ b/pkg/transformers/testdata/apigatewayv2.resolvers.withoverrides.go.txt @@ -0,0 +1,1032 @@ +// SPDX-FileCopyrightText: 2024 The Crossplane Authors +// +// SPDX-License-Identifier: Apache-2.0 +// Code generated by angryjet. DO NOT EDIT. +// Code transformed by upjet. DO NOT EDIT. + +package v1beta1 + +import ( + "context" + reference "github.com/crossplane/crossplane-runtime/pkg/reference" + resource "github.com/crossplane/upjet/pkg/resource" + errors "github.com/pkg/errors" + + xpresource "github.com/crossplane/crossplane-runtime/pkg/resource" + common "github.com/upbound/provider-aws/config/common" + apis "github.com/upbound/provider-aws/config/common/apis" + lambda "github.com/upbound/provider-aws/config/common/apis/lambda" + apisresolver "github.com/upbound/provider-aws/internal/resolver" + client "sigs.k8s.io/controller-runtime/pkg/client" +) + +func (mg *APIMapping) ResolveReferences( // ResolveReferences of this APIMapping. + ctx context.Context, c client.Reader) error { + var m xpresource.Managed + var l xpresource.ManagedList + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "API", "APIList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.APIID), + Extract: reference.ExternalName(), + Reference: mg.Spec.ForProvider.APIIDRef, + Selector: mg.Spec.ForProvider.APIIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.APIID") + } + mg.Spec.ForProvider.APIID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.APIIDRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "DomainName", "DomainNameList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.DomainName), + Extract: reference.ExternalName(), + Reference: mg.Spec.ForProvider.DomainNameRef, + Selector: mg.Spec.ForProvider.DomainNameSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.DomainName") + } + mg.Spec.ForProvider.DomainName = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.DomainNameRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "Stage", "StageList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.Stage), + Extract: common.TerraformID(), + Reference: mg.Spec.ForProvider.StageRef, + Selector: mg.Spec.ForProvider.StageSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.Stage") + } + mg.Spec.ForProvider.Stage = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.StageRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "API", "APIList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.APIID), + Extract: reference.ExternalName(), + Reference: mg.Spec.InitProvider.APIIDRef, + Selector: mg.Spec.InitProvider.APIIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.InitProvider.APIID") + } + mg.Spec.InitProvider.APIID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.InitProvider.APIIDRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "DomainName", "DomainNameList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.DomainName), + Extract: reference.ExternalName(), + Reference: mg.Spec.InitProvider.DomainNameRef, + Selector: mg.Spec.InitProvider.DomainNameSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.InitProvider.DomainName") + } + mg.Spec.InitProvider.DomainName = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.InitProvider.DomainNameRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "Stage", "StageList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.Stage), + Extract: common.TerraformID(), + Reference: mg.Spec.InitProvider.StageRef, + Selector: mg.Spec.InitProvider.StageSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.InitProvider.Stage") + } + mg.Spec.InitProvider.Stage = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.InitProvider.StageRef = rsp.ResolvedReference + + return nil +} + +// ResolveReferences of this Authorizer. +func (mg *Authorizer) ResolveReferences(ctx context.Context, c client.Reader) error { + var m xpresource.Managed + var l xpresource.ManagedList + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "API", "APIList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.APIID), + Extract: reference.ExternalName(), + Reference: mg.Spec.ForProvider.APIIDRef, + Selector: mg.Spec.ForProvider.APIIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.APIID") + } + mg.Spec.ForProvider.APIID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.APIIDRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("lambda.aws.upbound.io", "v1beta1", "Function", "FunctionList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.AuthorizerURI), + Extract: lambda.FunctionInvokeARN(), + Reference: mg.Spec.ForProvider.AuthorizerURIRef, + Selector: mg.Spec.ForProvider.AuthorizerURISelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.AuthorizerURI") + } + mg.Spec.ForProvider.AuthorizerURI = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.AuthorizerURIRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "API", "APIList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.APIID), + Extract: reference.ExternalName(), + Reference: mg.Spec.InitProvider.APIIDRef, + Selector: mg.Spec.InitProvider.APIIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.InitProvider.APIID") + } + mg.Spec.InitProvider.APIID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.InitProvider.APIIDRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("lambda.aws.upbound.io", "v1beta1", "Function", "FunctionList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.AuthorizerURI), + Extract: lambda.FunctionInvokeARN(), + Reference: mg.Spec.InitProvider.AuthorizerURIRef, + Selector: mg.Spec.InitProvider.AuthorizerURISelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.InitProvider.AuthorizerURI") + } + mg.Spec.InitProvider.AuthorizerURI = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.InitProvider.AuthorizerURIRef = rsp.ResolvedReference + + return nil +} + +// ResolveReferences of this Deployment. +func (mg *Deployment) ResolveReferences(ctx context.Context, c client.Reader) error { + var m xpresource.Managed + var l xpresource.ManagedList + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "API", "APIList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.APIID), + Extract: reference.ExternalName(), + Reference: mg.Spec.ForProvider.APIIDRef, + Selector: mg.Spec.ForProvider.APIIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.APIID") + } + mg.Spec.ForProvider.APIID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.APIIDRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "API", "APIList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.APIID), + Extract: reference.ExternalName(), + Reference: mg.Spec.InitProvider.APIIDRef, + Selector: mg.Spec.InitProvider.APIIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.InitProvider.APIID") + } + mg.Spec.InitProvider.APIID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.InitProvider.APIIDRef = rsp.ResolvedReference + + return nil +} + +// ResolveReferences of this DomainName. +func (mg *DomainName) ResolveReferences(ctx context.Context, c client.Reader) error { + var m xpresource.Managed + var l xpresource.ManagedList + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + + for i3 := 0; i3 < len(mg.Spec.ForProvider.DomainNameConfiguration); i3++ { + { + m, l, err = apisresolver.GetManagedResource("acm.aws.upbound.io", "v1beta1", "Certificate", "CertificateList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.DomainNameConfiguration[i3].CertificateArn), + Extract: common.ARNExtractor(), + Reference: mg.Spec.ForProvider.DomainNameConfiguration[i3].CertificateArnRef, + Selector: mg.Spec.ForProvider.DomainNameConfiguration[i3].CertificateArnSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.DomainNameConfiguration[i3].CertificateArn") + } + mg.Spec.ForProvider.DomainNameConfiguration[i3].CertificateArn = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.DomainNameConfiguration[i3].CertificateArnRef = rsp.ResolvedReference + + } + for i3 := 0; i3 < len(mg.Spec.InitProvider.DomainNameConfiguration); i3++ { + { + m, l, err = apisresolver.GetManagedResource("acm.aws.upbound.io", "v1beta1", "Certificate", "CertificateList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.DomainNameConfiguration[i3].CertificateArn), + Extract: common.ARNExtractor(), + Reference: mg.Spec.InitProvider.DomainNameConfiguration[i3].CertificateArnRef, + Selector: mg.Spec.InitProvider.DomainNameConfiguration[i3].CertificateArnSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.InitProvider.DomainNameConfiguration[i3].CertificateArn") + } + mg.Spec.InitProvider.DomainNameConfiguration[i3].CertificateArn = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.InitProvider.DomainNameConfiguration[i3].CertificateArnRef = rsp.ResolvedReference + + } + + return nil +} + +// ResolveReferences of this Integration. +func (mg *Integration) ResolveReferences(ctx context.Context, c client.Reader) error { + var m xpresource.Managed + var l xpresource.ManagedList + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "API", "APIList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.APIID), + Extract: reference.ExternalName(), + Reference: mg.Spec.ForProvider.APIIDRef, + Selector: mg.Spec.ForProvider.APIIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.APIID") + } + mg.Spec.ForProvider.APIID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.APIIDRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "VPCLink", "VPCLinkList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.ConnectionID), + Extract: resource.ExtractResourceID(), + Reference: mg.Spec.ForProvider.ConnectionIDRef, + Selector: mg.Spec.ForProvider.ConnectionIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.ConnectionID") + } + mg.Spec.ForProvider.ConnectionID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.ConnectionIDRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("iam.aws.upbound.io", "v1beta1", "Role", "RoleList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.CredentialsArn), + Extract: resource.ExtractParamPath("arn", true), + Reference: mg.Spec.ForProvider.CredentialsArnRef, + Selector: mg.Spec.ForProvider.CredentialsArnSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.CredentialsArn") + } + mg.Spec.ForProvider.CredentialsArn = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.CredentialsArnRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("lambda.aws.upbound.io", "v1beta1", "Function", "FunctionList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.IntegrationURI), + Extract: resource.ExtractParamPath("invoke_arn", true), + Reference: mg.Spec.ForProvider.IntegrationURIRef, + Selector: mg.Spec.ForProvider.IntegrationURISelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.IntegrationURI") + } + mg.Spec.ForProvider.IntegrationURI = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.IntegrationURIRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "API", "APIList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.APIID), + Extract: reference.ExternalName(), + Reference: mg.Spec.InitProvider.APIIDRef, + Selector: mg.Spec.InitProvider.APIIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.InitProvider.APIID") + } + mg.Spec.InitProvider.APIID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.InitProvider.APIIDRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "VPCLink", "VPCLinkList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.ConnectionID), + Extract: resource.ExtractResourceID(), + Reference: mg.Spec.InitProvider.ConnectionIDRef, + Selector: mg.Spec.InitProvider.ConnectionIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.InitProvider.ConnectionID") + } + mg.Spec.InitProvider.ConnectionID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.InitProvider.ConnectionIDRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("iam.aws.upbound.io", "v1beta1", "Role", "RoleList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.CredentialsArn), + Extract: resource.ExtractParamPath("arn", true), + Reference: mg.Spec.InitProvider.CredentialsArnRef, + Selector: mg.Spec.InitProvider.CredentialsArnSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.InitProvider.CredentialsArn") + } + mg.Spec.InitProvider.CredentialsArn = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.InitProvider.CredentialsArnRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("lambda.aws.upbound.io", "v1beta1", "Function", "FunctionList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.IntegrationURI), + Extract: resource.ExtractParamPath("invoke_arn", true), + Reference: mg.Spec.InitProvider.IntegrationURIRef, + Selector: mg.Spec.InitProvider.IntegrationURISelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.InitProvider.IntegrationURI") + } + mg.Spec.InitProvider.IntegrationURI = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.InitProvider.IntegrationURIRef = rsp.ResolvedReference + + return nil +} + +// ResolveReferences of this IntegrationResponse. +func (mg *IntegrationResponse) ResolveReferences(ctx context.Context, c client.Reader) error { + var m xpresource.Managed + var l xpresource.ManagedList + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "API", "APIList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.APIID), + Extract: reference.ExternalName(), + Reference: mg.Spec.ForProvider.APIIDRef, + Selector: mg.Spec.ForProvider.APIIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.APIID") + } + mg.Spec.ForProvider.APIID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.APIIDRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "Integration", "IntegrationList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.IntegrationID), + Extract: reference.ExternalName(), + Reference: mg.Spec.ForProvider.IntegrationIDRef, + Selector: mg.Spec.ForProvider.IntegrationIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.IntegrationID") + } + mg.Spec.ForProvider.IntegrationID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.IntegrationIDRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "API", "APIList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.APIID), + Extract: reference.ExternalName(), + Reference: mg.Spec.InitProvider.APIIDRef, + Selector: mg.Spec.InitProvider.APIIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.InitProvider.APIID") + } + mg.Spec.InitProvider.APIID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.InitProvider.APIIDRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "Integration", "IntegrationList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.IntegrationID), + Extract: reference.ExternalName(), + Reference: mg.Spec.InitProvider.IntegrationIDRef, + Selector: mg.Spec.InitProvider.IntegrationIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.InitProvider.IntegrationID") + } + mg.Spec.InitProvider.IntegrationID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.InitProvider.IntegrationIDRef = rsp.ResolvedReference + + return nil +} + +// ResolveReferences of this Model. +func (mg *Model) ResolveReferences(ctx context.Context, c client.Reader) error { + var m xpresource.Managed + var l xpresource.ManagedList + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "API", "APIList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.APIID), + Extract: reference.ExternalName(), + Reference: mg.Spec.ForProvider.APIIDRef, + Selector: mg.Spec.ForProvider.APIIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.APIID") + } + mg.Spec.ForProvider.APIID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.APIIDRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "API", "APIList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.APIID), + Extract: reference.ExternalName(), + Reference: mg.Spec.InitProvider.APIIDRef, + Selector: mg.Spec.InitProvider.APIIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.InitProvider.APIID") + } + mg.Spec.InitProvider.APIID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.InitProvider.APIIDRef = rsp.ResolvedReference + + return nil +} + +// ResolveReferences of this Route. +func (mg *Route) ResolveReferences(ctx context.Context, c client.Reader) error { + var m xpresource.Managed + var l xpresource.ManagedList + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "API", "APIList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.APIID), + Extract: reference.ExternalName(), + Reference: mg.Spec.ForProvider.APIIDRef, + Selector: mg.Spec.ForProvider.APIIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.APIID") + } + mg.Spec.ForProvider.APIID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.APIIDRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "Authorizer", "AuthorizerList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.AuthorizerID), + Extract: reference.ExternalName(), + Reference: mg.Spec.ForProvider.AuthorizerIDRef, + Selector: mg.Spec.ForProvider.AuthorizerIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.AuthorizerID") + } + mg.Spec.ForProvider.AuthorizerID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.AuthorizerIDRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "Integration", "IntegrationList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.Target), + Extract: apis.IntegrationIDPrefixed(), + Reference: mg.Spec.ForProvider.TargetRef, + Selector: mg.Spec.ForProvider.TargetSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.Target") + } + mg.Spec.ForProvider.Target = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.TargetRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "API", "APIList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.APIID), + Extract: reference.ExternalName(), + Reference: mg.Spec.InitProvider.APIIDRef, + Selector: mg.Spec.InitProvider.APIIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.InitProvider.APIID") + } + mg.Spec.InitProvider.APIID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.InitProvider.APIIDRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "Authorizer", "AuthorizerList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.AuthorizerID), + Extract: reference.ExternalName(), + Reference: mg.Spec.InitProvider.AuthorizerIDRef, + Selector: mg.Spec.InitProvider.AuthorizerIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.InitProvider.AuthorizerID") + } + mg.Spec.InitProvider.AuthorizerID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.InitProvider.AuthorizerIDRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "Integration", "IntegrationList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.Target), + Extract: apis.IntegrationIDPrefixed(), + Reference: mg.Spec.InitProvider.TargetRef, + Selector: mg.Spec.InitProvider.TargetSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.InitProvider.Target") + } + mg.Spec.InitProvider.Target = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.InitProvider.TargetRef = rsp.ResolvedReference + + return nil +} + +// ResolveReferences of this RouteResponse. +func (mg *RouteResponse) ResolveReferences(ctx context.Context, c client.Reader) error { + var m xpresource.Managed + var l xpresource.ManagedList + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "API", "APIList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.APIID), + Extract: reference.ExternalName(), + Reference: mg.Spec.ForProvider.APIIDRef, + Selector: mg.Spec.ForProvider.APIIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.APIID") + } + mg.Spec.ForProvider.APIID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.APIIDRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "Route", "RouteList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.RouteID), + Extract: reference.ExternalName(), + Reference: mg.Spec.ForProvider.RouteIDRef, + Selector: mg.Spec.ForProvider.RouteIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.RouteID") + } + mg.Spec.ForProvider.RouteID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.RouteIDRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "API", "APIList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.APIID), + Extract: reference.ExternalName(), + Reference: mg.Spec.InitProvider.APIIDRef, + Selector: mg.Spec.InitProvider.APIIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.InitProvider.APIID") + } + mg.Spec.InitProvider.APIID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.InitProvider.APIIDRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "Route", "RouteList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.RouteID), + Extract: reference.ExternalName(), + Reference: mg.Spec.InitProvider.RouteIDRef, + Selector: mg.Spec.InitProvider.RouteIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.InitProvider.RouteID") + } + mg.Spec.InitProvider.RouteID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.InitProvider.RouteIDRef = rsp.ResolvedReference + + return nil +} + +// ResolveReferences of this Stage. +func (mg *Stage) ResolveReferences(ctx context.Context, c client.Reader) error { + var m xpresource.Managed + var l xpresource.ManagedList + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "API", "APIList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.APIID), + Extract: reference.ExternalName(), + Reference: mg.Spec.ForProvider.APIIDRef, + Selector: mg.Spec.ForProvider.APIIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.APIID") + } + mg.Spec.ForProvider.APIID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.APIIDRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "Deployment", "DeploymentList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.DeploymentID), + Extract: reference.ExternalName(), + Reference: mg.Spec.ForProvider.DeploymentIDRef, + Selector: mg.Spec.ForProvider.DeploymentIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.DeploymentID") + } + mg.Spec.ForProvider.DeploymentID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.ForProvider.DeploymentIDRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "API", "APIList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.APIID), + Extract: reference.ExternalName(), + Reference: mg.Spec.InitProvider.APIIDRef, + Selector: mg.Spec.InitProvider.APIIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.InitProvider.APIID") + } + mg.Spec.InitProvider.APIID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.InitProvider.APIIDRef = rsp.ResolvedReference + { + m, l, err = apisresolver.GetManagedResource("fake.aws.upbound.io", "testdata", "Deployment", "DeploymentList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ + CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.DeploymentID), + Extract: reference.ExternalName(), + Reference: mg.Spec.InitProvider.DeploymentIDRef, + Selector: mg.Spec.InitProvider.DeploymentIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.InitProvider.DeploymentID") + } + mg.Spec.InitProvider.DeploymentID = reference.ToPtrValue(rsp.ResolvedValue) + mg.Spec.InitProvider.DeploymentIDRef = rsp.ResolvedReference + + return nil +} + +// ResolveReferences of this VPCLink. +func (mg *VPCLink) ResolveReferences(ctx context.Context, c client.Reader) error { + var m xpresource.Managed + var l xpresource.ManagedList + r := reference.NewAPIResolver(c, mg) + + var mrsp reference.MultiResolutionResponse + var err error + { + m, l, err = apisresolver.GetManagedResource("replacedec2.aws.upbound.io", "v1beta1", "SecurityGroup", "SecurityGroupList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + mrsp, err = r.ResolveMultiple(ctx, reference.MultiResolutionRequest{ + CurrentValues: reference.FromPtrValues(mg.Spec.ForProvider.SecurityGroupIds), + Extract: reference.ExternalName(), + References: mg.Spec.ForProvider.SecurityGroupIDRefs, + Selector: mg.Spec.ForProvider.SecurityGroupIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.SecurityGroupIds") + } + mg.Spec.ForProvider.SecurityGroupIds = reference.ToPtrValues(mrsp.ResolvedValues) + mg.Spec.ForProvider.SecurityGroupIDRefs = mrsp.ResolvedReferences + { + m, l, err = apisresolver.GetManagedResource("replacedec2.aws.upbound.io", "v1beta1", "Subnet", "SubnetList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + mrsp, err = r.ResolveMultiple(ctx, reference.MultiResolutionRequest{ + CurrentValues: reference.FromPtrValues(mg.Spec.ForProvider.SubnetIds), + Extract: reference.ExternalName(), + References: mg.Spec.ForProvider.SubnetIDRefs, + Selector: mg.Spec.ForProvider.SubnetIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.ForProvider.SubnetIds") + } + mg.Spec.ForProvider.SubnetIds = reference.ToPtrValues(mrsp.ResolvedValues) + mg.Spec.ForProvider.SubnetIDRefs = mrsp.ResolvedReferences + { + m, l, err = apisresolver.GetManagedResource("replacedec2.aws.upbound.io", "v1beta1", "SecurityGroup", "SecurityGroupList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + mrsp, err = r.ResolveMultiple(ctx, reference.MultiResolutionRequest{ + CurrentValues: reference.FromPtrValues(mg.Spec.InitProvider.SecurityGroupIds), + Extract: reference.ExternalName(), + References: mg.Spec.InitProvider.SecurityGroupIDRefs, + Selector: mg.Spec.InitProvider.SecurityGroupIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.InitProvider.SecurityGroupIds") + } + mg.Spec.InitProvider.SecurityGroupIds = reference.ToPtrValues(mrsp.ResolvedValues) + mg.Spec.InitProvider.SecurityGroupIDRefs = mrsp.ResolvedReferences + { + m, l, err = apisresolver.GetManagedResource("replacedec2.aws.upbound.io", "v1beta1", "Subnet", "SubnetList") + if err != nil { + return errors.Wrap(err, "failed to get the reference target managed resource and its list for reference resolution") + } + + mrsp, err = r.ResolveMultiple(ctx, reference.MultiResolutionRequest{ + CurrentValues: reference.FromPtrValues(mg.Spec.InitProvider.SubnetIds), + Extract: reference.ExternalName(), + References: mg.Spec.InitProvider.SubnetIDRefs, + Selector: mg.Spec.InitProvider.SubnetIDSelector, + To: reference.To{List: l, Managed: m}, + }) + } + if err != nil { + return errors.Wrap(err, "mg.Spec.InitProvider.SubnetIds") + } + mg.Spec.InitProvider.SubnetIds = reference.ToPtrValues(mrsp.ResolvedValues) + mg.Spec.InitProvider.SubnetIDRefs = mrsp.ResolvedReferences + + return nil +}