From 890b2c843422e9e3254bc33d6ba9f9d5f2f4ab74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatih=20T=C3=BCrken?= Date: Tue, 16 Apr 2024 18:11:33 +0300 Subject: [PATCH 1/3] Fix update loop for Function.lambda resource by adding CustomDiff MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fatih Türken --- config/lambda/config.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/config/lambda/config.go b/config/lambda/config.go index 31fe96c23c..1e24ae0ae8 100644 --- a/config/lambda/config.go +++ b/config/lambda/config.go @@ -6,6 +6,7 @@ package lambda import ( "github.com/crossplane/upjet/pkg/config" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/upbound/provider-aws/config/common" ) @@ -61,6 +62,14 @@ func Configure(p *config.Provider) { SelectorFieldName: "SubnetIDSelector", } delete(r.TerraformResource.Schema, "filename") + + r.TerraformCustomDiff = func(diff *terraform.InstanceDiff, _ *terraform.InstanceState, _ *terraform.ResourceConfig) (*terraform.InstanceDiff, error) { + if diff != nil && diff.Attributes != nil { + delete(diff.Attributes, "source_code_hash") + delete(diff.Attributes, "last_modified") + } + return diff, nil + } }) p.AddResourceConfigurator("aws_lambda_function_event_invoke_config", func(r *config.Resource) { From 5199951c9f9e800152daf2aa5f8e44713b9e4bfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatih=20T=C3=BCrken?= Date: Thu, 18 Apr 2024 23:07:48 +0300 Subject: [PATCH 2/3] Remove CustomDiff and move the field to IgnoredFields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fatih Türken --- apis/lambda/v1beta1/zz_function_terraformed.go | 1 + config/lambda/config.go | 10 ++-------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/apis/lambda/v1beta1/zz_function_terraformed.go b/apis/lambda/v1beta1/zz_function_terraformed.go index 9c067934d7..c2cab3b267 100755 --- a/apis/lambda/v1beta1/zz_function_terraformed.go +++ b/apis/lambda/v1beta1/zz_function_terraformed.go @@ -118,6 +118,7 @@ func (tr *Function) LateInitialize(attrs []byte) (bool, error) { return false, errors.Wrap(err, "failed to unmarshal Terraform state parameters for late-initialization") } opts := []resource.GenericLateInitializerOption{resource.WithZeroValueJSONOmitEmptyFilter(resource.CNameWildcard)} + opts = append(opts, resource.WithNameFilter("SourceCodeHash")) li := resource.NewGenericLateInitializer(opts...) return li.LateInitialize(&tr.Spec.ForProvider, params) diff --git a/config/lambda/config.go b/config/lambda/config.go index 1e24ae0ae8..321a4a9c3a 100644 --- a/config/lambda/config.go +++ b/config/lambda/config.go @@ -6,7 +6,6 @@ package lambda import ( "github.com/crossplane/upjet/pkg/config" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/upbound/provider-aws/config/common" ) @@ -62,13 +61,8 @@ func Configure(p *config.Provider) { SelectorFieldName: "SubnetIDSelector", } delete(r.TerraformResource.Schema, "filename") - - r.TerraformCustomDiff = func(diff *terraform.InstanceDiff, _ *terraform.InstanceState, _ *terraform.ResourceConfig) (*terraform.InstanceDiff, error) { - if diff != nil && diff.Attributes != nil { - delete(diff.Attributes, "source_code_hash") - delete(diff.Attributes, "last_modified") - } - return diff, nil + r.LateInitializer = config.LateInitializer{ + IgnoredFields: []string{"source_code_hash"}, } }) From 7b224489dc84f8b674e67667e38966396fe28c62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatih=20T=C3=BCrken?= Date: Wed, 24 Apr 2024 17:36:22 +0300 Subject: [PATCH 3/3] Extend the description of sourceCodeHash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fatih Türken --- apis/lambda/v1beta1/zz_function_types.go | 6 ++-- config/lambda/config.go | 4 +++ examples/lambda/v1beta1/function.yaml | 2 +- .../crds/lambda.aws.upbound.io_functions.yaml | 33 +++++++++---------- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/apis/lambda/v1beta1/zz_function_types.go b/apis/lambda/v1beta1/zz_function_types.go index 096e1a296f..7e2810fc93 100755 --- a/apis/lambda/v1beta1/zz_function_types.go +++ b/apis/lambda/v1beta1/zz_function_types.go @@ -238,7 +238,7 @@ type FunctionInitParameters struct { // Snap start settings block. Detailed below. SnapStart []SnapStartInitParameters `json:"snapStart,omitempty" tf:"snap_start,omitempty"` - // Used to trigger updates. Must be set to a base64-encoded SHA256 hash of the package file specified with either filename or s3_key. The usual way to set this is filebase64sha256("file.11.12 and later) or base64sha256(file("file.11.11 and earlier), where "file.zip" is the local filename of the lambda function source archive. + // Used to trigger updates. Must be set to a base64 encoded SHA256 hash of the package file specified with either filename or s3_key. If you have specified this field manually, it should be the actual (computed) hash of the underlying lambda function specified in the filename, image_uri, s3_bucket fields. SourceCodeHash *string `json:"sourceCodeHash,omitempty" tf:"source_code_hash,omitempty"` // Key-value map of resource tags. @@ -355,7 +355,7 @@ type FunctionObservation struct { // Snap start settings block. Detailed below. SnapStart []SnapStartObservation `json:"snapStart,omitempty" tf:"snap_start,omitempty"` - // Used to trigger updates. Must be set to a base64-encoded SHA256 hash of the package file specified with either filename or s3_key. The usual way to set this is filebase64sha256("file.11.12 and later) or base64sha256(file("file.11.11 and earlier), where "file.zip" is the local filename of the lambda function source archive. + // Used to trigger updates. Must be set to a base64 encoded SHA256 hash of the package file specified with either filename or s3_key. If you have specified this field manually, it should be the actual (computed) hash of the underlying lambda function specified in the filename, image_uri, s3_bucket fields. SourceCodeHash *string `json:"sourceCodeHash,omitempty" tf:"source_code_hash,omitempty"` // Size in bytes of the function .zip file. @@ -528,7 +528,7 @@ type FunctionParameters struct { // +kubebuilder:validation:Optional SnapStart []SnapStartParameters `json:"snapStart,omitempty" tf:"snap_start,omitempty"` - // Used to trigger updates. Must be set to a base64-encoded SHA256 hash of the package file specified with either filename or s3_key. The usual way to set this is filebase64sha256("file.11.12 and later) or base64sha256(file("file.11.11 and earlier), where "file.zip" is the local filename of the lambda function source archive. + // Used to trigger updates. Must be set to a base64 encoded SHA256 hash of the package file specified with either filename or s3_key. If you have specified this field manually, it should be the actual (computed) hash of the underlying lambda function specified in the filename, image_uri, s3_bucket fields. // +kubebuilder:validation:Optional SourceCodeHash *string `json:"sourceCodeHash,omitempty" tf:"source_code_hash,omitempty"` diff --git a/config/lambda/config.go b/config/lambda/config.go index 321a4a9c3a..79d6c73806 100644 --- a/config/lambda/config.go +++ b/config/lambda/config.go @@ -64,6 +64,10 @@ func Configure(p *config.Provider) { r.LateInitializer = config.LateInitializer{ IgnoredFields: []string{"source_code_hash"}, } + r.MetaResource.ArgumentDocs["source_code_hash"] = "Used to trigger updates. Must be set to " + + "a base64 encoded SHA256 hash of the package file specified with either filename or s3_key. " + + "If you have specified this field manually, it should be the actual (computed) hash of the " + + "underlying lambda function specified in the filename, image_uri, s3_bucket fields." }) p.AddResourceConfigurator("aws_lambda_function_event_invoke_config", func(r *config.Resource) { diff --git a/examples/lambda/v1beta1/function.yaml b/examples/lambda/v1beta1/function.yaml index 70bffb4f88..8a85bf14f6 100644 --- a/examples/lambda/v1beta1/function.yaml +++ b/examples/lambda/v1beta1/function.yaml @@ -13,7 +13,7 @@ metadata: name: example spec: forProvider: - s3Bucket: upbound-provider-test-data + s3Bucket: official-provider-test-data s3Key: hello-python.zip handler: index.py packageType: Zip diff --git a/package/crds/lambda.aws.upbound.io_functions.yaml b/package/crds/lambda.aws.upbound.io_functions.yaml index 2db26d552d..37559c0420 100644 --- a/package/crds/lambda.aws.upbound.io_functions.yaml +++ b/package/crds/lambda.aws.upbound.io_functions.yaml @@ -644,12 +644,11 @@ spec: type: object type: array sourceCodeHash: - description: Used to trigger updates. Must be set to a base64-encoded - SHA256 hash of the package file specified with either filename - or s3_key. The usual way to set this is filebase64sha256("file.11.12 - and later) or base64sha256(file("file.11.11 and earlier), where - "file.zip" is the local filename of the lambda function source - archive. + description: Used to trigger updates. Must be set to a base64 + encoded SHA256 hash of the package file specified with either + filename or s3_key. If you have specified this field manually, + it should be the actual (computed) hash of the underlying lambda + function specified in the filename, image_uri, s3_bucket fields. type: string tags: additionalProperties: @@ -1439,12 +1438,11 @@ spec: type: object type: array sourceCodeHash: - description: Used to trigger updates. Must be set to a base64-encoded - SHA256 hash of the package file specified with either filename - or s3_key. The usual way to set this is filebase64sha256("file.11.12 - and later) or base64sha256(file("file.11.11 and earlier), where - "file.zip" is the local filename of the lambda function source - archive. + description: Used to trigger updates. Must be set to a base64 + encoded SHA256 hash of the package file specified with either + filename or s3_key. If you have specified this field manually, + it should be the actual (computed) hash of the underlying lambda + function specified in the filename, image_uri, s3_bucket fields. type: string tags: additionalProperties: @@ -2047,12 +2045,11 @@ spec: type: object type: array sourceCodeHash: - description: Used to trigger updates. Must be set to a base64-encoded - SHA256 hash of the package file specified with either filename - or s3_key. The usual way to set this is filebase64sha256("file.11.12 - and later) or base64sha256(file("file.11.11 and earlier), where - "file.zip" is the local filename of the lambda function source - archive. + description: Used to trigger updates. Must be set to a base64 + encoded SHA256 hash of the package file specified with either + filename or s3_key. If you have specified this field manually, + it should be the actual (computed) hash of the underlying lambda + function specified in the filename, image_uri, s3_bucket fields. type: string sourceCodeSize: description: Size in bytes of the function .zip file.