Skip to content

Commit 158aab1

Browse files
authored
fix(aws): Handle Cloudfront Regions in different partitions (#10690)
#### Summary When syncing `aws-cn` the cloudfront region should be set to `cn-north-1` when partition is `aws-gov` then there is no cloudfront so no reason to set the multiplexer
1 parent 7a23c2e commit 158aab1

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

plugins/source/aws/client/account.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,18 @@ func (c *Client) setupAWSAccount(ctx context.Context, logger zerolog.Logger, aws
8888
}
8989
}
9090

91+
var cloudfrontRegion string
92+
switch iamArn.Partition {
93+
case "aws":
94+
cloudfrontRegion = awsCloudfrontScopeRegion
95+
case "aws-cn":
96+
cloudfrontRegion = awsCnCloudfrontScopeRegion
97+
}
98+
9199
svcsDetails[len(account.Regions)] = svcsDetail{
92100
partition: iamArn.Partition,
93101
accountId: *output.Account,
94-
svcs: initServices(cloudfrontScopeRegion, awsCfg),
102+
svcs: initServices(cloudfrontRegion, awsCfg),
95103
}
96104
return svcsDetails, nil
97105
}

plugins/source/aws/client/client.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ type ServicesManager struct {
5252
}
5353

5454
const (
55-
defaultRegion = "us-east-1"
56-
defaultVar = "default"
57-
cloudfrontScopeRegion = defaultRegion
55+
defaultRegion = "us-east-1"
56+
defaultVar = "default"
57+
awsCloudfrontScopeRegion = defaultRegion
58+
awsCnCloudfrontScopeRegion = "cn-north-1"
5859
)
5960

6061
var errInvalidRegion = errors.New("region wildcard \"*\" is only supported as first argument")

plugins/source/aws/client/multiplexers.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,14 @@ func ServiceAccountRegionScopeMultiplexer(table, service string) func(meta schem
118118
client := meta.(*Client)
119119
for partition := range client.ServicesManager.services {
120120
for accountID := range client.ServicesManager.services[partition] {
121-
// always fetch cloudfront related resources
122-
l = append(l, client.withPartitionAccountIDRegionAndScope(partition, accountID, cloudfrontScopeRegion, wafv2types.ScopeCloudfront))
121+
// always fetch cloudfront related resources as long as in aws or aws-cn partition
122+
switch partition {
123+
case "aws":
124+
l = append(l, client.withPartitionAccountIDRegionAndScope(partition, accountID, awsCloudfrontScopeRegion, wafv2types.ScopeCloudfront))
125+
case "aws-cn":
126+
l = append(l, client.withPartitionAccountIDRegionAndScope(partition, accountID, awsCnCloudfrontScopeRegion, wafv2types.ScopeCloudfront))
127+
}
128+
123129
for region := range client.ServicesManager.services[partition][accountID] {
124130
if !isSupportedServiceForRegion(service, region) {
125131
if client.specificRegions {

0 commit comments

Comments
 (0)