diff --git a/apis/apigatewayv2/v1beta1/zz_authorizer_types.go b/apis/apigatewayv2/v1beta1/zz_authorizer_types.go index d115ed4681..9e51a67063 100755 --- a/apis/apigatewayv2/v1beta1/zz_authorizer_types.go +++ b/apis/apigatewayv2/v1beta1/zz_authorizer_types.go @@ -53,7 +53,7 @@ type AuthorizerInitParameters struct { // For REQUEST authorizers this must be a well-formed Lambda function URI, such as the invoke_arn attribute of the aws_lambda_function resource. // Supported only for REQUEST authorizers. Must be between 1 and 2048 characters in length. // +crossplane:generate:reference:type=github.com/upbound/provider-aws/apis/lambda/v1beta1.Function - // +crossplane:generate:reference:extractor=github.com/upbound/provider-aws/apis/lambda/v1beta1.LambdaFunctionInvokeARN() + // +crossplane:generate:reference:extractor=github.com/upbound/provider-aws/config/common/apis/lambda.FunctionInvokeARN() AuthorizerURI *string `json:"authorizerUri,omitempty" tf:"authorizer_uri,omitempty"` // Reference to a Function in lambda to populate authorizerUri. @@ -172,7 +172,7 @@ type AuthorizerParameters struct { // For REQUEST authorizers this must be a well-formed Lambda function URI, such as the invoke_arn attribute of the aws_lambda_function resource. // Supported only for REQUEST authorizers. Must be between 1 and 2048 characters in length. // +crossplane:generate:reference:type=github.com/upbound/provider-aws/apis/lambda/v1beta1.Function - // +crossplane:generate:reference:extractor=github.com/upbound/provider-aws/apis/lambda/v1beta1.LambdaFunctionInvokeARN() + // +crossplane:generate:reference:extractor=github.com/upbound/provider-aws/config/common/apis/lambda.FunctionInvokeARN() // +kubebuilder:validation:Optional AuthorizerURI *string `json:"authorizerUri,omitempty" tf:"authorizer_uri,omitempty"` diff --git a/apis/apigatewayv2/v1beta1/zz_generated.resolvers.go b/apis/apigatewayv2/v1beta1/zz_generated.resolvers.go index 6a682ff61c..a725642475 100644 --- a/apis/apigatewayv2/v1beta1/zz_generated.resolvers.go +++ b/apis/apigatewayv2/v1beta1/zz_generated.resolvers.go @@ -15,6 +15,8 @@ import ( 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" ) @@ -149,7 +151,7 @@ func (mg *Authorizer) ResolveReferences(ctx context.Context, c client.Reader) er rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.AuthorizerURI), - Extract: v1beta1.LambdaFunctionInvokeARN(), + Extract: lambda.FunctionInvokeARN(), Reference: mg.Spec.ForProvider.AuthorizerURIRef, Selector: mg.Spec.ForProvider.AuthorizerURISelector, To: reference.To{ @@ -181,7 +183,7 @@ func (mg *Authorizer) ResolveReferences(ctx context.Context, c client.Reader) er rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.AuthorizerURI), - Extract: v1beta1.LambdaFunctionInvokeARN(), + Extract: lambda.FunctionInvokeARN(), Reference: mg.Spec.InitProvider.AuthorizerURIRef, Selector: mg.Spec.InitProvider.AuthorizerURISelector, To: reference.To{ @@ -582,7 +584,7 @@ func (mg *Route) ResolveReferences(ctx context.Context, c client.Reader) error { rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.Target), - Extract: IntegrationIDPrefixed(), + Extract: apis.IntegrationIDPrefixed(), Reference: mg.Spec.ForProvider.TargetRef, Selector: mg.Spec.ForProvider.TargetSelector, To: reference.To{ @@ -630,7 +632,7 @@ func (mg *Route) ResolveReferences(ctx context.Context, c client.Reader) error { rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ CurrentValue: reference.FromPtrValue(mg.Spec.InitProvider.Target), - Extract: IntegrationIDPrefixed(), + Extract: apis.IntegrationIDPrefixed(), Reference: mg.Spec.InitProvider.TargetRef, Selector: mg.Spec.InitProvider.TargetSelector, To: reference.To{ diff --git a/apis/apigatewayv2/v1beta1/zz_route_types.go b/apis/apigatewayv2/v1beta1/zz_route_types.go index ef343a4c20..5b4d92f2f1 100755 --- a/apis/apigatewayv2/v1beta1/zz_route_types.go +++ b/apis/apigatewayv2/v1beta1/zz_route_types.go @@ -105,15 +105,15 @@ type RouteInitParameters struct { RouteResponseSelectionExpression *string `json:"routeResponseSelectionExpression,omitempty" tf:"route_response_selection_expression,omitempty"` // Target for the route, of the form integrations/IntegrationID, where IntegrationID is the identifier of an aws_apigatewayv2_integration resource. - // +crossplane:generate:reference:type=Integration - // +crossplane:generate:reference:extractor=github.com/upbound/provider-aws/apis/apigatewayv2/v1beta1.IntegrationIDPrefixed() + // +crossplane:generate:reference:type=github.com/upbound/provider-aws/apis/apigatewayv2/v1beta1.Integration + // +crossplane:generate:reference:extractor=github.com/upbound/provider-aws/config/common/apis.IntegrationIDPrefixed() Target *string `json:"target,omitempty" tf:"target,omitempty"` - // Reference to a Integration to populate target. + // Reference to a Integration in apigatewayv2 to populate target. // +kubebuilder:validation:Optional TargetRef *v1.Reference `json:"targetRef,omitempty" tf:"-"` - // Selector for a Integration to populate target. + // Selector for a Integration in apigatewayv2 to populate target. // +kubebuilder:validation:Optional TargetSelector *v1.Selector `json:"targetSelector,omitempty" tf:"-"` } @@ -240,16 +240,16 @@ type RouteParameters struct { RouteResponseSelectionExpression *string `json:"routeResponseSelectionExpression,omitempty" tf:"route_response_selection_expression,omitempty"` // Target for the route, of the form integrations/IntegrationID, where IntegrationID is the identifier of an aws_apigatewayv2_integration resource. - // +crossplane:generate:reference:type=Integration - // +crossplane:generate:reference:extractor=github.com/upbound/provider-aws/apis/apigatewayv2/v1beta1.IntegrationIDPrefixed() + // +crossplane:generate:reference:type=github.com/upbound/provider-aws/apis/apigatewayv2/v1beta1.Integration + // +crossplane:generate:reference:extractor=github.com/upbound/provider-aws/config/common/apis.IntegrationIDPrefixed() // +kubebuilder:validation:Optional Target *string `json:"target,omitempty" tf:"target,omitempty"` - // Reference to a Integration to populate target. + // Reference to a Integration in apigatewayv2 to populate target. // +kubebuilder:validation:Optional TargetRef *v1.Reference `json:"targetRef,omitempty" tf:"-"` - // Selector for a Integration to populate target. + // Selector for a Integration in apigatewayv2 to populate target. // +kubebuilder:validation:Optional TargetSelector *v1.Selector `json:"targetSelector,omitempty" tf:"-"` } diff --git a/config/apigatewayv2/config.go b/config/apigatewayv2/config.go index 75ada34388..a9b8632c60 100644 --- a/config/apigatewayv2/config.go +++ b/config/apigatewayv2/config.go @@ -29,8 +29,8 @@ func Configure(p *config.Provider) { Type: "API", } r.References["authorizer_uri"] = config.Reference{ - Type: "github.com/upbound/provider-aws/apis/lambda/v1beta1.Function", - Extractor: "github.com/upbound/provider-aws/apis/lambda/v1beta1.LambdaFunctionInvokeARN()", + TerraformName: "aws_lambda_function", + Extractor: "github.com/upbound/provider-aws/config/common/apis/lambda.FunctionInvokeARN()", } }) p.AddResourceConfigurator("aws_apigatewayv2_domain_name", func(r *config.Resource) { @@ -74,8 +74,8 @@ func Configure(p *config.Provider) { Type: "API", } r.References["target"] = config.Reference{ - Type: "Integration", - Extractor: "github.com/upbound/provider-aws/apis/apigatewayv2/v1beta1.IntegrationIDPrefixed()", + TerraformName: "aws_apigatewayv2_integration", + Extractor: "github.com/upbound/provider-aws/config/common/apis.IntegrationIDPrefixed()", } r.References["authorizer_id"] = config.Reference{ Type: "Authorizer", diff --git a/apis/apigatewayv2/v1beta1/extractor.go b/config/common/apis/extractor.go similarity index 71% rename from apis/apigatewayv2/v1beta1/extractor.go rename to config/common/apis/extractor.go index af440cb6e2..f535c84242 100644 --- a/apis/apigatewayv2/v1beta1/extractor.go +++ b/config/common/apis/extractor.go @@ -1,8 +1,8 @@ /* -Copyright 2021 Upbound Inc. +Copyright 2022 Upbound Inc. */ -package v1beta1 +package apis import ( "github.com/crossplane/crossplane-runtime/pkg/meta" @@ -17,14 +17,10 @@ import ( func IntegrationIDPrefixed() reference.ExtractValueFn { return func(mg xpresource.Managed) string { return func(mg metav1.Object) string { - integration, ok := mg.(*Integration) - if !ok { + if meta.GetExternalName(mg) == "" { return "" } - if meta.GetExternalName(integration) == "" { - return "" - } - return "integrations/" + meta.GetExternalName(integration) + return "integrations/" + meta.GetExternalName(mg) }(mg) } } diff --git a/apis/lambda/v1beta1/extractor.go b/config/common/apis/lambda/extractor.go similarity index 66% rename from apis/lambda/v1beta1/extractor.go rename to config/common/apis/lambda/extractor.go index 1cad0a86b1..c4609ca3ed 100644 --- a/apis/lambda/v1beta1/extractor.go +++ b/config/common/apis/lambda/extractor.go @@ -2,19 +2,21 @@ Copyright 2022 Upbound Inc. */ -package v1beta1 +package lambda import ( "github.com/crossplane/crossplane-runtime/pkg/reference" xpresource "github.com/crossplane/crossplane-runtime/pkg/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + "github.com/upbound/provider-aws/apis/lambda/v1beta1" ) -// LambdaFunctionInvokeARN returns the invoke ARN value of the lambda function. -func LambdaFunctionInvokeARN() reference.ExtractValueFn { +// FunctionInvokeARN returns the invoke ARN value of the lambda function. +func FunctionInvokeARN() reference.ExtractValueFn { return func(mg xpresource.Managed) string { return func(mg metav1.Object) string { - f, ok := mg.(*Function) + f, ok := mg.(*v1beta1.Function) if !ok { return "" } diff --git a/package/crds/apigatewayv2.aws.upbound.io_routes.yaml b/package/crds/apigatewayv2.aws.upbound.io_routes.yaml index 5e3e79d58b..d517f1ec43 100644 --- a/package/crds/apigatewayv2.aws.upbound.io_routes.yaml +++ b/package/crds/apigatewayv2.aws.upbound.io_routes.yaml @@ -288,7 +288,8 @@ spec: resource. type: string targetRef: - description: Reference to a Integration to populate target. + description: Reference to a Integration in apigatewayv2 to populate + target. properties: name: description: Name of the referenced object. @@ -322,7 +323,8 @@ spec: - name type: object targetSelector: - description: Selector for a Integration to populate target. + description: Selector for a Integration in apigatewayv2 to populate + target. properties: matchControllerRef: description: MatchControllerRef ensures an object with the @@ -592,7 +594,8 @@ spec: resource. type: string targetRef: - description: Reference to a Integration to populate target. + description: Reference to a Integration in apigatewayv2 to populate + target. properties: name: description: Name of the referenced object. @@ -626,7 +629,8 @@ spec: - name type: object targetSelector: - description: Selector for a Integration to populate target. + description: Selector for a Integration in apigatewayv2 to populate + target. properties: matchControllerRef: description: MatchControllerRef ensures an object with the