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

Config: Allow API Gateway and Lambda endpoints configuration #2641

Merged
merged 1 commit into from
Dec 22, 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
8 changes: 6 additions & 2 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{}

ApigatewayEndpoint string
CloudFormationEndpoint string
CloudWatchEndpoint string
CloudWatchEventsEndpoint string
Expand All @@ -111,6 +112,7 @@ type Config struct {
IamEndpoint string
KinesisEndpoint string
KmsEndpoint string
LambdaEndpoint string
RdsEndpoint string
S3Endpoint string
SnsEndpoint string
Expand Down Expand Up @@ -318,6 +320,7 @@ func (c *Config) Client() (interface{}, error) {
r53Sess := sess.Copy(&aws.Config{Region: aws.String("us-east-1")})

// Some services have user-configurable endpoints
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)})
Expand All @@ -326,6 +329,7 @@ func (c *Config) Client() (interface{}, error) {
awsEc2Sess := sess.Copy(&aws.Config{Endpoint: aws.String(c.Ec2Endpoint)})
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)})
awsKinesisSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.KinesisEndpoint)})
awsKmsSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.KmsEndpoint)})
awsRdsSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.RdsEndpoint)})
Expand Down Expand Up @@ -375,7 +379,7 @@ func (c *Config) Client() (interface{}, error) {
}

client.acmconn = acm.New(sess)
client.apigateway = apigateway.New(sess)
client.apigateway = apigateway.New(awsApigatewaySess)
client.appautoscalingconn = applicationautoscaling.New(sess)
client.autoscalingconn = autoscaling.New(sess)
client.cfconn = cloudformation.New(awsCfSess)
Expand Down Expand Up @@ -410,7 +414,7 @@ func (c *Config) Client() (interface{}, error) {
client.iotconn = iot.New(sess)
client.kinesisconn = kinesis.New(awsKinesisSess)
client.kmsconn = kms.New(awsKmsSess)
client.lambdaconn = lambda.New(sess)
client.lambdaconn = lambda.New(awsLambdaSess)
client.lightsailconn = lightsail.New(sess)
client.mqconn = mq.New(sess)
client.opsworksconn = opsworks.New(sess)
Expand Down
20 changes: 20 additions & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ func init() {
"being executed. If the API request still fails, an error is\n" +
"thrown.",

"apigateway_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",

"cloudformation_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",

"cloudwatch_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",
Expand All @@ -583,6 +585,8 @@ func init() {

"iam_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",

"lambda_endpoint": "Use this to override the default endpoint URL constructed from the `region`\n",

"ec2_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",

"elb_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n",
Expand Down Expand Up @@ -677,6 +681,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {

for _, endpointsSetI := range endpointsSet.List() {
endpoints := endpointsSetI.(map[string]interface{})
config.ApigatewayEndpoint = endpoints["apigateway"].(string)
config.CloudFormationEndpoint = endpoints["cloudformation"].(string)
config.CloudWatchEndpoint = endpoints["cloudwatch"].(string)
config.CloudWatchEventsEndpoint = endpoints["cloudwatchevents"].(string)
Expand All @@ -688,6 +693,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config.IamEndpoint = endpoints["iam"].(string)
config.KinesisEndpoint = endpoints["kinesis"].(string)
config.KmsEndpoint = endpoints["kms"].(string)
config.LambdaEndpoint = endpoints["lambda"].(string)
config.RdsEndpoint = endpoints["rds"].(string)
config.S3Endpoint = endpoints["s3"].(string)
config.SnsEndpoint = endpoints["sns"].(string)
Expand Down Expand Up @@ -749,6 +755,12 @@ func endpointsSchema() *schema.Schema {
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"apigateway": {
Type: schema.TypeString,
Optional: true,
Default: "",
Description: descriptions["apigateway_endpoint"],
},
"cloudwatch": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -817,6 +829,12 @@ func endpointsSchema() *schema.Schema {
Default: "",
Description: descriptions["kms_endpoint"],
},
"lambda": {
Type: schema.TypeString,
Optional: true,
Default: "",
Description: descriptions["lambda_endpoint"],
},
"rds": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -850,6 +868,7 @@ func endpointsSchema() *schema.Schema {
func endpointsToHash(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})
buf.WriteString(fmt.Sprintf("%s-", m["apigateway"].(string)))
buf.WriteString(fmt.Sprintf("%s-", m["cloudwatch"].(string)))
buf.WriteString(fmt.Sprintf("%s-", m["cloudwatchevents"].(string)))
buf.WriteString(fmt.Sprintf("%s-", m["cloudwatchlogs"].(string)))
Expand All @@ -861,6 +880,7 @@ func endpointsToHash(v interface{}) int {
buf.WriteString(fmt.Sprintf("%s-", m["elb"].(string)))
buf.WriteString(fmt.Sprintf("%s-", m["kinesis"].(string)))
buf.WriteString(fmt.Sprintf("%s-", m["kms"].(string)))
buf.WriteString(fmt.Sprintf("%s-", m["lambda"].(string)))
buf.WriteString(fmt.Sprintf("%s-", m["rds"].(string)))
buf.WriteString(fmt.Sprintf("%s-", m["s3"].(string)))
buf.WriteString(fmt.Sprintf("%s-", m["sns"].(string)))
Expand Down