From 29f6405ecb585f6dc0c1eea76d7c911fc581aa00 Mon Sep 17 00:00:00 2001 From: Angie Pinilla Date: Wed, 11 Nov 2020 19:32:49 -0500 Subject: [PATCH] CR updates --- aws/resource_aws_db_instance.go | 27 ++++++++++++++++++++++++ aws/resource_aws_db_instance_test.go | 14 +++++++++--- website/docs/r/db_instance.html.markdown | 3 --- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/aws/resource_aws_db_instance.go b/aws/resource_aws_db_instance.go index 48c68a22b61..5ed3d2e3d84 100644 --- a/aws/resource_aws_db_instance.go +++ b/aws/resource_aws_db_instance.go @@ -296,14 +296,17 @@ func resourceAwsDbInstance() *schema.Resource { ValidateFunc: validateUTCTimestamp, ConflictsWith: []string{"restore_to_point_in_time.0.use_latest_restorable_time"}, }, + "source_db_instance_identifier": { Type: schema.TypeString, Optional: true, }, + "source_dbi_resource_id": { Type: schema.TypeString, Optional: true, }, + "use_latest_restorable_time": { Type: schema.TypeBool, Optional: true, @@ -1088,59 +1091,77 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error if v, ok := d.GetOk("availability_zone"); ok { input.AvailabilityZone = aws.String(v.(string)) } + if v, ok := d.GetOk("domain"); ok { input.Domain = aws.String(v.(string)) } + if v, ok := d.GetOk("domain_iam_role_name"); ok { input.DomainIAMRoleName = aws.String(v.(string)) } + if v, ok := d.GetOk("enabled_cloudwatch_logs_exports"); ok && v.(*schema.Set).Len() > 0 { input.EnableCloudwatchLogsExports = expandStringSet(v.(*schema.Set)) } + if v, ok := d.GetOk("engine"); ok { input.Engine = aws.String(v.(string)) } + if v, ok := d.GetOk("iam_database_authentication_enabled"); ok { input.EnableIAMDatabaseAuthentication = aws.Bool(v.(bool)) } + if v, ok := d.GetOk("iops"); ok { input.Iops = aws.Int64(int64(v.(int))) } + if v, ok := d.GetOk("license_model"); ok { input.LicenseModel = aws.String(v.(string)) } + if v, ok := d.GetOk("max_allocated_storage"); ok { input.MaxAllocatedStorage = aws.Int64(int64(v.(int))) } + if v, ok := d.GetOk("multi_az"); ok { input.MultiAZ = aws.Bool(v.(bool)) } + if v, ok := d.GetOk("name"); ok { input.DBName = aws.String(v.(string)) } + if v, ok := d.GetOk("option_group_name"); ok { input.OptionGroupName = aws.String(v.(string)) } + if v, ok := d.GetOk("parameter_group_name"); ok { input.DBParameterGroupName = aws.String(v.(string)) } + if v, ok := d.GetOk("port"); ok { input.Port = aws.Int64(int64(v.(int))) } + if v, ok := d.GetOk("storage_type"); ok { input.StorageType = aws.String(v.(string)) } + if v, ok := d.GetOk("subnet_group_name"); ok { input.DBSubnetGroupName = aws.String(v.(string)) } + if v, ok := d.GetOk("tde_credential_arn"); ok { input.TdeCredentialArn = aws.String(v.(string)) } + if v, ok := d.GetOk("vpc_security_group_ids"); ok && v.(*schema.Set).Len() > 0 { input.VpcSecurityGroupIds = expandStringSet(v.(*schema.Set)) } log.Printf("[DEBUG] DB Instance restore to point in time configuration: %s", input) + _, err := conn.RestoreDBInstanceToPointInTime(input) if err != nil { return fmt.Errorf("error creating DB Instance: %w", err) @@ -1933,23 +1954,29 @@ func expandRestoreToPointInTime(l []interface{}) *rds.RestoreDBInstanceToPointIn if len(l) == 0 || l[0] == nil { return nil } + tfMap, ok := l[0].(map[string]interface{}) if !ok { return nil } + input := &rds.RestoreDBInstanceToPointInTimeInput{} + if v, ok := tfMap["restore_time"].(string); ok && v != "" { parsedTime, err := time.Parse(time.RFC3339, v) if err == nil { input.RestoreTime = aws.Time(parsedTime) } } + if v, ok := tfMap["source_db_instance_identifier"].(string); ok && v != "" { input.SourceDBInstanceIdentifier = aws.String(v) } + if v, ok := tfMap["source_dbi_resource_id"].(string); ok && v != "" { input.SourceDbiResourceId = aws.String(v) } + if v, ok := tfMap["use_latest_restorable_time"].(bool); ok && v { input.UseLatestRestorableTime = aws.Bool(v) } diff --git a/aws/resource_aws_db_instance_test.go b/aws/resource_aws_db_instance_test.go index 2d43255bc44..18783de9086 100644 --- a/aws/resource_aws_db_instance_test.go +++ b/aws/resource_aws_db_instance_test.go @@ -3623,6 +3623,16 @@ resource "aws_db_instance" "test" { } const testAccAWSDBInstanceBaseConfig = ` +data "aws_rds_engine_version" "test" { + engine = "mysql" +} + +data "aws_rds_orderable_db_instance" "test" { + engine = data.aws_rds_engine_version.test.engine + engine_version = data.aws_rds_engine_version.test.version + preferred_instance_classes = ["db.t3.micro", "db.t2.micro", "db.t3.small"] +} + resource "aws_db_instance" "test" { allocated_storage = 10 backup_retention_period = 1 @@ -3630,7 +3640,7 @@ resource "aws_db_instance" "test" { engine_version = data.aws_rds_orderable_db_instance.test.engine_version instance_class = data.aws_rds_orderable_db_instance.test.instance_class name = "baz" - parameter_group_name = "default.mysql5.6" + parameter_group_name = "default.${data.aws_rds_engine_version.test.parameter_group_family}" password = "barbarbarbar" skip_final_snapshot = true username = "foo" @@ -3639,7 +3649,6 @@ resource "aws_db_instance" "test" { func testAccAWSDBInstanceConfig_RestoreToPointInTime_SourceIdentifier() string { return composeConfig( - testAccAWSDBInstanceConfig_orderableClassMysql(), testAccAWSDBInstanceBaseConfig, fmt.Sprintf(` resource "aws_db_instance" "restore" { @@ -3656,7 +3665,6 @@ resource "aws_db_instance" "restore" { func testAccAWSDBInstanceConfig_RestoreToPointInTime_SourceResourceID() string { return composeConfig( - testAccAWSDBInstanceConfig_orderableClassMysql(), testAccAWSDBInstanceBaseConfig, fmt.Sprintf(` resource "aws_db_instance" "restore" { diff --git a/website/docs/r/db_instance.html.markdown b/website/docs/r/db_instance.html.markdown index bbc8ae27598..9030a8d2e6b 100644 --- a/website/docs/r/db_instance.html.markdown +++ b/website/docs/r/db_instance.html.markdown @@ -217,11 +217,8 @@ This setting does not apply to `aurora-mysql` or `aurora-postgresql` DB engines. The `restore_to_point_in_time` block supports the following arguments: * `restore_time` - (Optional) The date and time to restore from. Value must be a time in Universal Coordinated Time (UTC) format and must be before the latest restorable time for the DB instance. Cannot be specified with `use_latest_restorable_time`. - * `source_db_instance_identifier` - (Optional) The identifier of the source DB instance from which to restore. Must match the identifier of an existing DB instance. Required if `source_dbi_resource_id` is not specified. - * `source_dbi_resource_id` - (Optional) The resource ID of the source DB instance from which to restore. Required if `source_db_instance_identifier` is not specified. - * `use_latest_restorable_time` - (Optional) A boolean value that indicates whether the DB instance is restored from the latest backup time. Defaults to `false`. Cannot be specified with `restore_time`. ### S3 Import Options