Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Data Source: aws_redshiftserverless_workgroup #29208

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/29208.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-data-source
aws_redshiftserverless_workgroup
```
4 changes: 4 additions & 0 deletions internal/service/redshiftserverless/service_package_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

141 changes: 141 additions & 0 deletions internal/service/redshiftserverless/workgroup_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package redshiftserverless

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
)

// @SDKDataSource("aws_redshiftserverless_workgroup")
func DataSourceWorkgroup() *schema.Resource {
return &schema.Resource{
ReadWithoutTimeout: dataSourceWorkgroupRead,

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"endpoint": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"address": {
Type: schema.TypeString,
Computed: true,
},
"port": {
Type: schema.TypeInt,
Computed: true,
},
"vpc_endpoint": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"network_interface": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"availability_zone": {
Type: schema.TypeString,
Computed: true,
},
"network_interface_id": {
Type: schema.TypeString,
Computed: true,
},
"private_ip_address": {
Type: schema.TypeString,
Computed: true,
},
"subnet_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"vpc_endpoint_id": {
Type: schema.TypeString,
Computed: true,
},
"vpc_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
},
},
"enhanced_vpc_routing": {
Type: schema.TypeBool,
Computed: true,
},
"namespace_name": {
Type: schema.TypeString,
Computed: true,
},
"publicly_accessible": {
Type: schema.TypeBool,
Computed: true,
},
"security_group_ids": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"subnet_ids": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"workgroup_id": {
Type: schema.TypeString,
Computed: true,
},
"workgroup_name": {
Type: schema.TypeString,
Required: true,
},
},
}
}

func dataSourceWorkgroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).RedshiftServerlessConn()

workgroupName := d.Get("workgroup_name").(string)

resource, err := FindWorkgroupByName(ctx, conn, workgroupName)

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading Redshift Serverless Workgroup (%s): %s", workgroupName, err)
}

d.SetId(workgroupName)
d.Set("arn", resource.WorkgroupArn)
if err := d.Set("endpoint", []interface{}{flattenEndpoint(resource.Endpoint)}); err != nil {
return sdkdiag.AppendErrorf(diags, "setting endpoint: %s", err)
}
d.Set("enhanced_vpc_routing", resource.EnhancedVpcRouting)
d.Set("namespace_name", resource.NamespaceName)
d.Set("publicly_accessible", resource.PubliclyAccessible)
d.Set("security_group_ids", resource.SecurityGroupIds)
d.Set("subnet_ids", resource.SubnetIds)
d.Set("workgroup_id", resource.WorkgroupId)

return diags
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package redshiftserverless_test

import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go/service/redshiftserverless"
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
)

func TestAccRedshiftServerlessWorkgroupDataSource_basic(t *testing.T) {
ctx := acctest.Context(t)
dataSourceName := "data.aws_redshiftserverless_workgroup.test"
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,
Steps: []resource.TestStep{
{
Config: testAccWorkgroupDataSourceConfig_basic(rName),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "endpoint.#", resourceName, "endpoint.#"),
resource.TestCheckResourceAttrPair(dataSourceName, "endpoint.0.address", resourceName, "endpoint.0.address"),
resource.TestCheckResourceAttrPair(dataSourceName, "endpoint.0.port", resourceName, "endpoint.0.port"),
resource.TestCheckResourceAttrPair(dataSourceName, "endpoint.0.port", resourceName, "endpoint.0.port"),
resource.TestCheckResourceAttrPair(dataSourceName, "endpoint.0.vpc_endpoint.#", resourceName, "endpoint.0.vpc_endpoint.#"),
resource.TestCheckResourceAttrPair(dataSourceName, "endpoint.0.vpc_endpoint.0.vpc_endpoint_id", resourceName, "endpoint.0.vpc_endpoint.0.vpc_endpoint_id"),
resource.TestCheckResourceAttrPair(dataSourceName, "endpoint.0.vpc_endpoint.0.vpc_id", resourceName, "endpoint.0.vpc_endpoint.0.vpc_id"),
resource.TestCheckResourceAttrPair(dataSourceName, "endpoint.0.vpc_endpoint.0.network_interface.#", resourceName, "endpoint.0.vpc_endpoint.0.network_interface.#"),
resource.TestCheckResourceAttrPair(dataSourceName, "endpoint.0.vpc_endpoint.0.network_interface.availability_zone", resourceName, "endpoint.0.vpc_endpoint.0.network_interface.availability_zone"),
resource.TestCheckResourceAttrPair(dataSourceName, "endpoint.0.vpc_endpoint.0.network_interface.network_interface_id", resourceName, "endpoint.0.vpc_endpoint.0.network_interface.network_interface_id"),
resource.TestCheckResourceAttrPair(dataSourceName, "endpoint.0.vpc_endpoint.0.network_interface.private_ip_address", resourceName, "endpoint.0.vpc_endpoint.0.network_interface.private_ip_address"),
resource.TestCheckResourceAttrPair(dataSourceName, "endpoint.0.vpc_endpoint.0.network_interface.subnet_id", resourceName, "endpoint.0.vpc_endpoint.0.network_interface.subnet_id"),
resource.TestCheckResourceAttrPair(dataSourceName, "enhanced_vpc_routing", resourceName, "enhanced_vpc_routing"),
resource.TestCheckResourceAttrPair(dataSourceName, "id", resourceName, "id"),
resource.TestCheckResourceAttrPair(dataSourceName, "namespace_name", resourceName, "namespace_name"),
resource.TestCheckResourceAttrPair(dataSourceName, "publicly_accessible", resourceName, "publicly_accessible"),
resource.TestCheckResourceAttrPair(dataSourceName, "security_group_ids.#", resourceName, "security_group_ids.#"),
resource.TestCheckResourceAttrPair(dataSourceName, "subnet_ids.#", resourceName, "subnet_ids.#"),
resource.TestCheckResourceAttrPair(dataSourceName, "workgroup_id", resourceName, "workgroup_id"),
resource.TestCheckResourceAttrPair(dataSourceName, "workgroup_name", resourceName, "workgroup_name"),
),
},
},
})
}

func testAccWorkgroupDataSourceConfig_basic(rName string) 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
}

data "aws_redshiftserverless_workgroup" "test" {
workgroup_name = aws_redshiftserverless_workgroup.test.workgroup_name
}
`, rName)
}
59 changes: 59 additions & 0 deletions website/docs/d/redshiftserverless_workgroup.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
subcategory: "Redshift Serverless"
layout: "aws"
page_title: "AWS: aws_redshiftserverless_workgroup"
description: |-
Terraform data source for managing an AWS Redshift Serverless Workgroup.
---

# Data Source: aws_redshiftserverless_workgroup

Terraform data source for managing an AWS Redshift Serverless Workgroup.

## Example Usage

### Basic Usage

```terraform
data "aws_redshiftserverless_workgroup" "example" {
workgroup_name = aws_redshiftserverless_workgroup.example.workgroup_name
}
```

## Argument Reference

The following arguments are required:

* `workgroup_name` - (Required) The name of the workgroup associated with the database.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

* `arn` - Amazon Resource Name (ARN) of the Redshift Serverless Workgroup.
* `id` - The Redshift Workgroup Name.
* `endpoint` - The endpoint that is created from the workgroup. See `Endpoint` below.
* `enhanced_vpc_routing` - 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.
* `publicly_accessible` - A value that specifies whether the workgroup can be accessed from a public network.
* `security_group_ids` - An array of security group IDs to associate with the workgroup.
* `subnet_ids` - 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).
* `workgroup_id` - The Redshift Workgroup ID.

### Endpoint

* `address` - The DNS address of the VPC endpoint.
* `port` - The port that Amazon Redshift Serverless listens on.
* `vpc_endpoint` - The VPC endpoint or the Redshift Serverless workgroup. See `VPC Endpoint` below.

#### VPC Endpoint

* `vpc_endpoint_id` - The DNS address of the VPC endpoint.
* `vpc_id` - The port that Amazon Redshift Serverless listens on.
* `network_interface` - The network interfaces of the endpoint.. See `Network Interface` below.

##### Network Interface

* `availability_zone` - The availability Zone.
* `network_interface_id` - The unique identifier of the network interface.
* `private_ip_address` - The IPv4 address of the network interface within the subnet.
* `subnet_id` - The unique identifier of the subnet.