Skip to content

Commit

Permalink
resource/aws_db_proxy_target: Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
bflad authored Sep 30, 2020
1 parent cef3556 commit e49d0cf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 33 deletions.
36 changes: 7 additions & 29 deletions aws/resource_aws_db_proxy_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,6 @@ func resourceAwsDbProxyTargetCreate(d *schema.ResourceData, meta interface{}) er
d.SetId(strings.Join([]string{dbProxyName, targetGroupName, *dbProxyTarget.RdsResourceId}, "/"))
log.Printf("[INFO] DB Proxy target ID: %s", d.Id())

// stateChangeConf := &resource.StateChangeConf{
// Pending: []string{rds.DBProxyStatusCreating},
// Target: []string{rds.DBProxyStatusAvailable},
// Refresh: resourceAwsDbProxyTargetRefreshFunc(conn, d.Id()),
// Timeout: d.Timeout(schema.TimeoutCreate),
// }

// _, err = stateChangeConf.WaitForState()
// if err != nil {
// return fmt.Errorf("Error waiting for DB Proxy target registration: %s", err)
// }

return resourceAwsDbProxyTargetRead(d, meta)
}

Expand Down Expand Up @@ -155,28 +143,30 @@ func resourceAwsDbProxyTargetRead(d *schema.ResourceData, meta interface{}) erro
resp, err := conn.DescribeDBProxyTargets(&params)
if err != nil {
if isAWSErr(err, rds.ErrCodeDBProxyNotFoundFault, "") {
log.Printf("[WARN] DB Proxy (%s) not found, removing from state", d.Id())
log.Printf("[WARN] DB Proxy Target (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}
if isAWSErr(err, rds.ErrCodeDBProxyTargetGroupNotFoundFault, "") {
log.Printf("[WARN] DB Proxy (%s) not found, removing from state", d.Id())
log.Printf("[WARN] DB Proxy Target (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}
return err
return fmt.Errorf("error reading RDS DB Proxy Target (%s): %w", d.Id(), err)
}

var dbProxyTarget *rds.DBProxyTarget
for _, target := range resp.Targets {
if *target.RdsResourceId == rdsResourceId {
if aws.StringValue(target.RdsResourceId) == rdsResourceId {
dbProxyTarget = target
break
}
}

if dbProxyTarget == nil {
return fmt.Errorf("Unable to find DB Proxy target: %#v", params)
log.Printf("[WARN] DB Proxy Target (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}

d.Set("endpoint", dbProxyTarget.Endpoint)
Expand Down Expand Up @@ -211,17 +201,5 @@ func resourceAwsDbProxyTargetDelete(d *schema.ResourceData, meta interface{}) er
return fmt.Errorf("Error deregistering DB Proxy target: %s", err)
}

// stateChangeConf := &resource.StateChangeConf{
// Pending: []string{rds.DBProxyStatusDeleting},
// Target: []string{""},
// Refresh: resourceAwsDbProxyTargetRefreshFunc(conn, d.Id()),
// Timeout: d.Timeout(schema.TimeoutDelete),
// }

// _, err = stateChangeConf.WaitForState()
// if err != nil {
// return fmt.Errorf("Error waiting for DB Proxy deletion: %s", err)
// }

return nil
}
8 changes: 4 additions & 4 deletions website/docs/r/db_proxy_target.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ resource "aws_db_proxy" "example" {
engine_family = "MYSQL"
idle_client_timeout = 1800
require_tls = true
role_arn = "arn:aws:iam:us-east-1:123456789012:role/example"
vpc_security_group_ids = ["sg-12345678901234567"]
vpc_subnet_ids = ["subnet-12345678901234567"]
role_arn = aws_iam_role.example.arn
vpc_security_group_ids = [aws_security_group.example.id]
vpc_subnet_ids = [aws_subnet.example.id]
auth {
auth_scheme = "SECRETS"
description = "example"
iam_auth = "DISABLED"
secret_arn = "arn:aws:secretsmanager:us-east-1:123456789012:secret:example"
secret_arn = aws_secretsmanager_secret.example.arn
}
tags = {
Expand Down

0 comments on commit e49d0cf

Please sign in to comment.