Adding backup_retention_period, preferred_backup_window and preferred_maintenance_window to RDS Cluster

This commit is contained in:
stack72 2015-11-04 19:40:22 +00:00
parent 9e9d4b2c72
commit 1d0dbc5d19
3 changed files with 72 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt"
"log"
"regexp"
"strings"
"time"
"github.com/aws/aws-sdk-go/aws"
@ -122,6 +123,33 @@ func resourceAwsRDSCluster() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
"preferred_backup_window": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"preferred_maintenance_window": &schema.Schema{
Type: schema.TypeString,
Optional: true,
StateFunc: func(val interface{}) string {
return strings.ToLower(val.(string))
},
},
"backup_retention_period": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Default: 1,
ValidateFunc: func(v interface{}, k string) (ws []string, es []error) {
value := v.(int)
if value > 35 {
es = append(es, fmt.Errorf(
"backup retention period cannot be more than 35 days"))
}
return
},
},
},
}
}
@ -156,6 +184,18 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
createOpts.AvailabilityZones = expandStringList(attr.List())
}
if v, ok := d.GetOk("backup_retention_period"); ok {
createOpts.BackupRetentionPeriod = aws.Int64(int64(v.(int)))
}
if v, ok := d.GetOk("preferred_backup_window"); ok {
createOpts.PreferredBackupWindow = aws.String(v.(string))
}
if v, ok := d.GetOk("preferred_maintenance_window"); ok {
createOpts.PreferredMaintenanceWindow = aws.String(v.(string))
}
log.Printf("[DEBUG] RDS Cluster create options: %s", createOpts)
resp, err := conn.CreateDBCluster(createOpts)
if err != nil {
@ -223,6 +263,9 @@ func resourceAwsRDSClusterRead(d *schema.ResourceData, meta interface{}) error {
d.Set("engine", dbc.Engine)
d.Set("master_username", dbc.MasterUsername)
d.Set("port", dbc.Port)
d.Set("backup_retention_period", dbc.BackupRetentionPeriod)
d.Set("preferred_backup_window", dbc.PreferredBackupWindow)
d.Set("preferred_maintenance_window", dbc.PreferredMaintenanceWindow)
var vpcg []string
for _, g := range dbc.VpcSecurityGroups {
@ -263,6 +306,18 @@ func resourceAwsRDSClusterUpdate(d *schema.ResourceData, meta interface{}) error
}
}
if d.HasChange("preferred_backup_window") {
req.PreferredBackupWindow = aws.String(d.Get("preferred_backup_window").(string))
}
if d.HasChange("preferred_maintaince_window") {
req.PreferredMaintenanceWindow = aws.String(d.Get("preferred_maintaince_window").(string))
}
if d.HasChange("backup_retention_limit") {
req.BackupRetentionPeriod = aws.Int64(int64(d.Get("backup_retention_limit").(int)))
}
_, err := conn.ModifyDBCluster(req)
if err != nil {
return fmt.Errorf("[WARN] Error modifying RDS Cluster (%s): %s", d.Id(), err)

View File

@ -26,6 +26,12 @@ func TestAccAWSRDSCluster_basic(t *testing.T) {
Config: testAccAWSClusterConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterExists("aws_rds_cluster.default", &v),
resource.TestCheckResourceAttr(
"aws_rds_cluster.default", "preferred_backup_window", "07:00-09:00"),
resource.TestCheckResourceAttr(
"aws_rds_cluster.default", "backup_retention_period", "5"),
resource.TestCheckResourceAttr(
"aws_rds_cluster.default", "preferred_maintenance_window", "tue:04:00-tue:04:30"),
),
},
},
@ -105,4 +111,7 @@ resource "aws_rds_cluster" "default" {
database_name = "mydb"
master_username = "foo"
master_password = "mustbeeightcharaters"
backup_retention_period = 5
preferred_backup_window = "07:00-09:00"
preferred_maintenance_window = "tue:04:00-tue:04:30"
}`, rand.New(rand.NewSource(time.Now().UnixNano())).Int())

View File

@ -24,6 +24,8 @@ resource "aws_rds_cluster" "default" {
database_name = "mydb"
master_username = "foo"
master_password = "bar"
backup_retention_period = 5
preferred_backup_window = "07:00-09:00"
}
```
@ -52,6 +54,9 @@ string.
instances in the DB cluster can be created in
* `backup_retention_period` - (Optional) The days to retain backups for. Default
1
* `preferred_backup_window` - (Optional) The daily time range during which automated backups are created if automated backups are enabled using the BackupRetentionPeriod parameter.
Default: A 30-minute window selected at random from an 8-hour block of time per region. e.g. 04:00-09:00
* `preferred_maintenance_window` - (Optional) The weekly time range during which system maintenance can occur, in (UTC) e.g. wed:04:00-wed:04:30
* `port` - (Optional) The port on which the DB accepts connections
* `vpc_security_group_ids` - (Optional) List of VPC security groups to associate
with the Cluster
@ -70,7 +75,8 @@ The following attributes are exported:
* `allocated_storage` - The amount of allocated storage
* `availability_zones` - The availability zone of the instance
* `backup_retention_period` - The backup retention period
* `backup_window` - The backup window
* `preferred_backup_window` - The backup window
* `preferred_maintenance_window` - The maintenance window
* `endpoint` - The primary, writeable connection endpoint
* `engine` - The database engine
* `engine_version` - The database engine version
@ -80,6 +86,7 @@ The following attributes are exported:
* `status` - The RDS instance status
* `username` - The master username for the database
* `storage_encrypted` - Specifies whether the DB instance is encrypted
* `preferred_backup_window` - The daily time range during which the backups happen
[1]: http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.Replication.html