diff --git a/pkg/generate/code/set_resource.go b/pkg/generate/code/set_resource.go index 7576cc0b..765e2669 100644 --- a/pkg/generate/code/set_resource.go +++ b/pkg/generate/code/set_resource.go @@ -793,7 +793,6 @@ func SetResourceGetAttributes( out := "\n" indent := strings.Repeat("\t", indentLevel) - adaptiveTargetVarName := targetVarName + cfg.PrefixConfig.StatusField // did we output an ACKResourceMetadata guard and constructor snippet? mdGuardOut := false @@ -806,6 +805,7 @@ func SetResourceGetAttributes( } sort.Strings(sortedAttrFieldNames) for _, fieldName := range sortedAttrFieldNames { + adaptiveTargetVarName := targetVarName + cfg.PrefixConfig.StatusField if r.IsPrimaryARNField(fieldName) { if !mdGuardOut { out += ackResourceMetadataGuardConstructor( @@ -850,16 +850,17 @@ func SetResourceGetAttributes( } fieldNames := names.New(fieldName) - if fieldConfig.IsReadOnly { - out += fmt.Sprintf( - "%s%s.%s = %s.Attributes[\"%s\"]\n", - indent, - adaptiveTargetVarName, - fieldNames.Camel, - sourceVarName, - fieldName, - ) + if !fieldConfig.IsReadOnly { + adaptiveTargetVarName = targetVarName + cfg.PrefixConfig.SpecField } + out += fmt.Sprintf( + "%s%s.%s = %s.Attributes[\"%s\"]\n", + indent, + adaptiveTargetVarName, + fieldNames.Camel, + sourceVarName, + fieldName, + ) } return out } diff --git a/pkg/generate/code/set_resource_test.go b/pkg/generate/code/set_resource_test.go index 56a8d36e..b9daedd1 100644 --- a/pkg/generate/code/set_resource_test.go +++ b/pkg/generate/code/set_resource_test.go @@ -2712,12 +2712,16 @@ func TestSetResource_SNS_Topic_GetAttributes(t *testing.T) { // (and thus in the Spec fields). Two of them are the tesource's ARN and // AWS Owner account ID, both of which are handled specially. expected := ` + ko.Spec.DeliveryPolicy = resp.Attributes["DeliveryPolicy"] + ko.Spec.DisplayName = resp.Attributes["DisplayName"] ko.Status.EffectiveDeliveryPolicy = resp.Attributes["EffectiveDeliveryPolicy"] + ko.Spec.KMSMasterKeyID = resp.Attributes["KmsMasterKeyId"] if ko.Status.ACKResourceMetadata == nil { ko.Status.ACKResourceMetadata = &ackv1alpha1.ResourceMetadata{} } tmpOwnerID := ackv1alpha1.AWSAccountID(*resp.Attributes["Owner"]) ko.Status.ACKResourceMetadata.OwnerAccountID = &tmpOwnerID + ko.Spec.Policy = resp.Attributes["Policy"] tmpARN := ackv1alpha1.AWSResourceName(*resp.Attributes["TopicArn"]) ko.Status.ACKResourceMetadata.ARN = &tmpARN ` @@ -2766,13 +2770,24 @@ func TestSetResource_SQS_Queue_GetAttributes(t *testing.T) { // (and thus in the Spec fields). One of them is the resource's ARN which // is handled specially. expected := ` + ko.Spec.ContentBasedDeduplication = resp.Attributes["ContentBasedDeduplication"] ko.Status.CreatedTimestamp = resp.Attributes["CreatedTimestamp"] + ko.Spec.DelaySeconds = resp.Attributes["DelaySeconds"] + ko.Spec.FifoQueue = resp.Attributes["FifoQueue"] + ko.Spec.KMSDataKeyReusePeriodSeconds = resp.Attributes["KmsDataKeyReusePeriodSeconds"] + ko.Spec.KMSMasterKeyID = resp.Attributes["KmsMasterKeyId"] ko.Status.LastModifiedTimestamp = resp.Attributes["LastModifiedTimestamp"] + ko.Spec.MaximumMessageSize = resp.Attributes["MaximumMessageSize"] + ko.Spec.MessageRetentionPeriod = resp.Attributes["MessageRetentionPeriod"] + ko.Spec.Policy = resp.Attributes["Policy"] if ko.Status.ACKResourceMetadata == nil { ko.Status.ACKResourceMetadata = &ackv1alpha1.ResourceMetadata{} } tmpARN := ackv1alpha1.AWSResourceName(*resp.Attributes["QueueArn"]) ko.Status.ACKResourceMetadata.ARN = &tmpARN + ko.Spec.ReceiveMessageWaitTimeSeconds = resp.Attributes["ReceiveMessageWaitTimeSeconds"] + ko.Spec.RedrivePolicy = resp.Attributes["RedrivePolicy"] + ko.Spec.VisibilityTimeout = resp.Attributes["VisibilityTimeout"] ` assert.Equal( expected, diff --git a/templates/pkg/resource/sdk_update_set_attributes.go.tpl b/templates/pkg/resource/sdk_update_set_attributes.go.tpl index 901765b2..6fecfbe0 100644 --- a/templates/pkg/resource/sdk_update_set_attributes.go.tpl +++ b/templates/pkg/resource/sdk_update_set_attributes.go.tpl @@ -5,6 +5,7 @@ func (rm *resourceManager) sdkUpdate( latest *resource, delta *ackcompare.Delta, ) (*resource, error) { + var err error rlog := ackrtlog.FromContext(ctx) exit := rlog.Trace("rm.sdkUpdate") defer func() {