diff --git a/.changelog/34925.txt b/.changelog/34925.txt new file mode 100644 index 00000000000..6c13c1e00c2 --- /dev/null +++ b/.changelog/34925.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_redshiftserverless_workgroup: Add port parameter +``` \ No newline at end of file diff --git a/internal/service/redshiftserverless/workgroup.go b/internal/service/redshiftserverless/workgroup.go index 74a4727d0fd..c75323965af 100644 --- a/internal/service/redshiftserverless/workgroup.go +++ b/internal/service/redshiftserverless/workgroup.go @@ -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, @@ -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)) } @@ -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)) @@ -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)), diff --git a/internal/service/redshiftserverless/workgroup_test.go b/internal/service/redshiftserverless/workgroup_test.go index 8de013e8c28..718e6fb5290 100644 --- a/internal/service/redshiftserverless/workgroup_test.go +++ b/internal/service/redshiftserverless/workgroup_test.go @@ -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) @@ -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) +} diff --git a/website/docs/r/redshiftserverless_workgroup.html.markdown b/website/docs/r/redshiftserverless_workgroup.html.markdown index 778c09933f8..688e188be92 100644 --- a/website/docs/r/redshiftserverless_workgroup.html.markdown +++ b/website/docs/r/redshiftserverless_workgroup.html.markdown @@ -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).