Add support for IAMDatabaseAuthenticationEnabled

This commit is contained in:
Gareth Oakley 2017-04-29 20:32:21 +01:00
parent 15704cc6ee
commit e4c732b34c
10 changed files with 463 additions and 247 deletions

View File

@ -335,6 +335,11 @@ func resourceAwsDbInstance() *schema.Resource {
ForceNew: true,
},
"iam_database_authentication_enabled": {
Type: schema.TypeBool,
Optional: true,
},
"tags": tagsSchema(),
},
}
@ -634,6 +639,10 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error
opts.KmsKeyId = aws.String(attr.(string))
}
if attr, ok := d.GetOk("iam_database_authentication_enabled"); ok {
opts.EnableIAMDatabaseAuthentication = aws.Bool(attr.(bool))
}
log.Printf("[DEBUG] DB Instance create configuration: %#v", opts)
var err error
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
@ -710,6 +719,7 @@ func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error {
d.Set("multi_az", v.MultiAZ)
d.Set("kms_key_id", v.KmsKeyId)
d.Set("port", v.DbInstancePort)
d.Set("iam_database_authentication_enabled", v.IAMDatabaseAuthenticationEnabled)
if v.DBSubnetGroup != nil {
d.Set("db_subnet_group_name", v.DBSubnetGroup.DBSubnetGroupName)
}
@ -994,6 +1004,11 @@ func resourceAwsDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error
requestUpdate = true
}
if d.HasChange("iam_database_authentication_enabled") {
req.EnableIAMDatabaseAuthentication = aws.Bool(d.Get("iam_database_authentication_enabled").(bool))
requestUpdate = true
}
log.Printf("[DEBUG] Send DB Instance Modification request: %t", requestUpdate)
if requestUpdate {
log.Printf("[DEBUG] DB Instance Modification request: %s", req)

View File

@ -170,6 +170,27 @@ func TestAccAWSDBInstance_optionGroup(t *testing.T) {
})
}
func TestAccAWSDBInstance_iamAuth(t *testing.T) {
var v rds.DBInstance
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckAWSDBIAMAuth(acctest.RandInt()),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
testAccCheckAWSDBInstanceAttributes(&v),
resource.TestCheckResourceAttr(
"aws_db_instance.bar", "iam_database_authentication_enabled", "true"),
),
},
},
})
}
func TestAccAWSDBInstanceReplica(t *testing.T) {
var s, r rds.DBInstance
@ -773,6 +794,24 @@ resource "aws_db_instance" "bar" {
}`, rName, acctest.RandInt())
}
func testAccCheckAWSDBIAMAuth(n int) string {
return fmt.Sprintf(`
resource "aws_db_instance" "bar" {
identifier = "foobarbaz-test-terraform-%d"
allocated_storage = 10
engine = "mysql"
engine_version = "5.6.34"
instance_class = "db.t2.micro"
name = "baz"
password = "barbarbarbar"
username = "foo"
backup_retention_period = 0
skip_final_snapshot = true
parameter_group_name = "default.mysql5.6"
iam_database_authentication_enabled = true
}`, n)
}
func testAccReplicaInstanceConfig(val int) string {
return fmt.Sprintf(`
resource "aws_db_instance" "bar" {

View File

@ -216,6 +216,11 @@ func resourceAwsRDSCluster() *schema.Resource {
Optional: true,
},
"iam_database_authentication_enabled": {
Type: schema.TypeBool,
Optional: true,
},
"tags": tagsSchema(),
},
}
@ -428,6 +433,10 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
createOpts.KmsKeyId = aws.String(attr.(string))
}
if attr, ok := d.GetOk("iam_database_authentication_enabled"); ok {
createOpts.EnableIAMDatabaseAuthentication = aws.Bool(attr.(bool))
}
log.Printf("[DEBUG] RDS Cluster create options: %s", createOpts)
resp, err := conn.CreateDBCluster(createOpts)
if err != nil {
@ -520,6 +529,7 @@ func resourceAwsRDSClusterRead(d *schema.ResourceData, meta interface{}) error {
d.Set("kms_key_id", dbc.KmsKeyId)
d.Set("reader_endpoint", dbc.ReaderEndpoint)
d.Set("replication_source_identifier", dbc.ReplicationSourceIdentifier)
d.Set("iam_database_authentication_enabled", dbc.IAMDatabaseAuthenticationEnabled)
var vpcg []string
for _, g := range dbc.VpcSecurityGroups {
@ -594,6 +604,11 @@ func resourceAwsRDSClusterUpdate(d *schema.ResourceData, meta interface{}) error
requestUpdate = true
}
if d.HasChange("iam_database_authentication_enabled") {
req.EnableIAMDatabaseAuthentication = aws.Bool(d.Get("iam_database_authentication_enabled").(bool))
requestUpdate = true
}
if requestUpdate {
_, err := conn.ModifyDBCluster(req)
if err != nil {

View File

@ -225,6 +225,26 @@ func TestAccAWSRDSCluster_backupsUpdate(t *testing.T) {
})
}
func TestAccAWSRDSCluster_iamAuth(t *testing.T) {
var v rds.DBCluster
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSClusterConfig_iamAuth(acctest.RandInt()),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterExists("aws_rds_cluster.default", &v),
resource.TestCheckResourceAttr(
"aws_rds_cluster.default", "iam_database_authentication_enabled", "true"),
),
},
},
})
}
func testAccCheckAWSClusterDestroy(s *terraform.State) error {
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_rds_cluster" {
@ -550,3 +570,16 @@ resource "aws_rds_cluster" "default" {
skip_final_snapshot = true
}`, n)
}
func testAccAWSClusterConfig_iamAuth(n int) string {
return fmt.Sprintf(`
resource "aws_rds_cluster" "default" {
cluster_identifier = "tf-aurora-cluster-%d"
availability_zones = ["us-west-2a","us-west-2b","us-west-2c"]
database_name = "mydb"
master_username = "foo"
master_password = "mustbeeightcharaters"
iam_database_authentication_enabled = true
skip_final_snapshot = true
}`, n)
}

File diff suppressed because it is too large Load Diff

View File

@ -272,7 +272,9 @@ const (
// ErrCodeInvalidDBParameterGroupStateFault for service response error code
// "InvalidDBParameterGroupState".
//
// The DB parameter group cannot be deleted because it is in use.
// The DB parameter group is in use or is in an invalid state. If you are attempting
// to delete the parameter group, you cannot delete it when the parameter group
// is in this state.
ErrCodeInvalidDBParameterGroupStateFault = "InvalidDBParameterGroupState"
// ErrCodeInvalidDBSecurityGroupStateFault for service response error code

View File

@ -14,9 +14,9 @@ import (
//
// Amazon Relational Database Service (Amazon RDS) is a web service that makes
// it easier to set up, operate, and scale a relational database in the cloud.
// It provides cost-efficient, resizeable capacity for an industry-standard
// relational database and manages common database administration tasks, freeing
// up developers to focus on what makes their applications and businesses unique.
// It provides cost-efficient, resizable capacity for an industry-standard relational
// database and manages common database administration tasks, freeing up developers
// to focus on what makes their applications and businesses unique.
//
// Amazon RDS gives you access to the capabilities of a MySQL, MariaDB, PostgreSQL,
// Microsoft SQL Server, Oracle, or Amazon Aurora database server. These capabilities

10
vendor/vendor.json vendored
View File

@ -1037,12 +1037,12 @@
"versionExact": "v1.8.16"
},
{
"checksumSHA1": "5Br7nJBgOm6y67Z95CGZtOaxlFY=",
"checksumSHA1": "z39/EZX3f3n0r2uML2XC33krUag=",
"path": "github.com/aws/aws-sdk-go/service/rds",
"revision": "f6ea558f30e0a983d529b32c741e4caed17c7df0",
"revisionTime": "2017-04-21T18:17:16Z",
"version": "v1.8.16",
"versionExact": "v1.8.16"
"revision": "8cab5437f896c3048506422a6fb9f5a7f2df9944",
"revisionTime": "2017-04-26T18:58:25Z",
"version": "v1.8.17",
"versionExact": "v1.8.17"
},
{
"checksumSHA1": "TIYqqHM4J5j5tWZR+FLpRpQzz7A=",

View File

@ -112,6 +112,7 @@ what IAM permissions are needed to allow Enhanced Monitoring for RDS Instances.
* `kms_key_id` - (Optional) The ARN for the KMS encryption key.
* `character_set_name` - (Optional) The character set name to use for DB encoding in Oracle instances. This can't be changed.
[Oracle Character Sets Supported in Amazon RDS](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Appendix.OracleCharacterSets.html)
* `iam_database_authentication_enabled` - (Optional) Specifies whether or mappings of AWS Identity and Access Management (IAM) accounts to database accounts is enabled.
* `tags` - (Optional) A mapping of tags to assign to the resource.
* `timezone` - (Optional) Time zone of the DB instance. `timezone` is currently only supported by Microsoft SQL Server.
The `timezone` can only be set on creation. See [MSSQL User Guide](http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_SQLServer.html#SQLServer.Concepts.General.TimeZone) for more information

View File

@ -83,6 +83,7 @@ Default: A 30-minute window selected at random from an 8-hour block of time per
* `db_subnet_group_name` - (Optional) A DB subnet group to associate with this DB instance. **NOTE:** This must match the `db_subnet_group_name` specified on every [`aws_rds_cluster_instance`](/docs/providers/aws/r/rds_cluster_instance.html) in the cluster.
* `db_cluster_parameter_group_name` - (Optional) A cluster parameter group to associate with the cluster.
* `kms_key_id` - (Optional) The ARN for the KMS encryption key. When specifying `kms_key_id`, `storage_encrypted` needs to be set to true.
* `iam_database_authentication_enabled` - (Optional) Specifies whether or mappings of AWS Identity and Access Management (IAM) accounts to database accounts is enabled.
## Attributes Reference