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: Adds support for domain joining RDS instances #5378

Merged
merged 12 commits into from
Sep 6, 2018
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
39 changes: 39 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,11 @@ func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("error setting enabled_cloudwatch_logs_exports: %s", err)
}

if len(v.DomainMemberships) > 0 && v.DomainMemberships[0] != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

To detect drift when the domain membership is removed out of band of Terraform, we should ensure the Terraform state always starts with "", e.g.

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)
}

👍

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 +1443,14 @@ func resourceAwsDbInstanceUpdate(d *schema.ResourceData, meta interface{}) error
requestUpdate = true
}

if (d.HasChange("domain") || d.HasChange("domain_iam_role_name")) && !d.IsNewResource() {
Copy link
Contributor

Choose a reason for hiding this comment

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

We very recently fixed the resource so it does not call the Update function after the Create function, so the !d.IsNewResource() check here is now extraneous. 😄

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