provider/aws: Convert RDS DB Parameter group to aws-sdk-go

This commit is contained in:
Clint Shryock 2015-02-26 09:33:33 -06:00
parent c52ee17e77
commit 242cdc7a29
3 changed files with 38 additions and 34 deletions

View File

@ -9,7 +9,9 @@ import (
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/mitchellh/goamz/rds"
"github.com/hashicorp/aws-sdk-go/aws"
"github.com/hashicorp/aws-sdk-go/gen/rds"
) )
func resourceAwsDbParameterGroup() *schema.Resource { func resourceAwsDbParameterGroup() *schema.Resource {
@ -70,12 +72,12 @@ func resourceAwsDbParameterGroup() *schema.Resource {
} }
func resourceAwsDbParameterGroupCreate(d *schema.ResourceData, meta interface{}) error { func resourceAwsDbParameterGroupCreate(d *schema.ResourceData, meta interface{}) error {
rdsconn := meta.(*AWSClient).rdsconn rdsconn := meta.(*AWSClient).awsRDSconn
createOpts := rds.CreateDBParameterGroup{ createOpts := rds.CreateDBParameterGroupMessage{
DBParameterGroupName: d.Get("name").(string), DBParameterGroupName: aws.String(d.Get("name").(string)),
DBParameterGroupFamily: d.Get("family").(string), DBParameterGroupFamily: aws.String(d.Get("family").(string)),
Description: d.Get("description").(string), Description: aws.String(d.Get("description").(string)),
} }
log.Printf("[DEBUG] Create DB Parameter Group: %#v", createOpts) log.Printf("[DEBUG] Create DB Parameter Group: %#v", createOpts)
@ -90,17 +92,17 @@ func resourceAwsDbParameterGroupCreate(d *schema.ResourceData, meta interface{})
d.SetPartial("description") d.SetPartial("description")
d.Partial(false) d.Partial(false)
d.SetId(createOpts.DBParameterGroupName) d.SetId(*createOpts.DBParameterGroupName)
log.Printf("[INFO] DB Parameter Group ID: %s", d.Id()) log.Printf("[INFO] DB Parameter Group ID: %s", d.Id())
return resourceAwsDbParameterGroupUpdate(d, meta) return resourceAwsDbParameterGroupUpdate(d, meta)
} }
func resourceAwsDbParameterGroupRead(d *schema.ResourceData, meta interface{}) error { func resourceAwsDbParameterGroupRead(d *schema.ResourceData, meta interface{}) error {
rdsconn := meta.(*AWSClient).rdsconn rdsconn := meta.(*AWSClient).awsRDSconn
describeOpts := rds.DescribeDBParameterGroups{ describeOpts := rds.DescribeDBParameterGroupsMessage{
DBParameterGroupName: d.Id(), DBParameterGroupName: aws.String(d.Id()),
} }
describeResp, err := rdsconn.DescribeDBParameterGroups(&describeOpts) describeResp, err := rdsconn.DescribeDBParameterGroups(&describeOpts)
@ -109,7 +111,7 @@ func resourceAwsDbParameterGroupRead(d *schema.ResourceData, meta interface{}) e
} }
if len(describeResp.DBParameterGroups) != 1 || if len(describeResp.DBParameterGroups) != 1 ||
describeResp.DBParameterGroups[0].DBParameterGroupName != d.Id() { *describeResp.DBParameterGroups[0].DBParameterGroupName != d.Id() {
return fmt.Errorf("Unable to find Parameter Group: %#v", describeResp.DBParameterGroups) return fmt.Errorf("Unable to find Parameter Group: %#v", describeResp.DBParameterGroups)
} }
@ -118,9 +120,9 @@ func resourceAwsDbParameterGroupRead(d *schema.ResourceData, meta interface{}) e
d.Set("description", describeResp.DBParameterGroups[0].Description) d.Set("description", describeResp.DBParameterGroups[0].Description)
// Only include user customized parameters as there's hundreds of system/default ones // Only include user customized parameters as there's hundreds of system/default ones
describeParametersOpts := rds.DescribeDBParameters{ describeParametersOpts := rds.DescribeDBParametersMessage{
DBParameterGroupName: d.Id(), DBParameterGroupName: aws.String(d.Id()),
Source: "user", Source: aws.String("user"),
} }
describeParametersResp, err := rdsconn.DescribeDBParameters(&describeParametersOpts) describeParametersResp, err := rdsconn.DescribeDBParameters(&describeParametersOpts)
@ -134,7 +136,7 @@ func resourceAwsDbParameterGroupRead(d *schema.ResourceData, meta interface{}) e
} }
func resourceAwsDbParameterGroupUpdate(d *schema.ResourceData, meta interface{}) error { func resourceAwsDbParameterGroupUpdate(d *schema.ResourceData, meta interface{}) error {
rdsconn := meta.(*AWSClient).rdsconn rdsconn := meta.(*AWSClient).awsRDSconn
d.Partial(true) d.Partial(true)
@ -157,8 +159,8 @@ func resourceAwsDbParameterGroupUpdate(d *schema.ResourceData, meta interface{})
} }
if len(parameters) > 0 { if len(parameters) > 0 {
modifyOpts := rds.ModifyDBParameterGroup{ modifyOpts := rds.ModifyDBParameterGroupMessage{
DBParameterGroupName: d.Get("name").(string), DBParameterGroupName: aws.String(d.Get("name").(string)),
Parameters: parameters, Parameters: parameters,
} }
@ -191,16 +193,16 @@ func resourceAwsDbParameterGroupDelete(d *schema.ResourceData, meta interface{})
func resourceAwsDbParameterGroupDeleteRefreshFunc( func resourceAwsDbParameterGroupDeleteRefreshFunc(
d *schema.ResourceData, d *schema.ResourceData,
meta interface{}) resource.StateRefreshFunc { meta interface{}) resource.StateRefreshFunc {
rdsconn := meta.(*AWSClient).rdsconn rdsconn := meta.(*AWSClient).awsRDSconn
return func() (interface{}, string, error) { return func() (interface{}, string, error) {
deleteOpts := rds.DeleteDBParameterGroup{ deleteOpts := rds.DeleteDBParameterGroupMessage{
DBParameterGroupName: d.Id(), DBParameterGroupName: aws.String(d.Id()),
} }
if _, err := rdsconn.DeleteDBParameterGroup(&deleteOpts); err != nil { if err := rdsconn.DeleteDBParameterGroup(&deleteOpts); err != nil {
rdserr, ok := err.(*rds.Error) rdserr, ok := err.(aws.APIError)
if !ok { if !ok {
return d, "error", err return d, "error", err
} }

View File

@ -3,10 +3,11 @@ package aws
import ( import (
"strings" "strings"
"github.com/hashicorp/aws-sdk-go/aws"
"github.com/hashicorp/aws-sdk-go/gen/rds"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/mitchellh/goamz/ec2" "github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/goamz/elb" "github.com/mitchellh/goamz/elb"
"github.com/mitchellh/goamz/rds"
) )
// Takes the result of flatmap.Expand for an array of listeners and // Takes the result of flatmap.Expand for an array of listeners and
@ -99,9 +100,9 @@ func expandParameters(configured []interface{}) ([]rds.Parameter, error) {
data := pRaw.(map[string]interface{}) data := pRaw.(map[string]interface{})
p := rds.Parameter{ p := rds.Parameter{
ApplyMethod: data["apply_method"].(string), ApplyMethod: aws.String(data["apply_method"].(string)),
ParameterName: data["name"].(string), ParameterName: aws.String(data["name"].(string)),
ParameterValue: data["value"].(string), ParameterValue: aws.String(data["value"].(string)),
} }
parameters = append(parameters, p) parameters = append(parameters, p)
@ -190,8 +191,8 @@ func flattenParameters(list []rds.Parameter) []map[string]interface{} {
result := make([]map[string]interface{}, 0, len(list)) result := make([]map[string]interface{}, 0, len(list))
for _, i := range list { for _, i := range list {
result = append(result, map[string]interface{}{ result = append(result, map[string]interface{}{
"name": strings.ToLower(i.ParameterName), "name": strings.ToLower(*i.ParameterName),
"value": strings.ToLower(i.ParameterValue), "value": strings.ToLower(*i.ParameterValue),
}) })
} }
return result return result

View File

@ -4,12 +4,13 @@ import (
"reflect" "reflect"
"testing" "testing"
"github.com/hashicorp/aws-sdk-go/aws"
"github.com/hashicorp/aws-sdk-go/gen/rds"
"github.com/hashicorp/terraform/flatmap" "github.com/hashicorp/terraform/flatmap"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/mitchellh/goamz/ec2" "github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/goamz/elb" "github.com/mitchellh/goamz/elb"
"github.com/mitchellh/goamz/rds"
) )
// Returns test configuration // Returns test configuration
@ -270,9 +271,9 @@ func Test_expandParameters(t *testing.T) {
} }
expected := rds.Parameter{ expected := rds.Parameter{
ParameterName: "character_set_client", ParameterName: aws.String("character_set_client"),
ParameterValue: "utf8", ParameterValue: aws.String("utf8"),
ApplyMethod: "immediate", ApplyMethod: aws.String("immediate"),
} }
if !reflect.DeepEqual(parameters[0], expected) { if !reflect.DeepEqual(parameters[0], expected) {
@ -291,8 +292,8 @@ func Test_flattenParameters(t *testing.T) {
{ {
Input: []rds.Parameter{ Input: []rds.Parameter{
rds.Parameter{ rds.Parameter{
ParameterName: "character_set_client", ParameterName: aws.String("character_set_client"),
ParameterValue: "utf8", ParameterValue: aws.String("utf8"),
}, },
}, },
Output: []map[string]interface{}{ Output: []map[string]interface{}{