Skip to content

Commit

Permalink
Merge branch 'mburtless-rds-add-domain'
Browse files Browse the repository at this point in the history
  • Loading branch information
bflad committed Sep 6, 2018
2 parents 130774c + 5a55e2d commit 54157c3
Show file tree
Hide file tree
Showing 3 changed files with 491 additions and 0 deletions.
41 changes: 41 additions & 0 deletions aws/resource_aws_db_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,16 @@ func resourceAwsDbInstance() *schema.Resource {
},
},

"domain": {
Type: schema.TypeString,
Optional: true,
},

"domain_iam_role_name": {
Type: schema.TypeString,
Optional: true,
},

"tags": tagsSchema(),
},
}
Expand Down Expand Up @@ -777,6 +787,14 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error
opts.DBSubnetGroupName = aws.String(attr.(string))
}

if attr, ok := d.GetOk("domain"); ok {
opts.Domain = aws.String(attr.(string))
}

if attr, ok := d.GetOk("domain_iam_role_name"); ok {
opts.DomainIAMRoleName = aws.String(attr.(string))
}

if attr, ok := d.GetOk("enabled_cloudwatch_logs_exports"); ok && len(attr.([]interface{})) > 0 {
opts.EnableCloudwatchLogsExports = expandStringList(attr.([]interface{}))
}
Expand Down Expand Up @@ -1003,6 +1021,14 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error
opts.EnableIAMDatabaseAuthentication = aws.Bool(attr.(bool))
}

if attr, ok := d.GetOk("domain"); ok {
opts.Domain = aws.String(attr.(string))
}

if attr, ok := d.GetOk("domain_iam_role_name"); ok {
opts.DomainIAMRoleName = aws.String(attr.(string))
}

log.Printf("[DEBUG] DB Instance create configuration: %#v", opts)
var err error
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
Expand Down Expand Up @@ -1153,6 +1179,13 @@ func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("error setting enabled_cloudwatch_logs_exports: %s", err)
}

d.Set("domain", "")
d.Set("domain_iam_role_name", "")
if len(v.DomainMemberships) > 0 && v.DomainMemberships[0] != nil {
d.Set("domain", v.DomainMemberships[0].Domain)
d.Set("domain_iam_role_name", v.DomainMemberships[0].IAMRoleName)
}

// list tags for resource
// set tags
conn := meta.(*AWSClient).rdsconn
Expand Down Expand Up @@ -1412,6 +1445,14 @@ func resourceAwsDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error
requestUpdate = true
}

if d.HasChange("domain") || d.HasChange("domain_iam_role_name") {
d.SetPartial("domain")
d.SetPartial("domain_iam_role_name")
req.Domain = aws.String(d.Get("domain").(string))
req.DomainIAMRoleName = aws.String(d.Get("domain_iam_role_name").(string))
requestUpdate = true
}

log.Printf("[DEBUG] Send DB Instance Modification request: %t", requestUpdate)
if requestUpdate {
log.Printf("[DEBUG] DB Instance Modification request: %s", req)
Expand Down
Loading

0 comments on commit 54157c3

Please sign in to comment.