provider/aws: Convert RDS DB Parameter group to aws-sdk-go
This commit is contained in:
parent
c52ee17e77
commit
242cdc7a29
|
@ -9,7 +9,9 @@ import (
|
|||
"github.com/hashicorp/terraform/helper/hashcode"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"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 {
|
||||
|
@ -70,12 +72,12 @@ func resourceAwsDbParameterGroup() *schema.Resource {
|
|||
}
|
||||
|
||||
func resourceAwsDbParameterGroupCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
rdsconn := meta.(*AWSClient).rdsconn
|
||||
rdsconn := meta.(*AWSClient).awsRDSconn
|
||||
|
||||
createOpts := rds.CreateDBParameterGroup{
|
||||
DBParameterGroupName: d.Get("name").(string),
|
||||
DBParameterGroupFamily: d.Get("family").(string),
|
||||
Description: d.Get("description").(string),
|
||||
createOpts := rds.CreateDBParameterGroupMessage{
|
||||
DBParameterGroupName: aws.String(d.Get("name").(string)),
|
||||
DBParameterGroupFamily: aws.String(d.Get("family").(string)),
|
||||
Description: aws.String(d.Get("description").(string)),
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] Create DB Parameter Group: %#v", createOpts)
|
||||
|
@ -90,17 +92,17 @@ func resourceAwsDbParameterGroupCreate(d *schema.ResourceData, meta interface{})
|
|||
d.SetPartial("description")
|
||||
d.Partial(false)
|
||||
|
||||
d.SetId(createOpts.DBParameterGroupName)
|
||||
d.SetId(*createOpts.DBParameterGroupName)
|
||||
log.Printf("[INFO] DB Parameter Group ID: %s", d.Id())
|
||||
|
||||
return resourceAwsDbParameterGroupUpdate(d, meta)
|
||||
}
|
||||
|
||||
func resourceAwsDbParameterGroupRead(d *schema.ResourceData, meta interface{}) error {
|
||||
rdsconn := meta.(*AWSClient).rdsconn
|
||||
rdsconn := meta.(*AWSClient).awsRDSconn
|
||||
|
||||
describeOpts := rds.DescribeDBParameterGroups{
|
||||
DBParameterGroupName: d.Id(),
|
||||
describeOpts := rds.DescribeDBParameterGroupsMessage{
|
||||
DBParameterGroupName: aws.String(d.Id()),
|
||||
}
|
||||
|
||||
describeResp, err := rdsconn.DescribeDBParameterGroups(&describeOpts)
|
||||
|
@ -109,7 +111,7 @@ func resourceAwsDbParameterGroupRead(d *schema.ResourceData, meta interface{}) e
|
|||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -118,9 +120,9 @@ func resourceAwsDbParameterGroupRead(d *schema.ResourceData, meta interface{}) e
|
|||
d.Set("description", describeResp.DBParameterGroups[0].Description)
|
||||
|
||||
// Only include user customized parameters as there's hundreds of system/default ones
|
||||
describeParametersOpts := rds.DescribeDBParameters{
|
||||
DBParameterGroupName: d.Id(),
|
||||
Source: "user",
|
||||
describeParametersOpts := rds.DescribeDBParametersMessage{
|
||||
DBParameterGroupName: aws.String(d.Id()),
|
||||
Source: aws.String("user"),
|
||||
}
|
||||
|
||||
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 {
|
||||
rdsconn := meta.(*AWSClient).rdsconn
|
||||
rdsconn := meta.(*AWSClient).awsRDSconn
|
||||
|
||||
d.Partial(true)
|
||||
|
||||
|
@ -157,8 +159,8 @@ func resourceAwsDbParameterGroupUpdate(d *schema.ResourceData, meta interface{})
|
|||
}
|
||||
|
||||
if len(parameters) > 0 {
|
||||
modifyOpts := rds.ModifyDBParameterGroup{
|
||||
DBParameterGroupName: d.Get("name").(string),
|
||||
modifyOpts := rds.ModifyDBParameterGroupMessage{
|
||||
DBParameterGroupName: aws.String(d.Get("name").(string)),
|
||||
Parameters: parameters,
|
||||
}
|
||||
|
||||
|
@ -191,16 +193,16 @@ func resourceAwsDbParameterGroupDelete(d *schema.ResourceData, meta interface{})
|
|||
func resourceAwsDbParameterGroupDeleteRefreshFunc(
|
||||
d *schema.ResourceData,
|
||||
meta interface{}) resource.StateRefreshFunc {
|
||||
rdsconn := meta.(*AWSClient).rdsconn
|
||||
rdsconn := meta.(*AWSClient).awsRDSconn
|
||||
|
||||
return func() (interface{}, string, error) {
|
||||
|
||||
deleteOpts := rds.DeleteDBParameterGroup{
|
||||
DBParameterGroupName: d.Id(),
|
||||
deleteOpts := rds.DeleteDBParameterGroupMessage{
|
||||
DBParameterGroupName: aws.String(d.Id()),
|
||||
}
|
||||
|
||||
if _, err := rdsconn.DeleteDBParameterGroup(&deleteOpts); err != nil {
|
||||
rdserr, ok := err.(*rds.Error)
|
||||
if err := rdsconn.DeleteDBParameterGroup(&deleteOpts); err != nil {
|
||||
rdserr, ok := err.(aws.APIError)
|
||||
if !ok {
|
||||
return d, "error", err
|
||||
}
|
||||
|
|
|
@ -3,10 +3,11 @@ package aws
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/aws-sdk-go/aws"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/rds"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/mitchellh/goamz/ec2"
|
||||
"github.com/mitchellh/goamz/elb"
|
||||
"github.com/mitchellh/goamz/rds"
|
||||
)
|
||||
|
||||
// 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{})
|
||||
|
||||
p := rds.Parameter{
|
||||
ApplyMethod: data["apply_method"].(string),
|
||||
ParameterName: data["name"].(string),
|
||||
ParameterValue: data["value"].(string),
|
||||
ApplyMethod: aws.String(data["apply_method"].(string)),
|
||||
ParameterName: aws.String(data["name"].(string)),
|
||||
ParameterValue: aws.String(data["value"].(string)),
|
||||
}
|
||||
|
||||
parameters = append(parameters, p)
|
||||
|
@ -190,8 +191,8 @@ func flattenParameters(list []rds.Parameter) []map[string]interface{} {
|
|||
result := make([]map[string]interface{}, 0, len(list))
|
||||
for _, i := range list {
|
||||
result = append(result, map[string]interface{}{
|
||||
"name": strings.ToLower(i.ParameterName),
|
||||
"value": strings.ToLower(i.ParameterValue),
|
||||
"name": strings.ToLower(*i.ParameterName),
|
||||
"value": strings.ToLower(*i.ParameterValue),
|
||||
})
|
||||
}
|
||||
return result
|
||||
|
|
|
@ -4,12 +4,13 @@ import (
|
|||
"reflect"
|
||||
"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/helper/hashcode"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/mitchellh/goamz/ec2"
|
||||
"github.com/mitchellh/goamz/elb"
|
||||
"github.com/mitchellh/goamz/rds"
|
||||
)
|
||||
|
||||
// Returns test configuration
|
||||
|
@ -270,9 +271,9 @@ func Test_expandParameters(t *testing.T) {
|
|||
}
|
||||
|
||||
expected := rds.Parameter{
|
||||
ParameterName: "character_set_client",
|
||||
ParameterValue: "utf8",
|
||||
ApplyMethod: "immediate",
|
||||
ParameterName: aws.String("character_set_client"),
|
||||
ParameterValue: aws.String("utf8"),
|
||||
ApplyMethod: aws.String("immediate"),
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(parameters[0], expected) {
|
||||
|
@ -291,8 +292,8 @@ func Test_flattenParameters(t *testing.T) {
|
|||
{
|
||||
Input: []rds.Parameter{
|
||||
rds.Parameter{
|
||||
ParameterName: "character_set_client",
|
||||
ParameterValue: "utf8",
|
||||
ParameterName: aws.String("character_set_client"),
|
||||
ParameterValue: aws.String("utf8"),
|
||||
},
|
||||
},
|
||||
Output: []map[string]interface{}{
|
||||
|
|
Loading…
Reference in New Issue