Skip to content

Commit

Permalink
Rebase on master and address reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
Gufran committed Nov 6, 2020
1 parent d84e64b commit 0e9be90
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 26 deletions.
25 changes: 11 additions & 14 deletions aws/resource_aws_rds_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aws
import (
"errors"
"fmt"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource"
"log"
"regexp"
"strings"
Expand Down Expand Up @@ -217,7 +218,7 @@ func resourceAwsRDSCluster() *schema.Resource {
ForceNew: true,
},

"restore_in_time": {
"restore_to_point_in_time": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Expand Down Expand Up @@ -249,7 +250,7 @@ func resourceAwsRDSCluster() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"restore_in_time.restore_to_time"},
ConflictsWith: []string{"restore_to_point_in_time.restore_to_time"},
},

"restore_to_time": {
Expand All @@ -268,7 +269,7 @@ func resourceAwsRDSCluster() *schema.Resource {
MaxItems: 1,
ConflictsWith: []string{
"snapshot_identifier",
"restore_in_time",
"restore_to_point_in_time",
},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -451,7 +452,7 @@ func resourceAwsRDSCluster() *schema.Resource {
Default: false,
},

"tags": tagsSchemaComputed(),
"tags": tagsSchema(),
},
}
}
Expand Down Expand Up @@ -696,7 +697,7 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
return err
}

} else if v, ok := d.GetOk("restore_in_time"); ok {
} else if v, ok := d.GetOk("restore_to_point_in_time"); ok {
pointInTime := v.([]interface{})[0].(map[string]interface{})

restoreToTimeAttr := pointInTime["restore_to_time"].(string)
Expand Down Expand Up @@ -768,7 +769,6 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error

requireUpdateAttrs := []string{
"master_password",
"final_snapshot_identifier",
"backup_retention_period",
"preferred_backup_window",
"preferred_maintenance_window",
Expand All @@ -788,7 +788,7 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
case "preferred_maintenance_window":
modifyDbClusterInput.PreferredMaintenanceWindow = aws.String(val.(string))
case "scaling_configuration":
modifyDbClusterInput.ScalingConfiguration = expandRdsScalingConfiguration(d.Get("scaling_configuration").([]interface{}))
modifyDbClusterInput.ScalingConfiguration = expandRdsClusterScalingConfiguration(d.Get("scaling_configuration").([]interface{}))
}
}
}
Expand All @@ -798,20 +798,17 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
err := resource.Retry(5*time.Minute, func() *resource.RetryError {
resp, err := conn.RestoreDBClusterToPointInTime(createOpts)
if err != nil {
if isAWSErr(err, "DBClusterSnapshotNotFoundFault", "DBClusterSnapshotIdentifier doesn't refer to an existing DB cluster snapshot") {
return resource.RetryableError(err)
}
if isAWSErr(err, "KMSKeyNotAccessibleFault", "An error occurred accessing an AWS KMS key") {
return resource.RetryableError(err)
}

return resource.NonRetryableError(err)
}

log.Printf("[DEBUG]: RDS Cluster restore response: %s", resp)
return nil
})

if tfresource.TimedOut(err) {
_, err = conn.RestoreDBClusterToPointInTime(createOpts)
}

if err != nil {
log.Printf("[ERROR] Error restoring RDS Cluster: %s", err)
return err
Expand Down
16 changes: 8 additions & 8 deletions aws/resource_aws_rds_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2668,7 +2668,7 @@ resource "aws_rds_cluster" "test" {
cluster_identifier = "%s"
master_username = "root"
master_password = "password"
db_subnet_group_name = "${aws_db_subnet_group.test.name}"
db_subnet_group_name = aws_db_subnet_group.test.name
skip_final_snapshot = true
engine = "aurora-mysql"
}
Expand All @@ -2681,28 +2681,28 @@ resource "aws_vpc" "test" {
}
resource "aws_subnet" "subnets" {
count = "${length(data.aws_availability_zones.available.names)}"
vpc_id = "${aws_vpc.test.id}"
count = length(data.aws_availability_zones.available.names)
vpc_id = aws_vpc.test.id
cidr_block = "10.0.${count.index}.0/24"
availability_zone = "${data.aws_availability_zones.available.names[count.index]}"
availability_zone = data.aws_availability_zones.available.names[count.index]
tags = {
Name = "%s-subnet-${count.index}"
}
}
resource "aws_db_subnet_group" "test" {
name = "%s-db-subnet-group"
subnet_ids = ["${aws_subnet.subnets.*.id}"]
subnet_ids = aws_subnet.subnets[*].id
}
resource "aws_rds_cluster" "restored_pit" {
cluster_identifier = "%s"
skip_final_snapshot = true
engine = "aurora-mysql"
restore_in_time {
source_cluster_identifier = "${aws_rds_cluster.test.cluster_identifier}"
restore_to_point_in_time {
source_cluster_identifier = aws_rds_cluster.test.cluster_identifier
restore_type = "full-copy"
use_latest_restorable_time = "true"
use_latest_restorable_time = true
}
}
`, parentId, parentId, parentId, parentId, childId)
Expand Down
2 changes: 1 addition & 1 deletion aws/validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3245,4 +3245,4 @@ func TestValidateRdsRestorableTimeFormat(t *testing.T) {
t.Fatalf("Expected the time %q to fail validation", f)
}
}
}
}
6 changes: 3 additions & 3 deletions website/docs/r/rds_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ The following arguments are supported:
* `preferred_backup_window` - (Optional) The daily time range during which automated backups are created if automated backups are enabled using the BackupRetentionPeriod parameter.Time in UTC. Default: A 30-minute window selected at random from an 8-hour block of time per region. e.g. 04:00-09:00
* `preferred_maintenance_window` - (Optional) The weekly time range during which system maintenance can occur, in (UTC) e.g. wed:04:00-wed:04:30
* `replication_source_identifier` - (Optional) ARN of a source DB cluster or DB instance if this DB cluster is to be created as a Read Replica. If DB Cluster is part of a Global Cluster, use the [`lifecycle` configuration block `ignore_changes` argument](/docs/configuration/resources.html#ignore_changes) to prevent Terraform from showing differences for this argument instead of configuring this value.
* `restore_in_time` - (Optional) Nested attribute for [point in time restore](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_PIT.html). More details below.
* `restore_to_point_in_time` - (Optional) Nested attribute for [point in time restore](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_PIT.html). More details below.
* `scaling_configuration` - (Optional) Nested attribute with scaling properties. Only valid when `engine_mode` is set to `serverless`. More details below.
* `skip_final_snapshot` - (Optional) Determines whether a final DB snapshot is created before the DB cluster is deleted. If true is specified, no DB snapshot is created. If false is specified, a DB snapshot is created before the DB cluster is deleted, using the value from `final_snapshot_identifier`. Default is `false`.
* `snapshot_identifier` - (Optional) Specifies whether or not to create this cluster from a snapshot. You can use either the name or ARN when specifying a DB cluster snapshot, or the ARN when specifying a DB snapshot.
Expand Down Expand Up @@ -190,15 +190,15 @@ resource "aws_rds_cluster" "example" {
* `seconds_until_auto_pause` - (Optional) The time, in seconds, before an Aurora DB cluster in serverless mode is paused. Valid values are `300` through `86400`. Defaults to `300`.
* `timeout_action` - (Optional) The action to take when the timeout is reached. Valid values: `ForceApplyCapacityChange`, `RollbackCapacityChange`. Defaults to `RollbackCapacityChange`. See [documentation](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-serverless.how-it-works.html#aurora-serverless.how-it-works.timeout-action).

### restore_in_time Argument Reference
### restore_to_point_in_time Argument Reference

Example:

```hcl
resource "aws_rds_cluster" "example-clone" {
# ... other configuration ...
restore_in_time {
restore_To_point_in_time {
source_cluster_identifier = "example"
restore_type = "copy-on-write"
use_latest_restorable_time = true
Expand Down

0 comments on commit 0e9be90

Please sign in to comment.