Skip to content

Commit ebb9eb6

Browse files
authored
fix(aws): Re-add Route53 hosted zone tags (#2480)
Should fix #2027
1 parent 0aa31a4 commit ebb9eb6

7 files changed

Lines changed: 61 additions & 31 deletions

File tree

plugins/source/aws/codegen/recipes/base.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ var defaultRegionalColumns = []codegen.ColumnDefinition{
5959
func awsNameTransformer(f reflect.StructField) (string, error) {
6060
c := caser.New(caser.WithCustomInitialisms(map[string]bool{
6161
"EC2": true,
62+
"VPC": true,
6263
}))
6364
return c.ToSnake(f.Name), nil
6465
}

plugins/source/aws/codegen/recipes/route53.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package recipes
22

33
import (
4+
"reflect"
5+
"strings"
6+
47
"github.com/aws/aws-sdk-go-v2/service/route53/types"
58
"github.com/aws/aws-sdk-go-v2/service/route53domains"
9+
"github.com/cloudquery/cloudquery/plugins/source/aws/resources/services/route53/models"
610
"github.com/cloudquery/plugin-sdk/codegen"
711
"github.com/cloudquery/plugin-sdk/schema"
812
)
@@ -80,7 +84,7 @@ func Route53Resources() []*Resource {
8084

8185
{
8286
SubService: "hosted_zones",
83-
Struct: &types.HostedZone{},
87+
Struct: &models.Route53HostedZoneWrapper{},
8488
SkipFields: []string{"ARN"},
8589
ExtraColumns: append(
8690
defaultAccountColumns,
@@ -209,6 +213,10 @@ func Route53Resources() []*Resource {
209213
for _, r := range resources {
210214
r.Service = "route53"
211215
r.Multiplex = "client.AccountMultiplex"
216+
structName := reflect.ValueOf(r.Struct).Elem().Type().Name()
217+
if strings.Contains(structName, "Wrapper") {
218+
r.UnwrapEmbeddedStructs = true
219+
}
212220
}
213221
return resources
214222
}

plugins/source/aws/docs/tables/aws_route53_hosted_zones.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ The following tables depend on `aws_route53_hosted_zones`:
2424
|name|String|
2525
|config|JSON|
2626
|linked_service|JSON|
27-
|resource_record_set_count|Int|
27+
|resource_record_set_count|Int|
28+
|tags|JSON|
29+
|delegation_set_id|String|
30+
|vpcs|JSON|

plugins/source/aws/resources/services/route53/hosted_zones.go

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

plugins/source/aws/resources/services/route53/hosted_zones_fetch.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,10 @@ import (
99
"github.com/aws/aws-sdk-go-v2/service/route53"
1010
"github.com/aws/aws-sdk-go-v2/service/route53/types"
1111
"github.com/cloudquery/cloudquery/plugins/source/aws/client"
12+
"github.com/cloudquery/cloudquery/plugins/source/aws/resources/services/route53/models"
1213
"github.com/cloudquery/plugin-sdk/schema"
1314
)
1415

15-
type Route53HostedZoneWrapper struct {
16-
types.HostedZone
17-
Tags map[string]string
18-
DelegationSetId *string
19-
VPCs []types.VPC
20-
}
21-
2216
func fetchRoute53HostedZones(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
2317
var config route53.ListHostedZonesInput
2418
c := meta.(*client.Client)
@@ -44,13 +38,12 @@ func fetchRoute53HostedZones(ctx context.Context, meta schema.ClientMeta, parent
4438
if gotHostedZone.DelegationSet != nil {
4539
delegationSetId = gotHostedZone.DelegationSet.Id
4640
}
47-
wrapper := Route53HostedZoneWrapper{
41+
res <- &models.Route53HostedZoneWrapper{
4842
HostedZone: h,
4943
Tags: client.TagsToMap(getRoute53tagsByResourceID(*h.Id, tagsResponse.ResourceTagSets)),
5044
DelegationSetId: delegationSetId,
5145
VPCs: gotHostedZone.VPCs,
5246
}
53-
res <- wrapper
5447
}
5548
return nil
5649
}
@@ -82,7 +75,7 @@ func fetchRoute53HostedZones(ctx context.Context, meta schema.ClientMeta, parent
8275
return nil
8376
}
8477
func fetchRoute53HostedZoneQueryLoggingConfigs(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
85-
r := parent.Item.(Route53HostedZoneWrapper)
78+
r := parent.Item.(*models.Route53HostedZoneWrapper)
8679
svc := meta.(*client.Client).Services().Route53
8780
config := route53.ListQueryLoggingConfigsInput{HostedZoneId: r.Id}
8881
for {
@@ -99,7 +92,7 @@ func fetchRoute53HostedZoneQueryLoggingConfigs(ctx context.Context, meta schema.
9992
return nil
10093
}
10194
func fetchRoute53HostedZoneResourceRecordSets(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
102-
r := parent.Item.(Route53HostedZoneWrapper)
95+
r := parent.Item.(*models.Route53HostedZoneWrapper)
10396
svc := meta.(*client.Client).Services().Route53
10497
config := route53.ListResourceRecordSetsInput{HostedZoneId: r.Id}
10598
for {
@@ -121,7 +114,7 @@ func fetchRoute53HostedZoneResourceRecordSets(ctx context.Context, meta schema.C
121114
return nil
122115
}
123116
func fetchRoute53HostedZoneTrafficPolicyInstances(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
124-
r := parent.Item.(Route53HostedZoneWrapper)
117+
r := parent.Item.(*models.Route53HostedZoneWrapper)
125118
config := route53.ListTrafficPolicyInstancesByHostedZoneInput{HostedZoneId: r.Id}
126119
svc := meta.(*client.Client).Services().Route53
127120
for {
@@ -148,7 +141,7 @@ func getRoute53tagsByResourceID(id string, set []types.ResourceTagSet) []types.T
148141
}
149142
func resolveRoute53HostedZoneArn(_ context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
150143
cl := meta.(*client.Client)
151-
hz := resource.Item.(Route53HostedZoneWrapper)
144+
hz := resource.Item.(*models.Route53HostedZoneWrapper)
152145
return resource.Set(c.Name, cl.PartitionGlobalARN(client.Route53Service, "hostedzone", *hz.Id))
153146
}
154147
func resolveRoute53HostedZoneQueryLoggingConfigsArn(_ context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {

plugins/source/aws/resources/services/route53/hosted_zones_mock_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"testing"
66

77
"github.com/aws/aws-sdk-go-v2/service/route53"
8-
route53Types "github.com/aws/aws-sdk-go-v2/service/route53/types"
8+
"github.com/aws/aws-sdk-go-v2/service/route53/types"
99
"github.com/cloudquery/cloudquery/plugins/source/aws/client"
1010
"github.com/cloudquery/cloudquery/plugins/source/aws/client/mocks"
1111
"github.com/cloudquery/faker/v3"
@@ -14,60 +14,60 @@ import (
1414

1515
func buildRoute53HostedZonesMock(t *testing.T, ctrl *gomock.Controller) client.Services {
1616
m := mocks.NewMockRoute53Client(ctrl)
17-
h := route53Types.HostedZone{}
17+
h := types.HostedZone{}
1818
if err := faker.FakeData(&h); err != nil {
1919
t.Fatal(err)
2020
}
2121
m.EXPECT().ListHostedZones(gomock.Any(), gomock.Any(), gomock.Any()).Return(
2222
&route53.ListHostedZonesOutput{
23-
HostedZones: []route53Types.HostedZone{h},
23+
HostedZones: []types.HostedZone{h},
2424
}, nil)
25-
tag := route53Types.Tag{}
25+
tag := types.Tag{}
2626
if err := faker.FakeData(&tag); err != nil {
2727
t.Fatal(err)
2828
}
2929
//create id that is usually returned by aws
3030
hzId := *h.Id
31-
newId := fmt.Sprintf("/%s/%s", route53Types.TagResourceTypeHostedzone, *h.Id)
31+
newId := fmt.Sprintf("/%s/%s", types.TagResourceTypeHostedzone, *h.Id)
3232
h.Id = &newId
3333
m.EXPECT().ListTagsForResources(gomock.Any(), gomock.Any(), gomock.Any()).Return(
3434
&route53.ListTagsForResourcesOutput{
35-
ResourceTagSets: []route53Types.ResourceTagSet{
35+
ResourceTagSets: []types.ResourceTagSet{
3636
{
3737
ResourceId: &hzId,
38-
Tags: []route53Types.Tag{tag},
38+
Tags: []types.Tag{tag},
3939
},
4040
},
4141
}, nil)
42-
qlc := route53Types.QueryLoggingConfig{}
42+
qlc := types.QueryLoggingConfig{}
4343
if err := faker.FakeData(&qlc); err != nil {
4444
t.Fatal(err)
4545
}
4646
m.EXPECT().ListQueryLoggingConfigs(gomock.Any(), gomock.Any(), gomock.Any()).Return(
4747
&route53.ListQueryLoggingConfigsOutput{
48-
QueryLoggingConfigs: []route53Types.QueryLoggingConfig{qlc},
48+
QueryLoggingConfigs: []types.QueryLoggingConfig{qlc},
4949
}, nil)
50-
rrs := route53Types.ResourceRecordSet{}
50+
rrs := types.ResourceRecordSet{}
5151
if err := faker.FakeData(&rrs); err != nil {
5252
t.Fatal(err)
5353
}
5454
m.EXPECT().ListResourceRecordSets(gomock.Any(), gomock.Any(), gomock.Any()).Return(
5555
&route53.ListResourceRecordSetsOutput{
56-
ResourceRecordSets: []route53Types.ResourceRecordSet{rrs},
56+
ResourceRecordSets: []types.ResourceRecordSet{rrs},
5757
}, nil)
58-
tpi := route53Types.TrafficPolicyInstance{}
58+
tpi := types.TrafficPolicyInstance{}
5959
if err := faker.FakeData(&tpi); err != nil {
6060
t.Fatal(err)
6161
}
6262
m.EXPECT().ListTrafficPolicyInstancesByHostedZone(gomock.Any(), gomock.Any(), gomock.Any()).Return(
6363
&route53.ListTrafficPolicyInstancesByHostedZoneOutput{
64-
TrafficPolicyInstances: []route53Types.TrafficPolicyInstance{tpi},
64+
TrafficPolicyInstances: []types.TrafficPolicyInstance{tpi},
6565
}, nil)
66-
vpc := route53Types.VPC{}
66+
vpc := types.VPC{}
6767
if err := faker.FakeData(&vpc); err != nil {
6868
t.Fatal(err)
6969
}
70-
ds := route53Types.DelegationSet{}
70+
ds := types.DelegationSet{}
7171
if err := faker.FakeData(&ds); err != nil {
7272
t.Fatal(err)
7373
}
@@ -76,7 +76,7 @@ func buildRoute53HostedZonesMock(t *testing.T, ctrl *gomock.Controller) client.S
7676
&route53.GetHostedZoneOutput{
7777
HostedZone: &h,
7878
DelegationSet: &ds,
79-
VPCs: []route53Types.VPC{vpc},
79+
VPCs: []types.VPC{vpc},
8080
}, nil)
8181
return client.Services{
8282
Route53: m,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package models
2+
3+
import "github.com/aws/aws-sdk-go-v2/service/route53/types"
4+
5+
type Route53HostedZoneWrapper struct {
6+
types.HostedZone
7+
Tags map[string]string
8+
DelegationSetId *string
9+
VPCs []types.VPC
10+
}

0 commit comments

Comments
 (0)