From db929c44b75219bd0bfe006142f1a81259d6481d Mon Sep 17 00:00:00 2001 From: Alper Rifat Ulucinar Date: Wed, 24 Jan 2024 17:09:44 +0300 Subject: [PATCH] Move main.TransformPackages to transformers.Resolver.TransformPackages - Bump Go version to 1.21 - Bump golangci-lint to v1.55.2 - Add tests for the Resolver.TransformPackages Signed-off-by: Alper Rifat Ulucinar --- .github/workflows/ci.yml | 4 +- Makefile | 4 +- cmd/resolver/main.go | 11 +- go.mod | 2 +- go.sum | 11 + .../resolver => pkg/transformers}/resolver.go | 164 ++- pkg/transformers/resolver_test.go | 114 ++ .../testdata/SuccessfulTransformation.go.txt | 872 ++++++++++++++ ...uccessfulTransformation.transformed.go.txt | 1032 +++++++++++++++++ 9 files changed, 2188 insertions(+), 26 deletions(-) rename {cmd/resolver => pkg/transformers}/resolver.go (69%) create mode 100644 pkg/transformers/resolver_test.go create mode 100644 pkg/transformers/testdata/SuccessfulTransformation.go.txt create mode 100644 pkg/transformers/testdata/SuccessfulTransformation.transformed.go.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dac05e1f..0a0bffaa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,8 +14,8 @@ on: env: # Common versions - GO_VERSION: "1.20" - GOLANGCI_VERSION: "v1.53.3" + GO_VERSION: "1.21" + GOLANGCI_VERSION: "v1.55.2" DOCKER_BUILDX_VERSION: "v0.8.2" # Common users. We can't run a step 'if secrets.AWS_USR != ""' but we can run diff --git a/Makefile b/Makefile index 940c7a81..cda2468e 100644 --- a/Makefile +++ b/Makefile @@ -11,8 +11,8 @@ PROJECT_REPO := github.com/crossplane/$(PROJECT_NAME) # GOLANGCILINT_VERSION is inherited from build submodule by default. # Uncomment below if you need to override the version. -# GOLANGCILINT_VERSION ?= 1.54.0 -GO_REQUIRED_VERSION ?= 1.20 +GOLANGCILINT_VERSION ?= 1.55.2 +GO_REQUIRED_VERSION ?= 1.21 PLATFORMS ?= linux_amd64 linux_arm64 # -include will silently skip missing files, which allows us diff --git a/cmd/resolver/main.go b/cmd/resolver/main.go index 77137f62..ccf8b1c2 100644 --- a/cmd/resolver/main.go +++ b/cmd/resolver/main.go @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2023 The Crossplane Authors +// SPDX-FileCopyrightText: 2024 The Crossplane Authors // // SPDX-License-Identifier: Apache-2.0 @@ -8,7 +8,12 @@ import ( "os" "path/filepath" + "github.com/crossplane/crossplane-runtime/pkg/logging" + "github.com/spf13/afero" "gopkg.in/alecthomas/kingpin.v2" + "sigs.k8s.io/controller-runtime/pkg/log/zap" + + "github.com/crossplane/upjet/pkg/transformers" ) func main() { @@ -20,5 +25,7 @@ func main() { ignorePackageLoadErrors = app.Flag("ignoreLoadErrors", "Ignore errors encountered while loading the packages.").Short('s').Bool() ) kingpin.MustParse(app.Parse(os.Args[1:])) - kingpin.FatalIfError(transformPackages(*apiGroupSuffix, *resolverFilePattern, *ignorePackageLoadErrors, *pattern...), "Failed to transform the resolver files in the specified packages.") + logger := logging.NewLogrLogger(zap.New().WithName("transformer-resolver")) + r := transformers.NewResolver(afero.NewOsFs(), *apiGroupSuffix, *ignorePackageLoadErrors, logger) + kingpin.FatalIfError(r.TransformPackages(*resolverFilePattern, *pattern...), "Failed to transform the resolver files in the specified packages.") } diff --git a/go.mod b/go.mod index 66fa03f1..65eaef97 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ module github.com/crossplane/upjet -go 1.20 +go 1.21 require ( dario.cat/mergo v1.0.0 diff --git a/go.sum b/go.sum index 5ea7e3de..48362ec2 100644 --- a/go.sum +++ b/go.sum @@ -39,6 +39,7 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/AdaLogics/go-fuzz-headers v0.0.0-20230106234847-43070de90fa1 h1:EKPd1INOIyr5hWOWhvpmQpY6tKjeG0hT1s3AMC/9fic= +github.com/AdaLogics/go-fuzz-headers v0.0.0-20230106234847-43070de90fa1/go.mod h1:VzwV+t+dZ9j/H867F1M2ziD+yLHtB46oM35FxxMJ4d0= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= @@ -78,6 +79,7 @@ github.com/crossplane/crossplane v1.13.2/go.mod h1:jjYHNF5j2JidsrFZ7sfTZoVnBDVEv github.com/crossplane/crossplane-runtime v1.14.0-rc.0.0.20231011070344-cc691421c2e5 h1:K1Km6NCu9+VlZB3CmWSjrs09cDSbwQxJd2Qw2002dFs= github.com/crossplane/crossplane-runtime v1.14.0-rc.0.0.20231011070344-cc691421c2e5/go.mod h1:kCS5576be8g++HhiDGEBUw+8nkW8p4jhURYeC0zx8jM= github.com/cyphar/filepath-securejoin v0.2.3 h1:YX6ebbZCZP7VkM3scTTokDgBL2TY741X51MTk3ycuNI= +github.com/cyphar/filepath-securejoin v0.2.3/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -117,6 +119,7 @@ github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g= github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= +github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/go-test/deep v1.0.7 h1:/VSMRlnY/JSyqxQUzQLKVMAskpY/NZKFA5j2P+0pP2M= github.com/go-test/deep v1.0.7/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8= @@ -191,6 +194,7 @@ github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20230926050212-f7f687d19a98 h1:pUa4ghanp6q4IJHwE9RwLgmVFfReJN+KbQ8ExNEUUoQ= +github.com/google/pprof v0.0.0-20230926050212-f7f687d19a98/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= @@ -244,6 +248,7 @@ github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -289,7 +294,9 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m github.com/muvaf/typewriter v0.0.0-20210910160850-80e49fe1eb32 h1:yBQlHXLeUJL3TWVmzup5uT3wG5FLxhiTAiTsmNVocys= github.com/muvaf/typewriter v0.0.0-20210910160850-80e49fe1eb32/go.mod h1:SAAdeMEiFXR8LcHffvIdiLI1w243DCH2DuHq7UrA5YQ= github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU= +github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM= github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= +github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -309,8 +316,10 @@ github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+Pymzi github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= +github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/spf13/afero v1.10.0 h1:EaGW2JJh15aKOejeuJ+wpFSHnbd7GE6Wvp3TsNhb6LY= github.com/spf13/afero v1.10.0/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= @@ -331,6 +340,7 @@ github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1F github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/tmccombs/hcl2json v0.3.3 h1:+DLNYqpWE0CsOQiEZu+OZm5ZBImake3wtITYxQ8uLFQ= github.com/tmccombs/hcl2json v0.3.3/go.mod h1:Y2chtz2x9bAeRTvSibVRVgbLJhLJXKlUeIvjeVdnm4w= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= @@ -370,6 +380,7 @@ go.starlark.net v0.0.0-20230525235612-a134d8f9ddca/go.mod h1:jxU+3+j+71eXOW14274 go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= +go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= diff --git a/cmd/resolver/resolver.go b/pkg/transformers/resolver.go similarity index 69% rename from cmd/resolver/resolver.go rename to pkg/transformers/resolver.go index 688be9b5..9a0ff9e9 100644 --- a/cmd/resolver/resolver.go +++ b/pkg/transformers/resolver.go @@ -1,20 +1,21 @@ -// SPDX-FileCopyrightText: 2023 The Crossplane Authors +// SPDX-FileCopyrightText: 2024 The Crossplane Authors // // SPDX-License-Identifier: Apache-2.0 -package main +package transformers import ( "fmt" "go/ast" "go/format" "go/token" - "os" "path/filepath" "slices" "strings" + "github.com/crossplane/crossplane-runtime/pkg/logging" "github.com/pkg/errors" + "github.com/spf13/afero" "golang.org/x/tools/go/ast/astutil" "golang.org/x/tools/go/packages" ) @@ -23,25 +24,149 @@ const ( varManagedResource = "m" varManagedResourceList = "l" commentFileTransformed = "// Code transformed by upjet. DO NOT EDIT." + + defaultLoadMode = packages.NeedName | packages.NeedFiles | packages.NeedImports | packages.NeedDeps | packages.NeedTypes | packages.NeedSyntax ) -func transformPackages(apiGroupSuffix, resolverFilePattern string, ignorePackageLoadErrors bool, patterns ...string) error { - pkgs, err := packages.Load(&packages.Config{ - Mode: packages.NeedName | packages.NeedFiles | packages.NeedImports | packages.NeedDeps | packages.NeedTypes | packages.NeedSyntax, - }, patterns...) +// Resolver transforms the source resolver implementations so that +// the resolution source managed resources are no longer statically typed +// and thus, the implementations no longer need to import the corresponding +// API packages. This transformer is helpful in preventing the import cycles +// described in https://github.com/crossplane/upjet/issues/96 +// and elsewhere. Please see TransformPackages for the details of the +// transformation applied. +type Resolver struct { + // the FS implementation used for storing the transformed output + fs afero.Fs + // the API group suffix to be used for the resolution source + // managed resources, such as aws.upbound.io. Then a sample + // API group for a resource is ec2.aws.upbound.io. + apiGroupSuffix 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. + // We need to set this when, for example, loading resolver implementations + // with import cycles, or when transforming just one package and not loading + // the referenced typed. + ignorePackageLoadErrors bool + logger logging.Logger + config *packages.Config +} + +// NewResolver initializes a new Resolver with the specified configuration. +func NewResolver(fs afero.Fs, apiGroupSuffix string, ignorePackageLoadErrors bool, logger logging.Logger, opts ...ResolverOption) *Resolver { + if logger == nil { + logger = logging.NewNopLogger() + } + r := &Resolver{ + fs: fs, + apiGroupSuffix: apiGroupSuffix, + ignorePackageLoadErrors: ignorePackageLoadErrors, + logger: logger, + config: &packages.Config{ + Mode: defaultLoadMode, + }, + } + for _, o := range opts { + o(r) + } + return r +} + +// ResolverOption is an option used to configure the Resolver. +type ResolverOption func(resolver *Resolver) + +// WithLoaderConfig configures the package loader config for a Resolver. +func WithLoaderConfig(c *packages.Config) ResolverOption { + return func(r *Resolver) { + r.config = c + } +} + +// 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` +// is set, any errors encountered while loading the source packages are +// ignored. This may be required when the transformation source files have +// compile errors, such as import cycles. The transformed resolver +// implementations will use the specified API group suffix, such as, +// "aws.upbound.io" when determining the API groups of the resolution +// source managed resources. +// A sample transformation implemented by this transformer is from: +// ``` +// +// func (mg *Subnet) ResolveReferences(ctx context.Context, c client.Reader) error { +// r := reference.NewAPIResolver(c, mg) +// +// var rsp reference.ResolutionResponse +// var err error +// +// rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ +// CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.VPCID), +// Extract: reference.ExternalName(), +// Reference: mg.Spec.ForProvider.VPCIDRef, +// Selector: mg.Spec.ForProvider.VPCIDSelector, +// To: reference.To{ +// List: &VPCList{}, +// Managed: &VPC{}, +// }, +// }) +// if err != nil { +// return errors.Wrap(err, "mg.Spec.ForProvider.VPCID") +// } +// mg.Spec.ForProvider.VPCID = reference.ToPtrValue(rsp.ResolvedValue) +// mg.Spec.ForProvider.VPCIDRef = rsp.ResolvedReference +// +// ``` +// to the following: +// ``` +// +// func (mg *Subnet) 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("ec2.aws.upbound.io", "v1beta1", "VPC", "VPCList") +// 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.VPCID), +// Extract: reference.ExternalName(), +// Reference: mg.Spec.ForProvider.VPCIDRef, +// Selector: mg.Spec.ForProvider.VPCIDSelector, +// To: reference.To{List: l, Managed: m}, +// }) +// } +// if err != nil { +// return errors.Wrap(err, "mg.Spec.ForProvider.VPCID") +// } +// mg.Spec.ForProvider.VPCID = reference.ToPtrValue(rsp.ResolvedValue) +// mg.Spec.ForProvider.VPCIDRef = rsp.ResolvedReference +// +// ``` +func (r *Resolver) TransformPackages(resolverFilePattern string, patterns ...string) error { + pkgs, err := packages.Load(r.config, patterns...) if err != nil { return errors.Wrapf(err, "failed to load the packages using the patterns %q", strings.Join(patterns, ",")) } for _, p := range pkgs { - if err := toError(p); err != nil && !ignorePackageLoadErrors { - return errors.Wrapf(err, "failed to load the package %q", p.Name) + if err := toError(p); err != nil { + if !r.ignorePackageLoadErrors { + return errors.Wrapf(err, "failed to load the package %q", p.Name) + } + r.logger.Info("Encounter the following issues when loading a package", "package", p.Name, "issues", err.Error()) } for i, f := range p.GoFiles { if filepath.Base(f) != resolverFilePattern { continue } - if err := transformResolverFile(p.Fset, p.Syntax[i], f, strings.Trim(apiGroupSuffix, ".")); err != nil { + if err := r.transformResolverFile(p.Fset, p.Syntax[i], f, strings.Trim(r.apiGroupSuffix, ".")); err != nil { return errors.Wrapf(err, "failed to transform the resolver file %s", f) } } @@ -100,15 +225,13 @@ func addTransformedComment(fset *token.FileSet, node *ast.File) bool { return true } -func transformResolverFile(fset *token.FileSet, node *ast.File, filePath, apiGroupSuffix string) error { //nolint:gocyclo // Arguably, easier to follow +func (r *Resolver) transformResolverFile(fset *token.FileSet, node *ast.File, filePath, apiGroupSuffix string) error { //nolint:gocyclo // Arguably, easier to follow if !addTransformedComment(fset, node) { return nil } - importMap, err := addMRVariableDeclarations(node) - if err != nil { - return errors.Wrapf(err, "failed to add the managed resource variable declarations to the file %s", filePath) - } - + // add resolution source variable declarations to the `ResolveReferences` + // function bodies. + importMap := addMRVariableDeclarations(node) // Map to track imports used in reference.To structs importsUsed := make(map[string]importUsage) // assign is the assignment statement that assigns the values returned from @@ -325,10 +448,13 @@ func transformResolverFile(fset *token.FileSet, node *ast.File, filePath, apiGro } } } + return r.dumpTransformed(fset, node, filePath) +} +func (r *Resolver) dumpTransformed(fset *token.FileSet, node *ast.File, filePath string) error { // dump the transformed resolver file adjustFunctionDocs(node) - outFile, err := os.Create(filepath.Clean(filePath)) + outFile, err := r.fs.Create(filepath.Clean(filePath)) if err != nil { return errors.Wrap(err, "failed to open the resolver file for writing the transformed AST") } @@ -356,7 +482,7 @@ func insertStatements(stmts []ast.Stmt, block *ast.BlockStmt, assign *ast.Assign return true } -func addMRVariableDeclarations(f *ast.File) (map[string]string, error) { //nolint:gocyclo +func addMRVariableDeclarations(f *ast.File) map[string]string { // prepare the first variable declaration: // `var m xpresource.Managed` varDecl1 := &ast.GenDecl{ @@ -403,7 +529,7 @@ func addMRVariableDeclarations(f *ast.File) (map[string]string, error) { //nolin }) return map[string]string{ `"github.com/crossplane/crossplane-runtime/pkg/resource"`: "xpresource", - }, nil + } } func getManagedResourceStatements(group, version, kind, listKind string) (map[string]string, []ast.Stmt) { diff --git a/pkg/transformers/resolver_test.go b/pkg/transformers/resolver_test.go new file mode 100644 index 00000000..19249e5a --- /dev/null +++ b/pkg/transformers/resolver_test.go @@ -0,0 +1,114 @@ +// SPDX-FileCopyrightText: 2024 The Crossplane Authors +// +// SPDX-License-Identifier: Apache-2.0 + +package transformers + +import ( + "path/filepath" + "testing" + + "github.com/crossplane/crossplane-runtime/pkg/test" + "github.com/google/go-cmp/cmp" + "github.com/spf13/afero" + "golang.org/x/tools/go/packages/packagestest" +) + +func TestTransformPackages(t *testing.T) { + // args struct to define input arguments for each test case + type args struct { + apiGroupSuffix string + resolverFilePattern string + ignorePackageLoadErrors bool + patterns []string + inputFilePath string + } + + // want struct to define the expected outcome for each test case + type want struct { + err error + transformedPath string + } + + // testCase struct for defining test cases + type testCase struct { + reason string + args args + want want + } + + cases := map[string]testCase{ + "SuccessfulTransformation": { + 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", + resolverFilePattern: "zz_generated.resolvers.go", + inputFilePath: "testdata/SuccessfulTransformation.go.txt", + ignorePackageLoadErrors: true, + patterns: []string{"./testdata"}, + }, + want: want{ + transformedPath: "testdata/SuccessfulTransformation.transformed.go.txt", + }, + }, + "TransformationIdempotency": { + 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", + resolverFilePattern: "zz_generated.resolvers.go", + inputFilePath: "testdata/SuccessfulTransformation.transformed.go.txt", + ignorePackageLoadErrors: true, + patterns: []string{"./testdata"}, + }, + want: want{ + transformedPath: "testdata/SuccessfulTransformation.transformed.go.txt", + }, + }, + // Other test cases + } + + for name, tc := range cases { + t.Run(name, func(t *testing.T) { + inputFileContents := readFile(t, afero.NewOsFs(), tc.args.inputFilePath, tc.reason) + exported := packagestest.Export(t, packagestest.Modules, []packagestest.Module{{ + Name: "fake", + Files: map[string]interface{}{ + filepath.Join("testdata", tc.args.resolverFilePattern): inputFileContents, + }}}) + defer exported.Cleanup() + exported.Config.Mode = defaultLoadMode + memFS := afero.NewMemMapFs() + 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)) + err := r.TransformPackages("zz_generated.resolvers.go", tc.args.patterns...) + if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + t.Errorf("\n%s\nResolver.TransformPackages(...): -wantErr, +gotErr:\n%s", tc.reason, diff) + } + if tc.want.err != nil { + return + } + if diff := cmp.Diff(readFile(t, afero.NewOsFs(), tc.want.transformedPath, tc.reason), + readFile(t, memFS, transformedFilePath, tc.reason)); diff != "" { + t.Errorf("\n%s\nResolver.TransformPackages(...): -want, +got:\n%s", tc.reason, diff) + } + }) + } +} + +func readFile(t *testing.T, fs afero.Fs, filePath string, reason string) string { + buff, err := afero.ReadFile(fs, filePath) + if err != nil { + t.Fatalf("\n%s\n: Failed to write the test artifact to the path %s: %v", reason, filePath, err) + } + return string(buff) +} + +func writeFile(t *testing.T, fs afero.Fs, filePath string, buff []byte, reason string) string { + err := afero.WriteFile(fs, filePath, buff, 0o600) + if err != nil { + t.Fatalf("\n%s\n: Failed to load the test artifact from the path %s: %v", reason, filePath, err) + } + return string(buff) +} diff --git a/pkg/transformers/testdata/SuccessfulTransformation.go.txt b/pkg/transformers/testdata/SuccessfulTransformation.go.txt new file mode 100644 index 00000000..a7256424 --- /dev/null +++ b/pkg/transformers/testdata/SuccessfulTransformation.go.txt @@ -0,0 +1,872 @@ +/* +Copyright 2022 Upbound Inc. +*/ +// Code generated by angryjet. 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" + v1beta11 "github.com/upbound/provider-aws/apis/acm/v1beta1" + v1beta13 "github.com/upbound/provider-aws/apis/ec2/v1beta1" + v1beta12 "github.com/upbound/provider-aws/apis/iam/v1beta1" + v1beta1 "github.com/upbound/provider-aws/apis/lambda/v1beta1" + 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" + client "sigs.k8s.io/controller-runtime/pkg/client" +) + +// ResolveReferences of this APIMapping. +func (mg *APIMapping) ResolveReferences(ctx context.Context, c client.Reader) error { + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + + 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: &APIList{}, + Managed: &API{}, + }, + }) + 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 + + 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: &DomainNameList{}, + Managed: &DomainName{}, + }, + }) + 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 + + 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: &StageList{}, + Managed: &Stage{}, + }, + }) + 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 + + 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: &APIList{}, + Managed: &API{}, + }, + }) + 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 + + 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: &DomainNameList{}, + Managed: &DomainName{}, + }, + }) + 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 + + 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: &StageList{}, + Managed: &Stage{}, + }, + }) + 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 { + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + + 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: &APIList{}, + Managed: &API{}, + }, + }) + 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 + + 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: &v1beta1.FunctionList{}, + Managed: &v1beta1.Function{}, + }, + }) + 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 + + 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: &APIList{}, + Managed: &API{}, + }, + }) + 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 + + 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: &v1beta1.FunctionList{}, + Managed: &v1beta1.Function{}, + }, + }) + 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 { + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + + 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: &APIList{}, + Managed: &API{}, + }, + }) + 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 + + 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: &APIList{}, + Managed: &API{}, + }, + }) + 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 { + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + + for i3 := 0; i3 < len(mg.Spec.ForProvider.DomainNameConfiguration); i3++ { + 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: &v1beta11.CertificateList{}, + Managed: &v1beta11.Certificate{}, + }, + }) + 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++ { + 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: &v1beta11.CertificateList{}, + Managed: &v1beta11.Certificate{}, + }, + }) + 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 { + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + + 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: &APIList{}, + Managed: &API{}, + }, + }) + 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 + + 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: &VPCLinkList{}, + Managed: &VPCLink{}, + }, + }) + 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 + + 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: &v1beta12.RoleList{}, + Managed: &v1beta12.Role{}, + }, + }) + 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 + + 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: &v1beta1.FunctionList{}, + Managed: &v1beta1.Function{}, + }, + }) + 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 + + 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: &APIList{}, + Managed: &API{}, + }, + }) + 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 + + 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: &VPCLinkList{}, + Managed: &VPCLink{}, + }, + }) + 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 + + 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: &v1beta12.RoleList{}, + Managed: &v1beta12.Role{}, + }, + }) + 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 + + 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: &v1beta1.FunctionList{}, + Managed: &v1beta1.Function{}, + }, + }) + 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 { + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + + 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: &APIList{}, + Managed: &API{}, + }, + }) + 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 + + 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: &IntegrationList{}, + Managed: &Integration{}, + }, + }) + 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 + + 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: &APIList{}, + Managed: &API{}, + }, + }) + 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 + + 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: &IntegrationList{}, + Managed: &Integration{}, + }, + }) + 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 { + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + + 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: &APIList{}, + Managed: &API{}, + }, + }) + 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 + + 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: &APIList{}, + Managed: &API{}, + }, + }) + 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 { + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + + 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: &APIList{}, + Managed: &API{}, + }, + }) + 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 + + 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: &AuthorizerList{}, + Managed: &Authorizer{}, + }, + }) + 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 + + 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: &IntegrationList{}, + Managed: &Integration{}, + }, + }) + 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 + + 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: &APIList{}, + Managed: &API{}, + }, + }) + 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 + + 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: &AuthorizerList{}, + Managed: &Authorizer{}, + }, + }) + 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 + + 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: &IntegrationList{}, + Managed: &Integration{}, + }, + }) + 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 { + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + + 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: &APIList{}, + Managed: &API{}, + }, + }) + 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 + + 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: &RouteList{}, + Managed: &Route{}, + }, + }) + 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 + + 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: &APIList{}, + Managed: &API{}, + }, + }) + 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 + + 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: &RouteList{}, + Managed: &Route{}, + }, + }) + 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 { + r := reference.NewAPIResolver(c, mg) + + var rsp reference.ResolutionResponse + var err error + + 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: &APIList{}, + Managed: &API{}, + }, + }) + 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 + + 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: &DeploymentList{}, + Managed: &Deployment{}, + }, + }) + 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 + + 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: &APIList{}, + Managed: &API{}, + }, + }) + 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 + + 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: &DeploymentList{}, + Managed: &Deployment{}, + }, + }) + 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 { + r := reference.NewAPIResolver(c, mg) + + var mrsp reference.MultiResolutionResponse + var err error + + 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: &v1beta13.SecurityGroupList{}, + Managed: &v1beta13.SecurityGroup{}, + }, + }) + 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 + + 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: &v1beta13.SubnetList{}, + Managed: &v1beta13.Subnet{}, + }, + }) + 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 + + 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: &v1beta13.SecurityGroupList{}, + Managed: &v1beta13.SecurityGroup{}, + }, + }) + 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 + + 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: &v1beta13.SubnetList{}, + Managed: &v1beta13.Subnet{}, + }, + }) + 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 +} diff --git a/pkg/transformers/testdata/SuccessfulTransformation.transformed.go.txt b/pkg/transformers/testdata/SuccessfulTransformation.transformed.go.txt new file mode 100644 index 00000000..93172b42 --- /dev/null +++ b/pkg/transformers/testdata/SuccessfulTransformation.transformed.go.txt @@ -0,0 +1,1032 @@ +/* +Copyright 2022 Upbound Inc. +*/ +// 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/apis" + 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("ec2.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("ec2.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("ec2.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("ec2.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 +}