Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/db_instance: Fix bug introduced v3.29.0, name, snapshot conflicts #17755

Merged
merged 2 commits into from
Feb 23, 2021
Merged
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
3 changes: 3 additions & 0 deletions .changelog/17755.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_db_instance: Fix conflicting argument validation error
```
32 changes: 11 additions & 21 deletions aws/resource_aws_db_instance.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package aws

import (
"context"
"fmt"
"log"
"regexp"
Expand All @@ -12,7 +11,6 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/rds"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand Down Expand Up @@ -415,10 +413,9 @@ func resourceAwsDbInstance() *schema.Resource {
},

"snapshot_identifier": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"username"},
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},

"auto_minor_version_upgrade": {
Expand Down Expand Up @@ -532,20 +529,6 @@ func resourceAwsDbInstance() *schema.Resource {

"tags": tagsSchema(),
},

CustomizeDiff: customdiff.All(
func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error {
if _, ok := diff.GetOk("snapshot_identifier"); ok {
switch strings.ToLower(diff.Get("engine").(string)) {
case "mysql", "postgres", "mariadb":
if _, ok := diff.GetOk("name"); ok {
return fmt.Errorf("name attribute is not supported with snapshot_identifier when engine is %s", diff.Get("engine").(string))
}
}
}
return nil
},
),
}
}

Expand Down Expand Up @@ -911,7 +894,14 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error
}

if attr, ok := d.GetOk("name"); ok {
opts.DBName = aws.String(attr.(string))
// "Note: This parameter [DBName] doesn't apply to the MySQL, PostgreSQL, or MariaDB engines."
// https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_RestoreDBInstanceFromDBSnapshot.html
switch strings.ToLower(d.Get("engine").(string)) {
case "mysql", "postgres", "mariadb":
// skip
default:
opts.DBName = aws.String(attr.(string))
}
}

if attr, ok := d.GetOk("allocated_storage"); ok {
Expand Down
2 changes: 2 additions & 0 deletions aws/resource_aws_db_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4575,6 +4575,8 @@ resource "aws_db_instance" "mysql_restore" {
instance_class = data.aws_rds_orderable_db_instance.test.instance_class
allocated_storage = 20
username = "root"
password = "password"
engine = data.aws_rds_orderable_db_instance.test.engine
engine_version = "5.6.41"
backup_retention_period = 0
Expand Down