Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow RDS Cluster / Cluster instance to specify the engine #1591

Merged
merged 3 commits into from
Sep 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should validate the engine value, as we would need to update the code each time a new engine is available. Thoughts?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid point however, amazon introduced aurora for MySQL in 2014 and added PostgreSQL in 2017. Don't have insights into their product plans but so far if they keep adding one every 3 years updating code won't be an issue. I think having validation is more useful/user friendly than flexibility.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me :)

},

"engine_version": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also read the engine version around line 575

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, missed that one.

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also read the engine_version here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will fix it too

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