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

allow setting endpoints for acm,ecr,ecs,sts,r53 #2795

Merged
merged 1 commit into from
Dec 29, 2017
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
19 changes: 14 additions & 5 deletions aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ type Config struct {
AllowedAccountIds []interface{}
ForbiddenAccountIds []interface{}

AcmEndpoint string
ApigatewayEndpoint string
CloudFormationEndpoint string
CloudWatchEndpoint string
Expand All @@ -108,15 +109,19 @@ type Config struct {
DynamoDBEndpoint string
DeviceFarmEndpoint string
Ec2Endpoint string
EcsEndpoint string
EcrEndpoint string
ElbEndpoint string
IamEndpoint string
KinesisEndpoint string
KmsEndpoint string
LambdaEndpoint string
RdsEndpoint string
R53Endpoint string
S3Endpoint string
SnsEndpoint string
SqsEndpoint string
StsEndpoint string
Insecure bool

SkipCredsValidation bool
Expand Down Expand Up @@ -317,16 +322,19 @@ func (c *Config) Client() (interface{}, error) {
// Other resources that have restrictions should allow the API to fail, rather
// than Terraform abstracting the region for the user. This can lead to breaking
// changes if that resource is ever opened up to more regions.
r53Sess := sess.Copy(&aws.Config{Region: aws.String("us-east-1")})
r53Sess := sess.Copy(&aws.Config{Region: aws.String("us-east-1"), Endpoint: aws.String(c.R53Endpoint)})

// Some services have user-configurable endpoints
awsAcmSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.AcmEndpoint)})
awsApigatewaySess := sess.Copy(&aws.Config{Endpoint: aws.String(c.ApigatewayEndpoint)})
awsCfSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.CloudFormationEndpoint)})
awsCwSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.CloudWatchEndpoint)})
awsCweSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.CloudWatchEventsEndpoint)})
awsCwlSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.CloudWatchLogsEndpoint)})
awsDynamoSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.DynamoDBEndpoint)})
awsEc2Sess := sess.Copy(&aws.Config{Endpoint: aws.String(c.Ec2Endpoint)})
awsEcrSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.EcrEndpoint)})
awsEcsSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.EcsEndpoint)})
awsElbSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.ElbEndpoint)})
awsIamSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.IamEndpoint)})
awsLambdaSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.LambdaEndpoint)})
Expand All @@ -336,14 +344,15 @@ func (c *Config) Client() (interface{}, error) {
awsS3Sess := sess.Copy(&aws.Config{Endpoint: aws.String(c.S3Endpoint)})
awsSnsSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.SnsEndpoint)})
awsSqsSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.SqsEndpoint)})
awsStsSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.StsEndpoint)})
awsDeviceFarmSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.DeviceFarmEndpoint)})

log.Println("[INFO] Initializing DeviceFarm SDK connection")
client.devicefarmconn = devicefarm.New(awsDeviceFarmSess)

// These two services need to be set up early so we can check on AccountID
client.iamconn = iam.New(awsIamSess)
client.stsconn = sts.New(sess)
client.stsconn = sts.New(awsStsSess)

if !c.SkipCredsValidation {
err = c.ValidateCredentials(client.stsconn)
Expand Down Expand Up @@ -378,7 +387,7 @@ func (c *Config) Client() (interface{}, error) {
}
}

client.acmconn = acm.New(sess)
client.acmconn = acm.New(awsAcmSess)
client.apigateway = apigateway.New(awsApigatewaySess)
client.appautoscalingconn = applicationautoscaling.New(sess)
client.autoscalingconn = autoscaling.New(sess)
Expand All @@ -398,8 +407,8 @@ func (c *Config) Client() (interface{}, error) {
client.codepipelineconn = codepipeline.New(sess)
client.dsconn = directoryservice.New(sess)
client.dynamodbconn = dynamodb.New(awsDynamoSess)
client.ecrconn = ecr.New(sess)
client.ecsconn = ecs.New(sess)
client.ecrconn = ecr.New(awsEcrSess)
client.ecsconn = ecs.New(awsEcsSess)
client.efsconn = efs.New(sess)
client.elasticacheconn = elasticache.New(sess)
client.elasticbeanstalkconn = elasticbeanstalk.New(sess)
Expand Down
37 changes: 37 additions & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {

for _, endpointsSetI := range endpointsSet.List() {
endpoints := endpointsSetI.(map[string]interface{})
config.AcmEndpoint = endpoints["acm"].(string)
config.ApigatewayEndpoint = endpoints["apigateway"].(string)
config.CloudFormationEndpoint = endpoints["cloudformation"].(string)
config.CloudWatchEndpoint = endpoints["cloudwatch"].(string)
Expand All @@ -690,15 +691,19 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config.DeviceFarmEndpoint = endpoints["devicefarm"].(string)
config.DynamoDBEndpoint = endpoints["dynamodb"].(string)
config.Ec2Endpoint = endpoints["ec2"].(string)
config.EcrEndpoint = endpoints["ecr"].(string)
config.EcsEndpoint = endpoints["ecs"].(string)
config.ElbEndpoint = endpoints["elb"].(string)
config.IamEndpoint = endpoints["iam"].(string)
config.KinesisEndpoint = endpoints["kinesis"].(string)
config.KmsEndpoint = endpoints["kms"].(string)
config.LambdaEndpoint = endpoints["lambda"].(string)
config.R53Endpoint = endpoints["r53"].(string)
config.RdsEndpoint = endpoints["rds"].(string)
config.S3Endpoint = endpoints["s3"].(string)
config.SnsEndpoint = endpoints["sns"].(string)
config.SqsEndpoint = endpoints["sqs"].(string)
config.StsEndpoint = endpoints["sts"].(string)
}

if v, ok := d.GetOk("allowed_account_ids"); ok {
Expand Down Expand Up @@ -756,6 +761,12 @@ func endpointsSchema() *schema.Schema {
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"acm": {
Type: schema.TypeString,
Optional: true,
Default: "",
Description: descriptions["acm_endpoint"],
},
"apigateway": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -812,6 +823,20 @@ func endpointsSchema() *schema.Schema {
Description: descriptions["ec2_endpoint"],
},

"ecr": {
Type: schema.TypeString,
Optional: true,
Default: "",
Description: descriptions["ecr_endpoint"],
},

"ecs": {
Type: schema.TypeString,
Optional: true,
Default: "",
Description: descriptions["ecs_endpoint"],
},

"elb": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -836,6 +861,12 @@ func endpointsSchema() *schema.Schema {
Default: "",
Description: descriptions["lambda_endpoint"],
},
"r53": {
Type: schema.TypeString,
Optional: true,
Default: "",
Description: descriptions["r53_endpoint"],
},
"rds": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -860,6 +891,12 @@ func endpointsSchema() *schema.Schema {
Default: "",
Description: descriptions["sqs_endpoint"],
},
"sts": {
Type: schema.TypeString,
Optional: true,
Default: "",
Description: descriptions["sts_endpoint"],
},
},
},
Set: endpointsToHash,
Expand Down