Skip to content

Commit

Permalink
Merge pull request mitchellh#126 from rcostanzo/master
Browse files Browse the repository at this point in the history
Added DBParameterGroupName as an option when creating a database instanc...
  • Loading branch information
mitchellh committed Oct 18, 2014
2 parents db36e88 + 62d44c5 commit 3506bc3
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
31 changes: 31 additions & 0 deletions rds/rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ type DBInstance struct {
VpcSecurityGroupIds []string `xml:"VpcSecurityGroups"`
DBSecurityGroupNames []string `xml:"DBSecurityGroups>DBSecurityGroup>DBSecurityGroupName"`
DBSubnetGroup DBSubnetGroup `xml:"DBSubnetGroup"`
DBParameterGroupName string `xml:"DBParameterGroupName"`
}

type DBSecurityGroup struct {
Expand Down Expand Up @@ -173,6 +174,7 @@ type CreateDBInstance struct {
PubliclyAccessible bool
VpcSecurityGroupIds []string
DBSecurityGroupNames []string
DBParameterGroupName string

SetAllocatedStorage bool
SetBackupRetentionPeriod bool
Expand Down Expand Up @@ -259,6 +261,10 @@ func (rds *Rds) CreateDBInstance(options *CreateDBInstance) (resp *SimpleResp, e
params["DBSecurityGroups.member."+strconv.Itoa(j+1)] = group
}

if options.DBParameterGroupName != "" {
params["DBParameterGroupName"] = options.DBParameterGroupName
}

resp = &SimpleResp{}

err = rds.query(params, resp)
Expand Down Expand Up @@ -362,6 +368,31 @@ func (rds *Rds) AuthorizeDBSecurityGroupIngress(options *AuthorizeDBSecurityGrou
return
}

// The CreateDBParameterGroup request parameters
type CreateDBParameterGroup struct {
DBParameterGroupFamily string
DBParameterGroupName string
Description string
}

func (rds *Rds) CreateDBParameterGroup(options *CreateDBParameterGroup) (resp *SimpleResp, err error) {
params := makeParams("CreateDBParameterGroup")

params["DBParameterGroupFamily"] = options.DBParameterGroupFamily
params["DBParameterGroupName"] = options.DBParameterGroupName
params["Description"] = options.Description

resp = &SimpleResp{}

err = rds.query(params, resp)

if err != nil {
resp = nil
}

return
}

// Describe

// DescribeDBInstances request params
Expand Down
21 changes: 21 additions & 0 deletions rds/rds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (s *S) Test_CreateDBInstance(c *C) {
MasterUserPassword: "bazbarbaz",
DBInstanceClass: "db.m1.small",
DBSecurityGroupNames: []string{"foo", "bar"},
DBParameterGroupName: "default.mysql5.6",

SetBackupRetentionPeriod: true,
}
Expand Down Expand Up @@ -101,6 +102,26 @@ func (s *S) Test_CreateDBSubnetGroup(c *C) {
c.Assert(resp.RequestId, Equals, "3a401b3f-bb9e-11d3-f4c6-37db295f7674")
}

func (s *S) Test_CreateDBParameterGroup(c *C) {
testServer.Response(200, nil, CreateDBParameterGroupExample)

options := rds.CreateDBParameterGroup{
DBParameterGroupFamily: "mysql5.6",
DBParameterGroupName: "mydbparamgroup3",
Description: "My new DB Parameter Group",
}

resp, err := s.rds.CreateDBParameterGroup(&options)
req := testServer.WaitRequest()

c.Assert(req.Form["Action"], DeepEquals, []string{"CreateDBParameterGroup"})
c.Assert(req.Form["DBParameterGroupFamily"], DeepEquals, []string{"mysql5.6"})
c.Assert(req.Form["DBParameterGroupName"], DeepEquals, []string{"mydbparamgroup3"})
c.Assert(req.Form["Description"], DeepEquals, []string{"My new DB Parameter Group"})
c.Assert(err, IsNil)
c.Assert(resp.RequestId, Equals, "7805c127-af22-11c3-96ac-6999cc5f7e72")
}

func (s *S) Test_DescribeDBInstances(c *C) {
testServer.Response(200, nil, DescribeDBInstancesExample)

Expand Down
15 changes: 15 additions & 0 deletions rds/responses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,3 +548,18 @@ var RestoreDBInstanceFromDBSnapshotExample = `
</ResponseMetadata>
</RestoreDBInstanceFromDBSnapshotResponse>
`

var CreateDBParameterGroupExample = `
<CreateDBParameterGroupResponse xmlns="http://rds.amazonaws.com/doc/2014-09-01/">
<CreateDBParameterGroupResult>
<DBParameterGroup>
<DBParameterGroupFamily>mysql5.6</DBParameterGroupFamily>
<Description>My new DB Parameter Group</Description>
<DBParameterGroupName>mydbparamgroup3</DBParameterGroupName>
</DBParameterGroup>
</CreateDBParameterGroupResult>
<ResponseMetadata>
<RequestId>7805c127-af22-11c3-96ac-6999cc5f7e72</RequestId>
</ResponseMetadata>
</CreateDBParameterGroupResponse>
`

0 comments on commit 3506bc3

Please sign in to comment.