Skip to content

Commit 68c62f4

Browse files
authored
Merge pull request #35723 from hashicorp/td-paginated-listtags
Paginated ListTags APIs
2 parents 5e1d978 + e568ccd commit 68c62f4

File tree

20 files changed

+193
-49
lines changed

20 files changed

+193
-49
lines changed

internal/generate/tags/main.go

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -116,34 +116,34 @@ func newTemplateBody(version int, kvtValues bool) *TemplateBody {
116116
switch version {
117117
case sdkV1:
118118
return &TemplateBody{
119-
"\n" + v1.GetTagBody,
120-
v1.HeaderBody,
121-
"\n" + v1.ListTagsBody,
122-
"\n" + v1.ServiceTagsMapBody,
123-
"\n" + v1.ServiceTagsSliceBody,
124-
"\n" + v1.UpdateTagsBody,
125-
"\n" + v1.WaitTagsPropagatedBody,
119+
getTag: "\n" + v1.GetTagBody,
120+
header: v1.HeaderBody,
121+
listTags: "\n" + v1.ListTagsBody,
122+
serviceTagsMap: "\n" + v1.ServiceTagsMapBody,
123+
serviceTagsSlice: "\n" + v1.ServiceTagsSliceBody,
124+
updateTags: "\n" + v1.UpdateTagsBody,
125+
waitTagsPropagated: "\n" + v1.WaitTagsPropagatedBody,
126126
}
127127
case sdkV2:
128128
if kvtValues {
129129
return &TemplateBody{
130-
"\n" + v2.GetTagBody,
131-
v2.HeaderBody,
132-
"\n" + v2.ListTagsBody,
133-
"\n" + v2.ServiceTagsValueMapBody,
134-
"\n" + v2.ServiceTagsSliceBody,
135-
"\n" + v2.UpdateTagsBody,
136-
"\n" + v2.WaitTagsPropagatedBody,
130+
getTag: "\n" + v2.GetTagBody,
131+
header: v2.HeaderBody,
132+
listTags: "\n" + v2.ListTagsBody,
133+
serviceTagsMap: "\n" + v2.ServiceTagsValueMapBody,
134+
serviceTagsSlice: "\n" + v2.ServiceTagsSliceBody,
135+
updateTags: "\n" + v2.UpdateTagsBody,
136+
waitTagsPropagated: "\n" + v2.WaitTagsPropagatedBody,
137137
}
138138
}
139139
return &TemplateBody{
140-
"\n" + v2.GetTagBody,
141-
v2.HeaderBody,
142-
"\n" + v2.ListTagsBody,
143-
"\n" + v2.ServiceTagsMapBody,
144-
"\n" + v2.ServiceTagsSliceBody,
145-
"\n" + v2.UpdateTagsBody,
146-
"\n" + v2.WaitTagsPropagatedBody,
140+
getTag: "\n" + v2.GetTagBody,
141+
header: v2.HeaderBody,
142+
listTags: "\n" + v2.ListTagsBody,
143+
serviceTagsMap: "\n" + v2.ServiceTagsMapBody,
144+
serviceTagsSlice: "\n" + v2.ServiceTagsSliceBody,
145+
updateTags: "\n" + v2.UpdateTagsBody,
146+
waitTagsPropagated: "\n" + v2.WaitTagsPropagatedBody,
147147
}
148148
default:
149149
return nil
@@ -172,6 +172,7 @@ type TemplateData struct {
172172
ParentNotFoundErrCode string
173173
ParentNotFoundErrMsg string
174174
RetryCreateOnNotFound string
175+
ServiceTagsMap bool
175176
SetTagsOutFunc string
176177
TagInCustomVal string
177178
TagInIDElem string
@@ -333,6 +334,7 @@ func main() {
333334
ListTagsOutTagsElem: *listTagsOutTagsElem,
334335
ParentNotFoundErrCode: *parentNotFoundErrCode,
335336
ParentNotFoundErrMsg: *parentNotFoundErrMsg,
337+
ServiceTagsMap: *serviceTagsMap,
336338
SetTagsOutFunc: *setTagsOutFunc,
337339
TagInCustomVal: *tagInCustomVal,
338340
TagInIDElem: *tagInIDElem,

internal/generate/tags/templates/v1/header_body.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,7 @@ import (
5050
{{- if .NamesPkg }}
5151
"github.com/hashicorp/terraform-provider-aws/names"
5252
{{- end }}
53+
{{- if and .ListTagsOpPaginated .ServiceTagsMap }}
54+
"golang.org/x/exp/maps"
55+
{{- end }}
5356
)

internal/generate/tags/templates/v1/list_tags_body.tmpl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,26 @@ func {{ .ListTagsFunc }}(ctx context.Context, conn {{ .ClientType }}, identifier
2222
{{- end }}
2323
}
2424
{{- if .ListTagsOpPaginated }}
25-
var output []*{{ .TagPackage }}.{{ .TagType }}
25+
{{- if .ServiceTagsMap }}
26+
output := make(map[string]*string)
27+
{{- else }}
28+
var output []*{{ .TagPackage }}.{{ or .TagType2 .TagType }}
29+
{{- end }}
2630

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

36+
{{ if .ServiceTagsMap }}
37+
maps.Copy(output, page.{{ .ListTagsOutTagsElem }})
38+
{{- else }}
3239
for _, v := range page.{{ .ListTagsOutTagsElem }} {
3340
if v != nil {
3441
output = append(output, v)
3542
}
3643
}
44+
{{- end }}
3745

3846
return !lastPage
3947
})

internal/generate/tags/templates/v2/list_tags_body.tmpl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,40 @@ func {{ .ListTagsFunc }}(ctx context.Context, conn {{ .ClientType }}, identifier
2323
{{- end }}
2424
{{- end }}
2525
}
26+
{{- if .ListTagsOpPaginated }}
27+
var output []awstypes.{{ or .TagType2 .TagType }}
28+
29+
pages := {{ .TagPackage }}.New{{ .ListTagsOp }}Paginator(conn, input)
30+
for pages.HasMorePages() {
31+
page, err := pages.NextPage(ctx)
32+
33+
{{ if and ( .ParentNotFoundErrCode ) ( .ParentNotFoundErrMsg ) }}
34+
if tfawserr.ErrMessageContains(err, "{{ .ParentNotFoundErrCode }}", "{{ .ParentNotFoundErrMsg }}") {
35+
return nil, &retry.NotFoundError{
36+
LastError: err,
37+
LastRequest: input,
38+
}
39+
}
40+
{{- else if ( .ParentNotFoundErrCode ) }}
41+
if tfawserr.ErrCodeEquals(err, "{{ .ParentNotFoundErrCode }}") {
42+
return nil, &retry.NotFoundError{
43+
LastError: err,
44+
LastRequest: input,
45+
}
46+
}
47+
{{- end }}
48+
49+
if err != nil {
50+
return tftags.New(ctx, nil), err
51+
}
52+
53+
for _, v := range page.{{ .ListTagsOutTagsElem }} {
54+
output = append(output, v)
55+
}
56+
}
57+
58+
return {{ .KeyValueTagsFunc }}(ctx, output{{ if .TagTypeIDElem }}, identifier{{ if .TagResTypeElem }}, resourceType{{ end }}{{ end }}), nil
59+
{{- else }}
2660

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

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

4983
return {{ .KeyValueTagsFunc }}(ctx, output.{{ .ListTagsOutTagsElem }}{{ if .TagTypeIDElem }}, identifier{{ if .TagResTypeElem }}, resourceType{{ end }}{{ end }}), nil
84+
{{- end }}
5085
}
5186

5287
{{- if .IsDefaultListTags }}

internal/service/acmpca/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) HashiCorp, Inc.
22
// SPDX-License-Identifier: MPL-2.0
33

4-
//go:generate go run ../../generate/tags/main.go -ListTags -ListTagsOp=ListTags -ListTagsInIDElem=CertificateAuthorityArn -ServiceTagsSlice -TagOp=TagCertificateAuthority -TagInIDElem=CertificateAuthorityArn -UntagOp=UntagCertificateAuthority -UntagInNeedTagType -UntagInTagsElem=Tags -UpdateTags
4+
//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
55
//go:generate go run ../../generate/servicepackage/main.go
66
// ONLY generate directives and package declaration! Do not add anything else to this file.
77

internal/service/acmpca/tags_gen.go

Lines changed: 15 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/service/autoscaling/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) HashiCorp, Inc.
22
// SPDX-License-Identifier: MPL-2.0
33

4-
//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
4+
//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
55
//go:generate go run ../../generate/listpages/main.go -ListOps=DescribeInstanceRefreshes,DescribeLoadBalancers,DescribeLoadBalancerTargetGroups,DescribeWarmPool
66
//go:generate go run ../../generate/servicepackage/main.go
77
// ONLY generate directives and package declaration! Do not add anything else to this file.

internal/service/autoscaling/tags_gen.go

Lines changed: 15 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/service/backup/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) HashiCorp, Inc.
22
// SPDX-License-Identifier: MPL-2.0
33

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

internal/service/backup/tags_gen.go

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/service/cloudhsmv2/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) HashiCorp, Inc.
22
// SPDX-License-Identifier: MPL-2.0
33

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

internal/service/cloudhsmv2/tags_gen.go

Lines changed: 15 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/service/cloudtrail/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) HashiCorp, Inc.
22
// SPDX-License-Identifier: MPL-2.0
33

4-
//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
4+
//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
55
//go:generate go run ../../generate/servicepackage/main.go
66
// ONLY generate directives and package declaration! Do not add anything else to this file.
77

internal/service/cloudtrail/tags_gen.go

Lines changed: 12 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/service/ec2/generate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// SPDX-License-Identifier: MPL-2.0
33

44
//go:generate go run ../../generate/tagresource/main.go -IDAttribName=resource_id -UpdateTagsFunc=updateTagsV2
5-
//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
6-
//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
5+
//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
6+
//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
77
//go:generate go run ../../generate/listpages/main.go -ListOps=DescribeSpotFleetInstances,DescribeSpotFleetRequestHistory,DescribeVpcEndpointServices
88
//go:generate go run ../../generate/servicepackage/main.go
99
// ONLY generate directives and package declaration! Do not add anything else to this file.

internal/service/ec2/tags_gen.go

Lines changed: 15 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)