Skip to content

Commit

Permalink
Merge pull request #38997 from hashicorp/b-rds-cluster-enable-http-en…
Browse files Browse the repository at this point in the history
…dpoint

aws_rds_cluster: Fix Data API for serverlessv2
  • Loading branch information
YakDriver authored Aug 22, 2024
2 parents 82a8eaf + 9f33cb2 commit 1bd56af
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/38997.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_rds_cluster: Allow Web Service Data API (`enabled_http_endpoint`) to be enabled and disabled for `provisioned` engine mode and serverlessv2
```
44 changes: 43 additions & 1 deletion internal/service/rds/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,17 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter
func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) (diags diag.Diagnostics) {
conn := meta.(*conns.AWSClient).RDSClient(ctx)

// There are two ways to enable the HTTP endpoint: new way and old way.
// This is the new way for provisioned engine mode (covers provisioned and serverlessv2).
// The old way is modifying the DB cluster and setting the EnableHttpEndpoint field (below).
// Both need a wait for update so when it's provisioned it will do old (not necessary but does the wait) & new ways, otherwise just old way.
if d.HasChange("enable_http_endpoint") && d.Get("engine_mode").(string) == engineModeProvisioned {
o, n := d.GetChange("enable_http_endpoint")
if err := enableHTTPEndpointProvisioned(ctx, conn, d.Get(names.AttrARN).(string), o, n); err != nil {
return sdkdiag.AppendErrorf(diags, "enabling HTTP endpoint for RDS Cluster (%s): %s", d.Id(), err)
}
}

if d.HasChangesExcept(
names.AttrAllowMajorVersionUpgrade,
"delete_automated_backups",
Expand Down Expand Up @@ -1452,7 +1463,8 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta int
input.EnableGlobalWriteForwarding = aws.Bool(d.Get("enable_global_write_forwarding").(bool))
}

if d.HasChange("enable_http_endpoint") {
// for provisioned and serverlessv2 (also "provisioned"), data api must be enabled using conn.EnableHttpEndpoint() as below
if d.HasChange("enable_http_endpoint") && d.Get("engine_mode").(string) != engineModeProvisioned {
input.EnableHttpEndpoint = aws.Bool(d.Get("enable_http_endpoint").(bool))
}

Expand Down Expand Up @@ -1751,6 +1763,36 @@ func resourceClusterImport(_ context.Context, d *schema.ResourceData, meta inter
return []*schema.ResourceData{d}, nil
}

func enableHTTPEndpointProvisioned(ctx context.Context, conn *rds.Client, arn string, o, n interface{}) error {
if o == nil {
return nil
}

if n == nil {
return nil
}

if !o.(bool) && n.(bool) {
_, err := conn.EnableHttpEndpoint(ctx, &rds.EnableHttpEndpointInput{
ResourceArn: aws.String(arn),
})
if err != nil {
return err
}
}

if o.(bool) && !n.(bool) {
_, err := conn.DisableHttpEndpoint(ctx, &rds.DisableHttpEndpointInput{
ResourceArn: aws.String(arn),
})
if err != nil {
return err
}
}

return nil
}

func addIAMRoleToCluster(ctx context.Context, conn *rds.Client, clusterID, roleARN string) error {
input := &rds.AddRoleToDBClusterInput{
DBClusterIdentifier: aws.String(clusterID),
Expand Down
21 changes: 21 additions & 0 deletions internal/service/rds/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2556,6 +2556,13 @@ func TestAccRDSCluster_enableHTTPEndpoint(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "enable_http_endpoint", acctest.CtFalse),
),
},
{
Config: testAccClusterConfig_enableHTTPEndpoint(rName, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckClusterExists(ctx, resourceName, &dbCluster),
resource.TestCheckResourceAttr(resourceName, "enable_http_endpoint", acctest.CtTrue),
),
},
},
})
}
Expand All @@ -2581,6 +2588,20 @@ func TestAccRDSCluster_enableHTTPEndpointProvisioned(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "enable_http_endpoint", acctest.CtTrue),
),
},
{
Config: testAccClusterConfig_enableHTTPEndpointProvisioned(rName, false),
Check: resource.ComposeTestCheckFunc(
testAccCheckClusterExists(ctx, resourceName, &dbCluster),
resource.TestCheckResourceAttr(resourceName, "enable_http_endpoint", acctest.CtFalse),
),
},
{
Config: testAccClusterConfig_enableHTTPEndpointProvisioned(rName, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckClusterExists(ctx, resourceName, &dbCluster),
resource.TestCheckResourceAttr(resourceName, "enable_http_endpoint", acctest.CtTrue),
),
},
},
})
}
Expand Down

0 comments on commit 1bd56af

Please sign in to comment.