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

fix(awsutil): properly determine partition for all supported regions #143

Merged
merged 2 commits into from
Apr 17, 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
17 changes: 9 additions & 8 deletions pkg/commands/account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,19 @@ func execute(c *cli.Context) error {
// Set the default region for the AWS SDK to use.
if defaultRegion != "" {
awsutil.DefaultRegionID = defaultRegion
switch defaultRegion {
case endpoints.UsEast1RegionID, endpoints.UsEast2RegionID, endpoints.UsWest1RegionID, endpoints.UsWest2RegionID:
awsutil.DefaultAWSPartitionID = endpoints.AwsPartitionID
case endpoints.UsGovEast1RegionID, endpoints.UsGovWest1RegionID:
awsutil.DefaultAWSPartitionID = endpoints.AwsUsGovPartitionID
default:

partition, ok := endpoints.PartitionForRegion(endpoints.DefaultPartitions(), defaultRegion)
if !ok {
if parsedConfig.CustomEndpoints.GetRegion(defaultRegion) == nil {
err = fmt.Errorf("the custom region '%s' must be specified in the configuration 'endpoints'", defaultRegion)
logrus.Error(err.Error())
err = fmt.Errorf(
"the custom region '%s' must be specified in the configuration 'endpoints'"+
" to determine its partition", defaultRegion)
logrus.WithError(err).Errorf("unable to resolve partition for region: %s", defaultRegion)
return err
}
}

awsutil.DefaultAWSPartitionID = partition.ID()
}

// Create the AWS Account object. This will be used to get the account ID and aliases for the account.
Expand Down
17 changes: 9 additions & 8 deletions pkg/commands/nuke/nuke.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,19 @@ func execute(c *cli.Context) error { //nolint:funlen,gocyclo
// Set the default region for the AWS SDK to use.
if defaultRegion != "" {
awsutil.DefaultRegionID = defaultRegion
switch defaultRegion {
case endpoints.UsEast1RegionID, endpoints.UsEast2RegionID, endpoints.UsWest1RegionID, endpoints.UsWest2RegionID:
awsutil.DefaultAWSPartitionID = endpoints.AwsPartitionID
case endpoints.UsGovEast1RegionID, endpoints.UsGovWest1RegionID:
awsutil.DefaultAWSPartitionID = endpoints.AwsUsGovPartitionID
default:

partition, ok := endpoints.PartitionForRegion(endpoints.DefaultPartitions(), defaultRegion)
if !ok {
if parsedConfig.CustomEndpoints.GetRegion(defaultRegion) == nil {
err = fmt.Errorf("the custom region '%s' must be specified in the configuration 'endpoints'", defaultRegion)
logrus.Error(err.Error())
err = fmt.Errorf(
"the custom region '%s' must be specified in the configuration 'endpoints'"+
" to determine its partition", defaultRegion)
logrus.WithError(err).Errorf("unable to resolve partition for region: %s", defaultRegion)
return err
}
}

awsutil.DefaultAWSPartitionID = partition.ID()
}

// Create the AWS Account object. This will be used to get the account ID and aliases for the account.
Expand Down