Skip to content
Closed
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
7 changes: 4 additions & 3 deletions aws/resource_aws_db_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,11 +535,12 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error
opts.Iops = aws.Int64(int64(attr.(int)))
}

if arnParts := strings.Split(v.(string), ":"); len(arnParts) >= 4 {
opts.SourceRegion = aws.String(arnParts[3])
}
Comment on lines +538 to +540
Copy link
Contributor

Choose a reason for hiding this comment

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

This check would be safer and easier to understand using the AWS Go SDK provided ARN handlers arn.IsARN() and arn.Parse(), e.g.

		if arn.IsARN(v.(string)) {
			replicaSourceDbArn, err := arn.Parse(v.(string))
			if err != nil {
				return fmt.Errorf("error parsing replica_source_db as ARN: %s", err)
			}
			opts.SourceRegion = aws.String(replicaSourceDbArn.Region)
		}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I can make that change. Just shows how long this pr has been sitting here. (;


if attr, ok := d.GetOk("kms_key_id"); ok {
opts.KmsKeyId = aws.String(attr.(string))
if arnParts := strings.Split(v.(string), ":"); len(arnParts) >= 4 {
opts.SourceRegion = aws.String(arnParts[3])
}
}

if attr, ok := d.GetOk("maintenance_window"); ok {
Expand Down
10 changes: 3 additions & 7 deletions website/docs/r/db_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ identifier beginning with the specified prefix. Conflicts with `identifier`.
* `instance_class` - (Required) The instance type of the RDS instance.
* `iops` - (Optional) The amount of provisioned IOPS. Setting this implies a
storage_type of "io1".
* `kms_key_id` - (Optional) The ARN for the KMS encryption key. If creating an
encrypted replica, set this to the destination KMS ARN.
* `kms_key_id` - (Optional) The ARN for the KMS encryption key.
* `license_model` - (Optional, but required for some DB engines, i.e. Oracle
SE1) License model information for this DB instance.
* `maintenance_window` - (Optional) The window to perform maintenance in.
Expand Down Expand Up @@ -147,8 +146,7 @@ accessible. Default is `false`.
* `replicate_source_db` - (Optional) Specifies that this resource is a Replicate
database, and to use this value as the source database. This correlates to the
`identifier` of another Amazon RDS Database to replicate. Note that if you are
creating a cross-region replica of an encrypted database you will also need to
specify a `kms_key_id`. See [DB Instance Replication][1] and [Working with
creating a cross-region replica it must be an arn. See [DB Instance Replication][1] and [Working with
PostgreSQL and MySQL Read Replicas](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ReadRepl.html)
for more information on using Replication.
* `security_group_names` - (Optional/Deprecated) List of DB Security Groups to
Expand All @@ -163,9 +161,7 @@ is `false`.
database from a snapshot. This correlates to the snapshot ID you'd find in the
RDS console, e.g: rds:production-2015-06-26-06-05.
* `storage_encrypted` - (Optional) Specifies whether the DB instance is
encrypted. Note that if you are creating a cross-region read replica this field
is ignored and you should instead declare `kms_key_id` with a valid ARN. The
default is `false` if not specified.
encrypted. The default is `false` if not specified.
* `storage_type` - (Optional) One of "standard" (magnetic), "gp2" (general
purpose SSD), or "io1" (provisioned IOPS SSD). The default is "io1" if `iops` is
specified, "gp2" if not.
Expand Down