Skip to content

Commit

Permalink
Merge pull request hashicorp#1591 from Shoobx/aurora-postgres
Browse files Browse the repository at this point in the history
Aurora for postgres RDS engine support
  • Loading branch information
Ninir authored Sep 21, 2017
2 parents cd7d96d + 7d32e83 commit dc6668b
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 2 deletions.
16 changes: 15 additions & 1 deletion aws/resource_aws_rds_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,18 @@ func resourceAwsRDSCluster() *schema.Resource {
},

"engine": {
Type: schema.TypeString,
Optional: true,
Default: "aurora",
ForceNew: true,
ValidateFunc: validateRdsEngine,
},

"engine_version": {
Type: schema.TypeString,
Optional: true,
Default: "aurora",
ForceNew: true,
Computed: true,
},

"storage_encrypted": {
Expand Down Expand Up @@ -371,6 +380,10 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
createOpts.DBClusterParameterGroupName = aws.String(attr.(string))
}

if attr, ok := d.GetOk("engine_version"); ok {
createOpts.EngineVersion = aws.String(attr.(string))
}

if attr := d.Get("vpc_security_group_ids").(*schema.Set); attr.Len() > 0 {
createOpts.VpcSecurityGroupIds = expandStringList(attr.List())
}
Expand Down Expand Up @@ -560,6 +573,7 @@ func resourceAwsRDSClusterRead(d *schema.ResourceData, meta interface{}) error {
d.Set("db_cluster_parameter_group_name", dbc.DBClusterParameterGroup)
d.Set("endpoint", dbc.Endpoint)
d.Set("engine", dbc.Engine)
d.Set("engine_version", dbc.EngineVersion)
d.Set("master_username", dbc.MasterUsername)
d.Set("port", dbc.Port)
d.Set("storage_encrypted", dbc.StorageEncrypted)
Expand Down
23 changes: 22 additions & 1 deletion aws/resource_aws_rds_cluster_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@ func resourceAwsRDSClusterInstance() *schema.Resource {
Required: true,
},

"engine": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: "aurora",
ValidateFunc: validateRdsEngine,
},

"engine_version": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},

"db_parameter_group_name": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -176,7 +191,7 @@ func resourceAwsRDSClusterInstanceCreate(d *schema.ResourceData, meta interface{
createOpts := &rds.CreateDBInstanceInput{
DBInstanceClass: aws.String(d.Get("instance_class").(string)),
DBClusterIdentifier: aws.String(d.Get("cluster_identifier").(string)),
Engine: aws.String("aurora"),
Engine: aws.String(d.Get("engine").(string)),
PubliclyAccessible: aws.Bool(d.Get("publicly_accessible").(bool)),
PromotionTier: aws.Int64(int64(d.Get("promotion_tier").(int))),
AutoMinorVersionUpgrade: aws.Bool(d.Get("auto_minor_version_upgrade").(bool)),
Expand All @@ -201,6 +216,10 @@ func resourceAwsRDSClusterInstanceCreate(d *schema.ResourceData, meta interface{
createOpts.DBSubnetGroupName = aws.String(attr.(string))
}

if attr, ok := d.GetOk("engine_version"); ok {
createOpts.EngineVersion = aws.String(attr.(string))
}

if attr, ok := d.GetOk("monitoring_role_arn"); ok {
createOpts.MonitoringRoleArn = aws.String(attr.(string))
}
Expand Down Expand Up @@ -292,6 +311,8 @@ func resourceAwsRDSClusterInstanceRead(d *schema.ResourceData, meta interface{})

d.Set("publicly_accessible", db.PubliclyAccessible)
d.Set("cluster_identifier", db.DBClusterIdentifier)
d.Set("engine", db.Engine)
d.Set("engine_version", db.EngineVersion)
d.Set("instance_class", db.DBInstanceClass)
d.Set("identifier", db.DBInstanceIdentifier)
d.Set("dbi_resource_id", db.DbiResourceId)
Expand Down
2 changes: 2 additions & 0 deletions aws/resource_aws_rds_cluster_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func TestAccAWSRDSClusterInstance_basic(t *testing.T) {
resource.TestCheckResourceAttrSet("aws_rds_cluster_instance.cluster_instances", "preferred_backup_window"),
resource.TestCheckResourceAttrSet("aws_rds_cluster_instance.cluster_instances", "dbi_resource_id"),
resource.TestCheckResourceAttrSet("aws_rds_cluster_instance.cluster_instances", "availability_zone"),
resource.TestCheckResourceAttrSet("aws_rds_cluster_instance.cluster_instances", "engine_version"),
resource.TestCheckResourceAttr("aws_rds_cluster_instance.cluster_instances", "engine", "aurora"),
),
},
{
Expand Down
4 changes: 4 additions & 0 deletions aws/resource_aws_rds_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func TestAccAWSRDSCluster_basic(t *testing.T) {
"aws_rds_cluster.default", "reader_endpoint"),
resource.TestCheckResourceAttrSet(
"aws_rds_cluster.default", "cluster_resource_id"),
resource.TestCheckResourceAttr(
"aws_rds_cluster.default", "engine", "aurora"),
resource.TestCheckResourceAttrSet(
"aws_rds_cluster.default", "engine_version"),
),
},
},
Expand Down
16 changes: 16 additions & 0 deletions aws/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ func validateRdsIdentifierPrefix(v interface{}, k string) (ws []string, errors [
return
}

func validateRdsEngine(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)

validTypes := map[string]bool{
"aurora": true,
"aurora-postgresql": true,
}

if _, ok := validTypes[value]; !ok {
errors = append(errors, fmt.Errorf(
"%q contains an invalid engine type %q. Valid types are either %q or %q.",
k, value, "aurora", "aurora-postgresql"))
}
return
}

func validateElastiCacheClusterId(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if (len(value) < 1) || (len(value) > 20) {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/rds_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Default: A 30-minute window selected at random from an 8-hour block of time per
* `iam_roles` - (Optional) A List of ARNs for the IAM roles to associate to the RDS Cluster.
* `iam_database_authentication_enabled` - (Optional) Specifies whether or mappings of AWS Identity and Access Management (IAM) accounts to database accounts is enabled.
* `engine` - (Optional) The name of the database engine to be used for this DB cluster. Defaults to `aurora`.
* `engine_version` - (Optional) The database engine version.


## Attributes Reference
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/rds_cluster_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ The following arguments are supported:
* `identifier` - (Optional, Forces new resource) The indentifier for the RDS instance, if omitted, Terraform will assign a random, unique identifier.
* `identifier_prefix` - (Optional, Forces new resource) Creates a unique identifier beginning with the specified prefix. Conflicts with `identifer`.
* `cluster_identifier` - (Required) The identifier of the [`aws_rds_cluster`](/docs/providers/aws/r/rds_cluster.html) in which to launch this instance.
* `engine` - (Optional) The name of the database engine to be used for the RDS instance. Defaults to `aurora`.
* `engine_version` - (Optional) The database engine version.
* `instance_class` - (Required) The instance class to use. For details on CPU
and memory, see [Scaling Aurora DB Instances][4]. Aurora currently
supports the below instance classes.
Expand Down

0 comments on commit dc6668b

Please sign in to comment.