dynamodb-local Add `dynamodb_endpoint` allowing to change the DynamoDB Endpoint for

example to connect to dynamodb-local
This commit is contained in:
Pablo Cantero 2015-07-22 18:57:29 -03:00
parent a4cbef0523
commit 35201e730e
2 changed files with 26 additions and 7 deletions

View File

@ -35,6 +35,8 @@ type Config struct {
AllowedAccountIds []interface{} AllowedAccountIds []interface{}
ForbiddenAccountIds []interface{} ForbiddenAccountIds []interface{}
DynamoDBEndpoint string
} }
type AWSClient struct { type AWSClient struct {
@ -56,7 +58,7 @@ type AWSClient struct {
lambdaconn *lambda.Lambda 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) { func (c *Config) Client() (interface{}, error) {
var client AWSClient var client AWSClient
@ -84,9 +86,15 @@ func (c *Config) Client() (interface{}, error) {
Region: c.Region, Region: c.Region,
MaxRetries: c.MaxRetries, MaxRetries: c.MaxRetries,
} }
awsDynamoDBConfig := &aws.Config{
Credentials: creds,
Region: c.Region,
MaxRetries: c.MaxRetries,
Endpoint: c.DynamoDBEndpoint,
}
log.Println("[INFO] Initializing DynamoDB connection") log.Println("[INFO] Initializing DynamoDB connection")
client.dynamodbconn = dynamodb.New(awsConfig) client.dynamodbconn = dynamodb.New(awsDynamoDBConfig)
log.Println("[INFO] Initializing ELB connection") log.Println("[INFO] Initializing ELB connection")
client.elbconn = elb.New(awsConfig) client.elbconn = elb.New(awsConfig)

View File

@ -145,6 +145,13 @@ func Provider() terraform.ResourceProvider {
return hashcode.String(v.(string)) return hashcode.String(v.(string))
}, },
}, },
"dynamodb_endpoint": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "",
Description: descriptions["dynamodb_endpoint"],
},
}, },
ResourcesMap: map[string]*schema.Resource{ ResourcesMap: map[string]*schema.Resource{
@ -242,16 +249,20 @@ func init() {
"max_retries": "The maximum number of times an AWS API request is\n" + "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" + "being executed. If the API request still fails, an error is\n" +
"thrown.", "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) { func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config := Config{ config := Config{
AccessKey: d.Get("access_key").(string), AccessKey: d.Get("access_key").(string),
SecretKey: d.Get("secret_key").(string), SecretKey: d.Get("secret_key").(string),
Token: d.Get("token").(string), Token: d.Get("token").(string),
Region: d.Get("region").(string), Region: d.Get("region").(string),
MaxRetries: d.Get("max_retries").(int), MaxRetries: d.Get("max_retries").(int),
DynamoDBEndpoint: d.Get("dynamodb_endpoint").(string),
} }
if v, ok := d.GetOk("allowed_account_ids"); ok { if v, ok := d.GetOk("allowed_account_ids"); ok {