Skip to content

Commit

Permalink
New Resource: aws_db_proxy_endpoint (#18881)
Browse files Browse the repository at this point in the history
Output from acceptance testing in AWS Commercial:

```
--- PASS: TestAccAWSDBProxyEndpoint_targetRole (1287.78s)
--- PASS: TestAccAWSDBProxyEndpoint_disappears (1299.92s)
--- PASS: TestAccAWSDBProxyEndpoint_disappears_proxy (1306.28s)
--- PASS: TestAccAWSDBProxyEndpoint_tags (1328.11s)
--- PASS: TestAccAWSDBProxyEndpoint_basic (1370.47s)
--- PASS: TestAccAWSDBProxyEndpoint_vpcSecurityGroupIds (1523.22s)
```

Output from acceptance testing in AWS GovCloud (US):

```
--- SKIP: TestAccAWSDBProxyEndpoint_basic (1.88s)
--- SKIP: TestAccAWSDBProxyEndpoint_tags (1.88s)
--- SKIP: TestAccAWSDBProxyEndpoint_vpcSecurityGroupIds (1.88s)
--- SKIP: TestAccAWSDBProxyEndpoint_disappears (1.88s)
--- SKIP: TestAccAWSDBProxyEndpoint_targetRole (1.89s)
--- SKIP: TestAccAWSDBProxyEndpoint_disappears_proxy (1.93s)
```
  • Loading branch information
DrFaust92 authored Apr 29, 2021
1 parent 3998fe1 commit 0783da7
Show file tree
Hide file tree
Showing 9 changed files with 883 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/18881.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
aws_rds_proxy_endpoint
```
35 changes: 34 additions & 1 deletion aws/internal/service/rds/finder/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package finder
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/rds"
tfrds "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/rds"
)

// DBProxyTarget returns matching DBProxyTarget.
func DBProxyTarget(conn *rds.RDS, dbProxyName string, targetGroupName string, targetType string, rdsResourceId string) (*rds.DBProxyTarget, error) {
func DBProxyTarget(conn *rds.RDS, dbProxyName, targetGroupName, targetType, rdsResourceId string) (*rds.DBProxyTarget, error) {
input := &rds.DescribeDBProxyTargetsInput{
DBProxyName: aws.String(dbProxyName),
TargetGroupName: aws.String(targetGroupName),
Expand All @@ -30,3 +31,35 @@ func DBProxyTarget(conn *rds.RDS, dbProxyName string, targetGroupName string, ta

return dbProxyTarget, err
}

// DBProxyEndpoint returns matching DBProxyEndpoint.
func DBProxyEndpoint(conn *rds.RDS, id string) (*rds.DBProxyEndpoint, error) {
dbProxyName, dbProxyEndpointName, err := tfrds.ResourceAwsDbProxyEndpointParseID(id)
if err != nil {
return nil, err
}

input := &rds.DescribeDBProxyEndpointsInput{
DBProxyName: aws.String(dbProxyName),
DBProxyEndpointName: aws.String(dbProxyEndpointName),
}
var dbProxyEndpoint *rds.DBProxyEndpoint

err = conn.DescribeDBProxyEndpointsPages(input, func(page *rds.DescribeDBProxyEndpointsOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}

for _, endpoint := range page.DBProxyEndpoints {
if aws.StringValue(endpoint.DBProxyEndpointName) == dbProxyEndpointName &&
aws.StringValue(endpoint.DBProxyName) == dbProxyName {
dbProxyEndpoint = endpoint
return false
}
}

return !lastPage
})

return dbProxyEndpoint, err
}
14 changes: 14 additions & 0 deletions aws/internal/service/rds/id.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package rds

import (
"fmt"
"strings"
)

func ResourceAwsDbProxyEndpointParseID(id string) (string, string, error) {
idParts := strings.SplitN(id, "/", 2)
if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" {
return "", "", fmt.Errorf("unexpected format of ID (%s), expected db_proxy_name/db_proxy_endpoint_name", id)
}
return idParts[0], idParts[1], nil
}
24 changes: 24 additions & 0 deletions aws/internal/service/rds/waiter/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/rds"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/rds/finder"
)

const (
Expand All @@ -12,6 +13,12 @@ const (

// EventSubscription Unknown
EventSubscriptionStatusUnknown = "Unknown"

// ProxyEndpoint NotFound
ProxyEndpointStatusNotFound = "NotFound"

// ProxyEndpoint Unknown
ProxyEndpointStatusUnknown = "Unknown"
)

// EventSubscriptionStatus fetches the EventSubscription and its Status
Expand All @@ -34,3 +41,20 @@ func EventSubscriptionStatus(conn *rds.RDS, subscriptionName string) resource.St
return output.EventSubscriptionsList[0], aws.StringValue(output.EventSubscriptionsList[0].Status), nil
}
}

// DBProxyEndpointStatus fetches the ProxyEndpoint and its Status
func DBProxyEndpointStatus(conn *rds.RDS, id string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := finder.DBProxyEndpoint(conn, id)

if err != nil {
return nil, ProxyEndpointStatusUnknown, err
}

if output == nil {
return nil, ProxyEndpointStatusNotFound, nil
}

return output, aws.StringValue(output.Status), nil
}
}
41 changes: 40 additions & 1 deletion aws/internal/service/rds/waiter/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
RdsClusterInitiateUpgradeTimeout = 5 * time.Minute
)

// DeploymentDeployed waits for a EventSubscription to return Deleted
// EventSubscriptionDeleted waits for a EventSubscription to return Deleted
func EventSubscriptionDeleted(conn *rds.RDS, subscriptionName string) (*rds.EventSubscription, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{"deleting"},
Expand All @@ -30,3 +30,42 @@ func EventSubscriptionDeleted(conn *rds.RDS, subscriptionName string) (*rds.Even

return nil, err
}

// DBProxyEndpointAvailable waits for a DBProxyEndpoint to return Available
func DBProxyEndpointAvailable(conn *rds.RDS, id string, timeout time.Duration) (*rds.DBProxyEndpoint, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{
rds.DBProxyEndpointStatusCreating,
rds.DBProxyEndpointStatusModifying,
},
Target: []string{rds.DBProxyEndpointStatusAvailable},
Refresh: DBProxyEndpointStatus(conn, id),
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForState()

if v, ok := outputRaw.(*rds.DBProxyEndpoint); ok {
return v, err
}

return nil, err
}

// DBProxyEndpointDeleted waits for a DBProxyEndpoint to return Deleted
func DBProxyEndpointDeleted(conn *rds.RDS, id string, timeout time.Duration) (*rds.DBProxyEndpoint, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{rds.DBProxyEndpointStatusDeleting},
Target: []string{},
Refresh: DBProxyEndpointStatus(conn, id),
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForState()

if v, ok := outputRaw.(*rds.DBProxyEndpoint); ok {
return v, err
}

return nil, err
}
1 change: 1 addition & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ func Provider() *schema.Provider {
"aws_db_parameter_group": resourceAwsDbParameterGroup(),
"aws_db_proxy": resourceAwsDbProxy(),
"aws_db_proxy_default_target_group": resourceAwsDbProxyDefaultTargetGroup(),
"aws_db_proxy_endpoint": resourceAwsDbProxyEndpoint(),
"aws_db_proxy_target": resourceAwsDbProxyTarget(),
"aws_db_security_group": resourceAwsDbSecurityGroup(),
"aws_db_snapshot": resourceAwsDbSnapshot(),
Expand Down
Loading

0 comments on commit 0783da7

Please sign in to comment.