Skip to content

Commit

Permalink
CR updates
Browse files Browse the repository at this point in the history
  • Loading branch information
anGie44 committed Nov 12, 2020
1 parent 81ca42c commit 29f6405
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
27 changes: 27 additions & 0 deletions aws/resource_aws_db_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
14 changes: 11 additions & 3 deletions aws/resource_aws_db_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3623,14 +3623,24 @@ 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
engine = data.aws_rds_orderable_db_instance.test.engine
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"
Expand All @@ -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" {
Expand All @@ -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" {
Expand Down
3 changes: 0 additions & 3 deletions website/docs/r/db_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 29f6405

Please sign in to comment.