From e49d0cf09b56556c1ebf66478189128af62dd0df Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Wed, 30 Sep 2020 12:50:47 -0400 Subject: [PATCH] resource/aws_db_proxy_target: Apply suggestions from code review --- aws/resource_aws_db_proxy_target.go | 36 ++++---------------- website/docs/r/db_proxy_target.html.markdown | 8 ++--- 2 files changed, 11 insertions(+), 33 deletions(-) diff --git a/aws/resource_aws_db_proxy_target.go b/aws/resource_aws_db_proxy_target.go index 25492d3267a..1e501c446f1 100644 --- a/aws/resource_aws_db_proxy_target.go +++ b/aws/resource_aws_db_proxy_target.go @@ -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) } @@ -155,28 +143,30 @@ func resourceAwsDbProxyTargetRead(d *schema.ResourceData, meta interface{}) erro resp, err := conn.DescribeDBProxyTargets(¶ms) 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) @@ -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 } diff --git a/website/docs/r/db_proxy_target.html.markdown b/website/docs/r/db_proxy_target.html.markdown index f3fdae2c611..726269a9b9f 100644 --- a/website/docs/r/db_proxy_target.html.markdown +++ b/website/docs/r/db_proxy_target.html.markdown @@ -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 = {