Skip to content

Commit

Permalink
Merge pull request hashicorp#34925 from EttoreFoti/e-redhisft_serverl…
Browse files Browse the repository at this point in the history
…ess_custom_ports

(feat): add port parameter in aws_redshiftserverless_workgroup
  • Loading branch information
nam054 authored Dec 29, 2023
2 parents 8690dbe + 17a34d6 commit b3c1440
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/34925.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_redshiftserverless_workgroup: Add port parameter
```
21 changes: 21 additions & 0 deletions internal/service/redshiftserverless/workgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ func ResourceWorkgroup() *schema.Resource {
Required: true,
ForceNew: true,
},
"port": {
Type: schema.TypeInt,
Computed: true,
Optional: true,
},
"publicly_accessible": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -219,6 +224,10 @@ func resourceWorkgroupCreate(ctx context.Context, d *schema.ResourceData, meta i
input.EnhancedVpcRouting = aws.Bool(v.(bool))
}

if v, ok := d.GetOk("port"); ok {
input.Port = aws.Int64(int64(v.(int)))
}

if v, ok := d.GetOk("publicly_accessible"); ok {
input.PubliclyAccessible = aws.Bool(v.(bool))
}
Expand Down Expand Up @@ -273,6 +282,7 @@ func resourceWorkgroupRead(ctx context.Context, d *schema.ResourceData, meta int
}
d.Set("enhanced_vpc_routing", out.EnhancedVpcRouting)
d.Set("namespace_name", out.NamespaceName)
d.Set("port", flattenEndpoint(out.Endpoint)["port"])
d.Set("publicly_accessible", out.PubliclyAccessible)
d.Set("security_group_ids", flex.FlattenStringSet(out.SecurityGroupIds))
d.Set("subnet_ids", flex.FlattenStringSet(out.SubnetIds))
Expand Down Expand Up @@ -321,6 +331,17 @@ func resourceWorkgroupUpdate(ctx context.Context, d *schema.ResourceData, meta i
}
}

if d.HasChange("port") {
input := &redshiftserverless.UpdateWorkgroupInput{
Port: aws.Int64(int64(d.Get("port").(int))),
WorkgroupName: aws.String(d.Id()),
}

if err := updateWorkgroup(ctx, conn, input, d.Timeout(schema.TimeoutUpdate)); err != nil {
return sdkdiag.AppendFromErr(diags, err)
}
}

if d.HasChange("publicly_accessible") {
input := &redshiftserverless.UpdateWorkgroupInput{
PubliclyAccessible: aws.Bool(d.Get("publicly_accessible").(bool)),
Expand Down
41 changes: 41 additions & 0 deletions internal/service/redshiftserverless/workgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,33 @@ func TestAccRedshiftServerlessWorkgroup_disappears(t *testing.T) {
})
}

func TestAccRedshiftServerlessWorkgroup_port(t *testing.T) {
ctx := acctest.Context(t)
resourceName := "aws_redshiftserverless_workgroup.test"
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, redshiftserverless.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckWorkgroupDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccWorkgroupConfig_port(rName, 8191),
Check: resource.ComposeTestCheckFunc(
testAccCheckWorkgroupExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, "port", "8191"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCheckWorkgroupDestroy(ctx context.Context) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := acctest.Provider.Meta().(*conns.AWSClient).RedshiftServerlessConn(ctx)
Expand Down Expand Up @@ -415,3 +442,17 @@ resource "aws_redshiftserverless_workgroup" "test" {
}
`, rName, tagKey1, tagValue1, tagKey2, tagValue2)
}

func testAccWorkgroupConfig_port(rName string, port int) string {
return fmt.Sprintf(`
resource "aws_redshiftserverless_namespace" "test" {
namespace_name = %[1]q
}
resource "aws_redshiftserverless_workgroup" "test" {
namespace_name = aws_redshiftserverless_namespace.test.namespace_name
workgroup_name = %[1]q
port = %[2]d
}
`, rName, port)
}
1 change: 1 addition & 0 deletions website/docs/r/redshiftserverless_workgroup.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The following arguments are optional:
* `base_capacity` - (Optional) The base data warehouse capacity of the workgroup in Redshift Processing Units (RPUs).
* `config_parameter` - (Optional) An array of parameters to set for more control over a serverless database. See `Config Parameter` below.
* `enhanced_vpc_routing` - (Optional) The value that specifies whether to turn on enhanced virtual private cloud (VPC) routing, which forces Amazon Redshift Serverless to route traffic through your VPC instead of over the internet.
* `port` - (Optional) The port number on which the cluster accepts incoming connections.
* `publicly_accessible` - (Optional) A value that specifies whether the workgroup can be accessed from a public network.
* `security_group_ids` - (Optional) An array of security group IDs to associate with the workgroup.
* `subnet_ids` - (Optional) An array of VPC subnet IDs to associate with the workgroup. When set, must contain at least three subnets spanning three Availability Zones. A minimum number of IP addresses is required and scales with the Base Capacity. For more information, see the following [AWS document](https://docs.aws.amazon.com/redshift/latest/mgmt/serverless-known-issues.html).
Expand Down

0 comments on commit b3c1440

Please sign in to comment.