From 17c4055bf4730dadf98dd3f35174bcbb04dd3064 Mon Sep 17 00:00:00 2001 From: Miro Madecki Date: Mon, 14 Aug 2017 06:43:57 -0400 Subject: [PATCH 1/3] Aurora for postgres RDS engine support - allows explicitly setting one of two supported engine types aurora (default) or aurora-postgresql - adds optional engine_version which may be useful for pinning specific postgres engine version - maintains backward compatibility with existing aurora rds clusters with combinaton of defaults and optional parameters - used and tested under "Aurora PostgreSQL Preview" authorized aws account in us-east-1 region ``` github.com/terraform-providers/terraform-provider-aws$ TF_ACC=1 go test -v github.com/terraform-providers/terraform-provider-aws/aws -timeout=7200s -run "TestAccAWSRDSClusterInstance_.*" === RUN TestAccAWSRDSClusterInstance_importBasic --- PASS: TestAccAWSRDSClusterInstance_importBasic (770.69s) === RUN TestAccAWSRDSClusterInstance_basic --- PASS: TestAccAWSRDSClusterInstance_basic (1440.30s) === RUN TestAccAWSRDSClusterInstance_namePrefix --- PASS: TestAccAWSRDSClusterInstance_namePrefix (764.54s) === RUN TestAccAWSRDSClusterInstance_generatedName --- PASS: TestAccAWSRDSClusterInstance_generatedName (720.21s) === RUN TestAccAWSRDSClusterInstance_kmsKey --- PASS: TestAccAWSRDSClusterInstance_kmsKey (765.96s) === RUN TestAccAWSRDSClusterInstance_disappears --- PASS: TestAccAWSRDSClusterInstance_disappears (722.53s) === RUN TestAccAWSRDSClusterInstance_withInstanceEnhancedMonitor --- PASS: TestAccAWSRDSClusterInstance_withInstanceEnhancedMonitor (735.03s) PASS ok github.com/terraform-providers/terraform-provider-aws/aws 5919.258s github.com/terraform-providers/terraform-provider-aws$ TF_ACC=1 go test -v github.com/terraform-providers/terraform-provider-aws/aws -timeout=7200s -run "TestAccAWSRDSCluster_.*" === RUN TestAccAWSRDSCluster_importBasic --- PASS: TestAccAWSRDSCluster_importBasic (155.95s) === RUN TestAccAWSRDSCluster_basic --- PASS: TestAccAWSRDSCluster_basic (119.60s) === RUN TestAccAWSRDSCluster_namePrefix --- PASS: TestAccAWSRDSCluster_namePrefix (185.24s) === RUN TestAccAWSRDSCluster_generatedName --- PASS: TestAccAWSRDSCluster_generatedName (196.65s) === RUN TestAccAWSRDSCluster_takeFinalSnapshot --- PASS: TestAccAWSRDSCluster_takeFinalSnapshot (197.50s) === RUN TestAccAWSRDSCluster_missingUserNameCausesError --- PASS: TestAccAWSRDSCluster_missingUserNameCausesError (9.30s) === RUN TestAccAWSRDSCluster_updateTags --- PASS: TestAccAWSRDSCluster_updateTags (175.84s) === RUN TestAccAWSRDSCluster_updateIamRoles --- PASS: TestAccAWSRDSCluster_updateIamRoles (189.80s) === RUN TestAccAWSRDSCluster_kmsKey --- PASS: TestAccAWSRDSCluster_kmsKey (195.33s) === RUN TestAccAWSRDSCluster_encrypted --- PASS: TestAccAWSRDSCluster_encrypted (152.58s) === RUN TestAccAWSRDSCluster_backupsUpdate --- PASS: TestAccAWSRDSCluster_backupsUpdate (165.99s) === RUN TestAccAWSRDSCluster_iamAuth --- PASS: TestAccAWSRDSCluster_iamAuth (141.66s) PASS ok github.com/terraform-providers/terraform-provider-aws/aws 1885.459s ``` --- aws/resource_aws_rds_cluster.go | 15 ++++++++++++++- aws/resource_aws_rds_cluster_instance.go | 22 +++++++++++++++++++++- aws/validators.go | 16 ++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/aws/resource_aws_rds_cluster.go b/aws/resource_aws_rds_cluster.go index fe22f0959e5..a2ea8fcd34b 100644 --- a/aws/resource_aws_rds_cluster.go +++ b/aws/resource_aws_rds_cluster.go @@ -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": { @@ -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()) } diff --git a/aws/resource_aws_rds_cluster_instance.go b/aws/resource_aws_rds_cluster_instance.go index ef66b10de9c..0846c8a1c58 100644 --- a/aws/resource_aws_rds_cluster_instance.go +++ b/aws/resource_aws_rds_cluster_instance.go @@ -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, @@ -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)), @@ -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)) } @@ -292,6 +311,7 @@ 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("instance_class", db.DBInstanceClass) d.Set("identifier", db.DBInstanceIdentifier) d.Set("dbi_resource_id", db.DbiResourceId) diff --git a/aws/validators.go b/aws/validators.go index d69528f3dc4..d37510e103d 100644 --- a/aws/validators.go +++ b/aws/validators.go @@ -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) { From 1d866460aa178e4f45829ac93041844d88d226af Mon Sep 17 00:00:00 2001 From: Miro Madecki Date: Mon, 18 Sep 2017 15:03:55 -0400 Subject: [PATCH 2/3] Making sure engine_version is read and docs are updated. --- aws/resource_aws_rds_cluster.go | 1 + aws/resource_aws_rds_cluster_instance.go | 1 + website/docs/r/rds_cluster.html.markdown | 1 + website/docs/r/rds_cluster_instance.html.markdown | 2 ++ 4 files changed, 5 insertions(+) diff --git a/aws/resource_aws_rds_cluster.go b/aws/resource_aws_rds_cluster.go index a2ea8fcd34b..cd451b2d7c4 100644 --- a/aws/resource_aws_rds_cluster.go +++ b/aws/resource_aws_rds_cluster.go @@ -573,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) diff --git a/aws/resource_aws_rds_cluster_instance.go b/aws/resource_aws_rds_cluster_instance.go index 0846c8a1c58..a3321f33316 100644 --- a/aws/resource_aws_rds_cluster_instance.go +++ b/aws/resource_aws_rds_cluster_instance.go @@ -312,6 +312,7 @@ 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) diff --git a/website/docs/r/rds_cluster.html.markdown b/website/docs/r/rds_cluster.html.markdown index 934ba1957e6..a984258b362 100644 --- a/website/docs/r/rds_cluster.html.markdown +++ b/website/docs/r/rds_cluster.html.markdown @@ -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 diff --git a/website/docs/r/rds_cluster_instance.html.markdown b/website/docs/r/rds_cluster_instance.html.markdown index 5df3b906ab6..5a800e0ac6a 100644 --- a/website/docs/r/rds_cluster_instance.html.markdown +++ b/website/docs/r/rds_cluster_instance.html.markdown @@ -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. From 7d32e834b4995c5043ed961956dff36dddae9b66 Mon Sep 17 00:00:00 2001 From: Ninir Date: Thu, 21 Sep 2017 14:08:32 +0200 Subject: [PATCH 3/3] Added attributes validation --- aws/resource_aws_rds_cluster_instance_test.go | 2 ++ aws/resource_aws_rds_cluster_test.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/aws/resource_aws_rds_cluster_instance_test.go b/aws/resource_aws_rds_cluster_instance_test.go index 443a869e16f..72e49cd1728 100644 --- a/aws/resource_aws_rds_cluster_instance_test.go +++ b/aws/resource_aws_rds_cluster_instance_test.go @@ -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"), ), }, { diff --git a/aws/resource_aws_rds_cluster_test.go b/aws/resource_aws_rds_cluster_test.go index 1f26952e0f0..51da8845220 100644 --- a/aws/resource_aws_rds_cluster_test.go +++ b/aws/resource_aws_rds_cluster_test.go @@ -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"), ), }, },