From 35201e730eb5dae91bc3b1a72c0efd02727edae0 Mon Sep 17 00:00:00 2001 From: Pablo Cantero Date: Wed, 22 Jul 2015 18:57:29 -0300 Subject: [PATCH 1/4] dynamodb-local Add `dynamodb_endpoint` allowing to change the DynamoDB Endpoint for example to connect to dynamodb-local --- builtin/providers/aws/config.go | 12 ++++++++++-- builtin/providers/aws/provider.go | 21 ++++++++++++++++----- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/builtin/providers/aws/config.go b/builtin/providers/aws/config.go index bc465394cc..437a0b8b12 100644 --- a/builtin/providers/aws/config.go +++ b/builtin/providers/aws/config.go @@ -35,6 +35,8 @@ type Config struct { AllowedAccountIds []interface{} ForbiddenAccountIds []interface{} + + DynamoDBEndpoint string } type AWSClient struct { @@ -56,7 +58,7 @@ type AWSClient struct { lambdaconn *lambda.Lambda } -// Client configures and returns a fully initailized AWSClient +// Client configures and returns a fully initialized AWSClient func (c *Config) Client() (interface{}, error) { var client AWSClient @@ -84,9 +86,15 @@ func (c *Config) Client() (interface{}, error) { Region: c.Region, MaxRetries: c.MaxRetries, } + awsDynamoDBConfig := &aws.Config{ + Credentials: creds, + Region: c.Region, + MaxRetries: c.MaxRetries, + Endpoint: c.DynamoDBEndpoint, + } log.Println("[INFO] Initializing DynamoDB connection") - client.dynamodbconn = dynamodb.New(awsConfig) + client.dynamodbconn = dynamodb.New(awsDynamoDBConfig) log.Println("[INFO] Initializing ELB connection") client.elbconn = elb.New(awsConfig) diff --git a/builtin/providers/aws/provider.go b/builtin/providers/aws/provider.go index d6d877187a..058cb85a25 100644 --- a/builtin/providers/aws/provider.go +++ b/builtin/providers/aws/provider.go @@ -145,6 +145,13 @@ func Provider() terraform.ResourceProvider { return hashcode.String(v.(string)) }, }, + + "dynamodb_endpoint": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Default: "", + Description: descriptions["dynamodb_endpoint"], + }, }, ResourcesMap: map[string]*schema.Resource{ @@ -242,16 +249,20 @@ func init() { "max_retries": "The maximum number of times an AWS API request is\n" + "being executed. If the API request still fails, an error is\n" + "thrown.", + + "dynamodb_endpoint": "Use this to override the default endpoint URL constructed from the :region.\n" + + "It's typically used to connect to dynamodb-local.", } } func providerConfigure(d *schema.ResourceData) (interface{}, error) { config := Config{ - AccessKey: d.Get("access_key").(string), - SecretKey: d.Get("secret_key").(string), - Token: d.Get("token").(string), - Region: d.Get("region").(string), - MaxRetries: d.Get("max_retries").(int), + AccessKey: d.Get("access_key").(string), + SecretKey: d.Get("secret_key").(string), + Token: d.Get("token").(string), + Region: d.Get("region").(string), + MaxRetries: d.Get("max_retries").(int), + DynamoDBEndpoint: d.Get("dynamodb_endpoint").(string), } if v, ok := d.GetOk("allowed_account_ids"); ok { From 2f6d20837f0bc092c4d2980d1a9aaeab0b088a51 Mon Sep 17 00:00:00 2001 From: Pablo Cantero Date: Wed, 29 Jul 2015 13:28:22 -0300 Subject: [PATCH 2/4] dynamodb-local Update aws provider docs to include the `dynamodb_endpoint` argument --- website/source/docs/providers/aws/index.html.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/website/source/docs/providers/aws/index.html.markdown b/website/source/docs/providers/aws/index.html.markdown index 9e8c43d4cc..00db319350 100644 --- a/website/source/docs/providers/aws/index.html.markdown +++ b/website/source/docs/providers/aws/index.html.markdown @@ -55,5 +55,7 @@ The following arguments are supported in the `provider` block: to prevent you mistakenly using a wrong one (and end up destroying live environment). Conflicts with `allowed_account_ids`. +* `dynamodb_endpoint` - (Optional) Use this to override the default endpoint URL constructed from the `region`. It's typically used to connect to dynamodb-local. + In addition to the above parameters, the `AWS_SECURITY_TOKEN` environmental variable can be set to set an MFA token. From 75492513ec7beeedb72e73dd51bd567f10ae5a59 Mon Sep 17 00:00:00 2001 From: Pablo Cantero Date: Wed, 29 Jul 2015 13:36:02 -0300 Subject: [PATCH 3/4] dynamodb-local Use ` instead of : to refer region to keep the consistency with the provider docs --- builtin/providers/aws/provider.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/providers/aws/provider.go b/builtin/providers/aws/provider.go index 058cb85a25..fc9a558742 100644 --- a/builtin/providers/aws/provider.go +++ b/builtin/providers/aws/provider.go @@ -250,7 +250,7 @@ func init() { "being executed. If the API request still fails, an error is\n" + "thrown.", - "dynamodb_endpoint": "Use this to override the default endpoint URL constructed from the :region.\n" + + "dynamodb_endpoint": "Use this to override the default endpoint URL constructed from the `region`.\n" + "It's typically used to connect to dynamodb-local.", } } From 5930f22974a87d4de40e4ddd2bebc223cf802bc7 Mon Sep 17 00:00:00 2001 From: Pablo Cantero Date: Thu, 30 Jul 2015 12:21:03 -0300 Subject: [PATCH 4/4] dynamodb-local Update AWS config https://github.com/hashicorp/terraform/pull/2825#issuecomment-126353610 Tks @catsby --- builtin/providers/aws/config.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/builtin/providers/aws/config.go b/builtin/providers/aws/config.go index 560e552637..c99a66c523 100644 --- a/builtin/providers/aws/config.go +++ b/builtin/providers/aws/config.go @@ -95,11 +95,12 @@ func (c *Config) Client() (interface{}, error) { if err != nil { errs = append(errs, err) } + awsDynamoDBConfig := &aws.Config{ Credentials: creds, - Region: c.Region, - MaxRetries: c.MaxRetries, - Endpoint: c.DynamoDBEndpoint, + Region: aws.String(c.Region), + MaxRetries: aws.Int(c.MaxRetries), + Endpoint: aws.String(c.DynamoDBEndpoint), } log.Println("[INFO] Initializing DynamoDB connection")