Skip to content

Commit 3298a8e

Browse files
committed
Only configure STS region for route53 when we obtain it using IDMS
1 parent 951129c commit 3298a8e

File tree

1 file changed

+22
-19
lines changed
  • dnsprovider/pkg/dnsprovider/providers/aws/route53

1 file changed

+22
-19
lines changed

dnsprovider/pkg/dnsprovider/providers/aws/route53/route53.go

+22-19
Original file line numberDiff line numberDiff line change
@@ -71,34 +71,37 @@ func newRoute53() (*Interface, error) {
7171
region = imdsRegionResp.Region
7272
}
7373

74-
stsCfg, err := awsconfig.LoadDefaultConfig(ctx,
75-
awsconfig.WithClientLogMode(aws.LogRetries),
76-
awslog.WithAWSLogger(),
77-
awsconfig.WithRetryer(func() aws.Retryer {
78-
return retry.AddWithMaxAttempts(retry.NewStandard(), 5)
79-
}),
80-
awsconfig.WithRegion(region),
81-
)
82-
if err != nil {
83-
return nil, fmt.Errorf("failed to load default aws config for STS client: %w", err)
84-
}
85-
8674
awsOptions := []func(*awsconfig.LoadOptions) error{
8775
awsconfig.WithClientLogMode(aws.LogRetries),
8876
awslog.WithAWSLogger(),
8977
awsconfig.WithRetryer(func() aws.Retryer {
9078
return retry.AddWithMaxAttempts(retry.NewStandard(), 5)
9179
}),
92-
awsconfig.WithAssumeRoleCredentialOptions(func(aro *stscreds.AssumeRoleOptions) {
93-
// Ensure the STS client has a region configured, if discovered by IMDS
94-
aro.Client = sts.NewFromConfig(stsCfg)
95-
}),
9680
}
9781

9882
if imdsClient != nil {
99-
awsOptions = append(awsOptions, awsconfig.WithEC2IMDSRegion(func(o *awsconfig.UseEC2IMDSRegion) {
100-
o.Client = imdsClient
101-
}))
83+
stsCfg, err := awsconfig.LoadDefaultConfig(ctx,
84+
awsconfig.WithClientLogMode(aws.LogRetries),
85+
awslog.WithAWSLogger(),
86+
awsconfig.WithRetryer(func() aws.Retryer {
87+
return retry.AddWithMaxAttempts(retry.NewStandard(), 5)
88+
}),
89+
awsconfig.WithRegion(region),
90+
)
91+
if err != nil {
92+
return nil, fmt.Errorf("failed to load default aws config for STS client: %w", err)
93+
}
94+
95+
awsOptions = append(
96+
awsOptions,
97+
awsconfig.WithEC2IMDSRegion(func(o *awsconfig.UseEC2IMDSRegion) {
98+
o.Client = imdsClient
99+
}),
100+
awsconfig.WithAssumeRoleCredentialOptions(func(aro *stscreds.AssumeRoleOptions) {
101+
// Ensure the STS client has a region configured, if discovered by IMDS
102+
aro.Client = sts.NewFromConfig(stsCfg)
103+
}),
104+
)
102105
}
103106

104107
cfg, err := awsconfig.LoadDefaultConfig(ctx, awsOptions...)

0 commit comments

Comments
 (0)