Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paginated ListTags APIs #35723

Merged
merged 6 commits into from
Feb 8, 2024
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
44 changes: 23 additions & 21 deletions internal/generate/tags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,34 +116,34 @@ func newTemplateBody(version int, kvtValues bool) *TemplateBody {
switch version {
case sdkV1:
return &TemplateBody{
"\n" + v1.GetTagBody,
v1.HeaderBody,
"\n" + v1.ListTagsBody,
"\n" + v1.ServiceTagsMapBody,
"\n" + v1.ServiceTagsSliceBody,
"\n" + v1.UpdateTagsBody,
"\n" + v1.WaitTagsPropagatedBody,
getTag: "\n" + v1.GetTagBody,
header: v1.HeaderBody,
listTags: "\n" + v1.ListTagsBody,
serviceTagsMap: "\n" + v1.ServiceTagsMapBody,
serviceTagsSlice: "\n" + v1.ServiceTagsSliceBody,
updateTags: "\n" + v1.UpdateTagsBody,
waitTagsPropagated: "\n" + v1.WaitTagsPropagatedBody,
}
case sdkV2:
if kvtValues {
return &TemplateBody{
"\n" + v2.GetTagBody,
v2.HeaderBody,
"\n" + v2.ListTagsBody,
"\n" + v2.ServiceTagsValueMapBody,
"\n" + v2.ServiceTagsSliceBody,
"\n" + v2.UpdateTagsBody,
"\n" + v2.WaitTagsPropagatedBody,
getTag: "\n" + v2.GetTagBody,
header: v2.HeaderBody,
listTags: "\n" + v2.ListTagsBody,
serviceTagsMap: "\n" + v2.ServiceTagsValueMapBody,
serviceTagsSlice: "\n" + v2.ServiceTagsSliceBody,
updateTags: "\n" + v2.UpdateTagsBody,
waitTagsPropagated: "\n" + v2.WaitTagsPropagatedBody,
}
}
return &TemplateBody{
"\n" + v2.GetTagBody,
v2.HeaderBody,
"\n" + v2.ListTagsBody,
"\n" + v2.ServiceTagsMapBody,
"\n" + v2.ServiceTagsSliceBody,
"\n" + v2.UpdateTagsBody,
"\n" + v2.WaitTagsPropagatedBody,
getTag: "\n" + v2.GetTagBody,
header: v2.HeaderBody,
listTags: "\n" + v2.ListTagsBody,
serviceTagsMap: "\n" + v2.ServiceTagsMapBody,
serviceTagsSlice: "\n" + v2.ServiceTagsSliceBody,
updateTags: "\n" + v2.UpdateTagsBody,
waitTagsPropagated: "\n" + v2.WaitTagsPropagatedBody,
}
default:
return nil
Expand Down Expand Up @@ -172,6 +172,7 @@ type TemplateData struct {
ParentNotFoundErrCode string
ParentNotFoundErrMsg string
RetryCreateOnNotFound string
ServiceTagsMap bool
SetTagsOutFunc string
TagInCustomVal string
TagInIDElem string
Expand Down Expand Up @@ -333,6 +334,7 @@ func main() {
ListTagsOutTagsElem: *listTagsOutTagsElem,
ParentNotFoundErrCode: *parentNotFoundErrCode,
ParentNotFoundErrMsg: *parentNotFoundErrMsg,
ServiceTagsMap: *serviceTagsMap,
SetTagsOutFunc: *setTagsOutFunc,
TagInCustomVal: *tagInCustomVal,
TagInIDElem: *tagInIDElem,
Expand Down
3 changes: 3 additions & 0 deletions internal/generate/tags/templates/v1/header_body.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ import (
{{- if .NamesPkg }}
"github.com/hashicorp/terraform-provider-aws/names"
{{- end }}
{{- if and .ListTagsOpPaginated .ServiceTagsMap }}
"golang.org/x/exp/maps"
{{- end }}
)
10 changes: 9 additions & 1 deletion internal/generate/tags/templates/v1/list_tags_body.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,26 @@ func {{ .ListTagsFunc }}(ctx context.Context, conn {{ .ClientType }}, identifier
{{- end }}
}
{{- if .ListTagsOpPaginated }}
var output []*{{ .TagPackage }}.{{ .TagType }}
{{- if .ServiceTagsMap }}
output := make(map[string]*string)
{{- else }}
var output []*{{ .TagPackage }}.{{ or .TagType2 .TagType }}
{{- end }}

err := conn.{{ .ListTagsOp }}PagesWithContext(ctx, input, func(page *{{ .TagPackage }}.{{ .ListTagsOp }}Output, lastPage bool) bool {
if page == nil {
return !lastPage
}

{{ if .ServiceTagsMap }}
maps.Copy(output, page.{{ .ListTagsOutTagsElem }})
{{- else }}
for _, v := range page.{{ .ListTagsOutTagsElem }} {
if v != nil {
output = append(output, v)
}
}
{{- end }}

return !lastPage
})
Expand Down
35 changes: 35 additions & 0 deletions internal/generate/tags/templates/v2/list_tags_body.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,40 @@ func {{ .ListTagsFunc }}(ctx context.Context, conn {{ .ClientType }}, identifier
{{- end }}
{{- end }}
}
{{- if .ListTagsOpPaginated }}
var output []awstypes.{{ or .TagType2 .TagType }}

pages := {{ .TagPackage }}.New{{ .ListTagsOp }}Paginator(conn, input)
for pages.HasMorePages() {
page, err := pages.NextPage(ctx)

{{ if and ( .ParentNotFoundErrCode ) ( .ParentNotFoundErrMsg ) }}
if tfawserr.ErrMessageContains(err, "{{ .ParentNotFoundErrCode }}", "{{ .ParentNotFoundErrMsg }}") {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}
{{- else if ( .ParentNotFoundErrCode ) }}
if tfawserr.ErrCodeEquals(err, "{{ .ParentNotFoundErrCode }}") {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}
{{- end }}

if err != nil {
return tftags.New(ctx, nil), err
}

for _, v := range page.{{ .ListTagsOutTagsElem }} {
output = append(output, v)
}
}

return {{ .KeyValueTagsFunc }}(ctx, output{{ if .TagTypeIDElem }}, identifier{{ if .TagResTypeElem }}, resourceType{{ end }}{{ end }}), nil
{{- else }}

output, err := conn.{{ .ListTagsOp }}(ctx, input, optFns...)

Expand All @@ -47,6 +81,7 @@ func {{ .ListTagsFunc }}(ctx context.Context, conn {{ .ClientType }}, identifier
}

return {{ .KeyValueTagsFunc }}(ctx, output.{{ .ListTagsOutTagsElem }}{{ if .TagTypeIDElem }}, identifier{{ if .TagResTypeElem }}, resourceType{{ end }}{{ end }}), nil
{{- end }}
}

{{- if .IsDefaultListTags }}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/acmpca/generate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

//go:generate go run ../../generate/tags/main.go -ListTags -ListTagsOp=ListTags -ListTagsInIDElem=CertificateAuthorityArn -ServiceTagsSlice -TagOp=TagCertificateAuthority -TagInIDElem=CertificateAuthorityArn -UntagOp=UntagCertificateAuthority -UntagInNeedTagType -UntagInTagsElem=Tags -UpdateTags
//go:generate go run ../../generate/tags/main.go -ListTags -ListTagsOp=ListTags -ListTagsOpPaginated -ListTagsInIDElem=CertificateAuthorityArn -ServiceTagsSlice -TagOp=TagCertificateAuthority -TagInIDElem=CertificateAuthorityArn -UntagOp=UntagCertificateAuthority -UntagInNeedTagType -UntagInTagsElem=Tags -UpdateTags
//go:generate go run ../../generate/servicepackage/main.go
// ONLY generate directives and package declaration! Do not add anything else to this file.

Expand Down
17 changes: 15 additions & 2 deletions internal/service/acmpca/tags_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/service/autoscaling/generate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

//go:generate go run ../../generate/tags/main.go -GetTag -ListTags -ListTagsOp=DescribeTags -ListTagsInFiltIDName=auto-scaling-group -ServiceTagsSlice -TagOp=CreateOrUpdateTags -TagResTypeElem=ResourceType -TagType2=TagDescription -TagTypeAddBoolElem=PropagateAtLaunch -TagTypeIDElem=ResourceId -UntagOp=DeleteTags -UntagInNeedTagType -UntagInTagsElem=Tags -UpdateTags
//go:generate go run ../../generate/tags/main.go -GetTag -ListTags -ListTagsOp=DescribeTags -ListTagsOpPaginated -ListTagsInFiltIDName=auto-scaling-group -ServiceTagsSlice -TagOp=CreateOrUpdateTags -TagResTypeElem=ResourceType -TagType2=TagDescription -TagTypeAddBoolElem=PropagateAtLaunch -TagTypeIDElem=ResourceId -UntagOp=DeleteTags -UntagInNeedTagType -UntagInTagsElem=Tags -UpdateTags
//go:generate go run ../../generate/listpages/main.go -ListOps=DescribeInstanceRefreshes,DescribeLoadBalancers,DescribeLoadBalancerTargetGroups,DescribeWarmPool
//go:generate go run ../../generate/servicepackage/main.go
// ONLY generate directives and package declaration! Do not add anything else to this file.
Expand Down
17 changes: 15 additions & 2 deletions internal/service/autoscaling/tags_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/service/backup/generate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

//go:generate go run ../../generate/tags/main.go -ListTags -ListTagsOp=ListTags -ServiceTagsMap -UntagInTagsElem=TagKeyList -UpdateTags
//go:generate go run ../../generate/tags/main.go -ListTags -ListTagsOp=ListTags -ListTagsOpPaginated -ServiceTagsMap -UntagInTagsElem=TagKeyList -UpdateTags
//go:generate go run ../../generate/servicepackage/main.go
// ONLY generate directives and package declaration! Do not add anything else to this file.

Expand Down
14 changes: 12 additions & 2 deletions internal/service/backup/tags_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/service/cloudhsmv2/generate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

//go:generate go run ../../generate/tags/main.go -ListTags -ListTagsOp=ListTags -ListTagsInIDElem=ResourceId -ListTagsOutTagsElem=TagList -ServiceTagsSlice -TagInIDElem=ResourceId -TagInTagsElem=TagList -UntagInTagsElem=TagKeyList -UpdateTags
//go:generate go run ../../generate/tags/main.go -ListTags -ListTagsOp=ListTags -ListTagsOpPaginated -ListTagsInIDElem=ResourceId -ListTagsOutTagsElem=TagList -ServiceTagsSlice -TagInIDElem=ResourceId -TagInTagsElem=TagList -UntagInTagsElem=TagKeyList -UpdateTags
//go:generate go run ../../generate/servicepackage/main.go
// ONLY generate directives and package declaration! Do not add anything else to this file.

Expand Down
17 changes: 15 additions & 2 deletions internal/service/cloudhsmv2/tags_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/service/cloudtrail/generate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -ListTags -ListTagsOp=ListTags -ListTagsInIDElem=ResourceIdList --ListTagsInIDNeedValueSlice=yes -ListTagsOutTagsElem=ResourceTagList[0].TagsList -ServiceTagsSlice -TagOp=AddTags -TagInIDElem=ResourceId -TagInTagsElem=TagsList -UntagOp=RemoveTags -UntagInNeedTagType -UntagInTagsElem=TagsList -UpdateTags
//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -ListTags -ListTagsOp=ListTags -ListTagsOpPaginated -ListTagsInIDElem=ResourceIdList --ListTagsInIDNeedValueSlice=yes -ListTagsOutTagsElem=ResourceTagList[0].TagsList -ServiceTagsSlice -TagOp=AddTags -TagInIDElem=ResourceId -TagInTagsElem=TagsList -UntagOp=RemoveTags -UntagInNeedTagType -UntagInTagsElem=TagsList -UpdateTags
//go:generate go run ../../generate/servicepackage/main.go
// ONLY generate directives and package declaration! Do not add anything else to this file.

Expand Down
16 changes: 12 additions & 4 deletions internal/service/cloudtrail/tags_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/service/ec2/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// SPDX-License-Identifier: MPL-2.0

//go:generate go run ../../generate/tagresource/main.go -IDAttribName=resource_id -UpdateTagsFunc=updateTagsV2
//go:generate go run ../../generate/tags/main.go -ListTags -ListTagsOp=DescribeTags -ListTagsInFiltIDName=resource-id -ListTagsInIDElem=Resources -ServiceTagsSlice -TagOp=CreateTags -TagInIDElem=Resources -TagInIDNeedSlice=yes -TagType2=TagDescription -UntagOp=DeleteTags -UntagInNeedTagType -UntagInTagsElem=Tags -UpdateTags
//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -GetTag -ListTagsOp=DescribeTags -ListTagsInFiltIDName=resource-id -ServiceTagsSlice -TagsFunc=TagsV2 -KeyValueTagsFunc=keyValueTagsV2 -GetTagsInFunc=getTagsInV2 -SetTagsOutFunc=setTagsOutV2 -TagOp=CreateTags -TagInIDElem=Resources -TagInIDNeedValueSlice=yes -TagType2=TagDescription -UntagOp=DeleteTags -UpdateTagsFunc=updateTagsV2 -UntagInNeedTagType -UntagInTagsElem=Tags -UpdateTags -- tagsv2_gen.go
//go:generate go run ../../generate/tags/main.go -ListTags -ListTagsOp=DescribeTags -ListTagsOpPaginated -ListTagsInFiltIDName=resource-id -ListTagsInIDElem=Resources -ServiceTagsSlice -TagOp=CreateTags -TagInIDElem=Resources -TagInIDNeedSlice=yes -TagType2=TagDescription -UntagOp=DeleteTags -UntagInNeedTagType -UntagInTagsElem=Tags -UpdateTags
//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -GetTag -ListTagsOp=DescribeTags -ListTagsOpPaginated -ListTagsInFiltIDName=resource-id -ServiceTagsSlice -TagsFunc=TagsV2 -KeyValueTagsFunc=keyValueTagsV2 -GetTagsInFunc=getTagsInV2 -SetTagsOutFunc=setTagsOutV2 -TagOp=CreateTags -TagInIDElem=Resources -TagInIDNeedValueSlice=yes -TagType2=TagDescription -UntagOp=DeleteTags -UpdateTagsFunc=updateTagsV2 -UntagInNeedTagType -UntagInTagsElem=Tags -UpdateTags -- tagsv2_gen.go
//go:generate go run ../../generate/listpages/main.go -ListOps=DescribeSpotFleetInstances,DescribeSpotFleetRequestHistory,DescribeVpcEndpointServices
//go:generate go run ../../generate/servicepackage/main.go
// ONLY generate directives and package declaration! Do not add anything else to this file.
Expand Down
17 changes: 15 additions & 2 deletions internal/service/ec2/tags_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading