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

resource/aws_db_instance: Redact MasterUserPassword when displaying InvalidParameterValue error with CreateDBInstance #9446

Merged
merged 1 commit into from
Jul 23, 2019
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
1 change: 1 addition & 0 deletions aws/resource_aws_db_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,7 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error
})
if err != nil {
if isAWSErr(err, "InvalidParameterValue", "") {
opts.MasterUserPassword = aws.String("********")
return fmt.Errorf("Error creating DB Instance: %s, %+v", err, opts)
}
return fmt.Errorf("Error creating DB Instance: %s", err)
Expand Down
52 changes: 52 additions & 0 deletions aws/resource_aws_db_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,44 @@ func TestAccAWSDBInstance_MaxAllocatedStorage(t *testing.T) {
})
}

func TestAccAWSDBInstance_Password(t *testing.T) {
var dbInstance rds.DBInstance

rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_db_instance.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
Steps: []resource.TestStep{
// Password should not be shown in error message
{
Config: testAccAWSDBInstanceConfig_Password(rName, "invalid"),
ExpectError: regexp.MustCompile(`MasterUserPassword: "\*{8}",`),
},
{
Config: testAccAWSDBInstanceConfig_Password(rName, "valid-password"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBInstanceExists(resourceName, &dbInstance),
resource.TestCheckResourceAttr(resourceName, "password", "valid-password"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"apply_immediately",
"final_snapshot_identifier",
"password",
"skip_final_snapshot",
},
},
},
})
}

func TestAccAWSDBInstance_ReplicateSourceDb(t *testing.T) {
var dbInstance, sourceDbInstance rds.DBInstance

Expand Down Expand Up @@ -3971,6 +4009,20 @@ resource "aws_db_instance" "test" {
`, rName, maxAllocatedStorage)
}

func testAccAWSDBInstanceConfig_Password(rName, password string) string {
return fmt.Sprintf(`
resource "aws_db_instance" "test" {
allocated_storage = 5
engine = "mysql"
identifier = %[1]q
instance_class = "db.t2.micro"
password = %[2]q
username = "tfacctest"
skip_final_snapshot = true
}
`, rName, password)
}

func testAccAWSDBInstanceConfig_ReplicateSourceDb(rName string) string {
return fmt.Sprintf(`
resource "aws_db_instance" "source" {
Expand Down