11package eks
22
33import (
4+ "os"
45 "sync"
56
67 "github.com/aws/aws-sdk-go-v2/aws"
@@ -14,6 +15,7 @@ import (
1415 "github.com/aws/aws-sdk-go-v2/service/outposts"
1516 "github.com/aws/aws-sdk-go-v2/service/ssm"
1617 "github.com/aws/aws-sdk-go-v2/service/sts"
18+ "github.com/kris-nova/logger"
1719
1820 api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5"
1921 "github.com/weaveworks/eksctl/pkg/awsapi"
@@ -45,6 +47,7 @@ func (s *ServicesV2) STS() awsapi.STS {
4547 defer s .mu .Unlock ()
4648 if s .sts == nil {
4749 s .sts = sts .NewFromConfig (s .config , func (o * sts.Options ) {
50+ o .BaseEndpoint = getBaseEndpoint (sts .ServiceID , "AWS_STS_ENDPOINT" )
4851 // Disable retryer for STS
4952 // (see https://github.com/eksctl-io/eksctl/issues/705)
5053 o .Retryer = aws.NopRetryer {}
@@ -75,6 +78,7 @@ func (s *ServicesV2) CloudFormation() awsapi.CloudFormation {
7578 defer s .mu .Unlock ()
7679 if s .cloudformation == nil {
7780 s .cloudformation = cloudformation .NewFromConfig (s .config , func (o * cloudformation.Options ) {
81+ o .BaseEndpoint = getBaseEndpoint (cloudformation .ServiceID , "AWS_CLOUDFORMATION_ENDPOINT" )
7882 // Use adaptive mode for retrying CloudFormation requests to mimic
7983 // the logic used for AWS SDK v1.
8084 o .Retryer = retry .NewAdaptiveMode (func (o * retry.AdaptiveModeOptions ) {
@@ -94,7 +98,9 @@ func (s *ServicesV2) ELB() awsapi.ELB {
9498 s .mu .Lock ()
9599 defer s .mu .Unlock ()
96100 if s .elasticloadbalancing == nil {
97- s .elasticloadbalancing = elasticloadbalancing .NewFromConfig (s .config )
101+ s .elasticloadbalancing = elasticloadbalancing .NewFromConfig (s .config , func (o * elasticloadbalancing.Options ) {
102+ o .BaseEndpoint = getBaseEndpoint (elasticloadbalancing .ServiceID , "AWS_ELB_ENDPOINT" )
103+ })
98104 }
99105 return s .elasticloadbalancing
100106}
@@ -104,7 +110,9 @@ func (s *ServicesV2) ELBV2() awsapi.ELBV2 {
104110 s .mu .Lock ()
105111 defer s .mu .Unlock ()
106112 if s .elasticloadbalancingV2 == nil {
107- s .elasticloadbalancingV2 = elasticloadbalancingv2 .NewFromConfig (s .config )
113+ s .elasticloadbalancingV2 = elasticloadbalancingv2 .NewFromConfig (s .config , func (o * elasticloadbalancingv2.Options ) {
114+ o .BaseEndpoint = getBaseEndpoint (elasticloadbalancingv2 .ServiceID , "AWS_ELBV2_ENDPOINT" )
115+ })
108116 }
109117 return s .elasticloadbalancingV2
110118}
@@ -124,7 +132,9 @@ func (s *ServicesV2) IAM() awsapi.IAM {
124132 s .mu .Lock ()
125133 defer s .mu .Unlock ()
126134 if s .iam == nil {
127- s .iam = iam .NewFromConfig (s .config )
135+ s .iam = iam .NewFromConfig (s .config , func (o * iam.Options ) {
136+ o .BaseEndpoint = getBaseEndpoint (iam .ServiceID , "AWS_IAM_ENDPOINT" )
137+ })
128138 }
129139 return s .iam
130140}
@@ -134,7 +144,9 @@ func (s *ServicesV2) EC2() awsapi.EC2 {
134144 s .mu .Lock ()
135145 defer s .mu .Unlock ()
136146 if s .ec2 == nil {
137- s .ec2 = ec2 .NewFromConfig (s .config )
147+ s .ec2 = ec2 .NewFromConfig (s .config , func (o * ec2.Options ) {
148+ o .BaseEndpoint = getBaseEndpoint (ec2 .ServiceID , "AWS_EC2_ENDPOINT" )
149+ })
138150 }
139151 return s .ec2
140152}
@@ -144,7 +156,9 @@ func (s *ServicesV2) EKS() awsapi.EKS {
144156 s .mu .Lock ()
145157 defer s .mu .Unlock ()
146158 if s .eks == nil {
147- s .eks = eks .NewFromConfig (s .config )
159+ s .eks = eks .NewFromConfig (s .config , func (o * eks.Options ) {
160+ o .BaseEndpoint = getBaseEndpoint (eks .ServiceID , "AWS_EKS_ENDPOINT" )
161+ })
148162 }
149163 return s .eks
150164}
@@ -166,3 +180,12 @@ func (s *ServicesV2) AWSConfig() aws.Config {
166180func (s * ServicesV2 ) CredentialsProvider () aws.CredentialsProvider {
167181 return s .config .Credentials
168182}
183+
184+ func getBaseEndpoint (serviceID , endpoint string ) * string {
185+ if endpoint , ok := os .LookupEnv (endpoint ); ok {
186+ logger .Debug (
187+ "Setting %s endpoint to %s" , serviceID , endpoint )
188+ return aws .String (endpoint )
189+ }
190+ return nil
191+ }
0 commit comments