Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions pkg/generate/code/set_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/generate/code/set_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
`
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions templates/pkg/resource/sdk_update_set_attributes.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down