Skip to content
This repository was archived by the owner on Jan 17, 2025. It is now read-only.
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
28 changes: 28 additions & 0 deletions docs/data-sources/namespace.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "redshift_namespace Data Source - terraform-provider-redshift"
subcategory: ""
description: |-
Gets the cluster namespace (unique ID) of the Amazon Redshift cluster.
---

# redshift_namespace (Data Source)

Gets the cluster namespace (unique ID) of the Amazon Redshift cluster.

## Example Usage

```terraform
data "redshift_namespace" "namespace" {
# no attributes required. Cluster namespace will be set as the id.
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- **id** (String) The ID of this resource.


3 changes: 3 additions & 0 deletions examples/data-sources/redshift_namespace/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "redshift_namespace" "namespace" {
# no attributes required. Cluster namespace will be set as the id.
}
22 changes: 22 additions & 0 deletions redshift/data_source_redshift_namespace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package redshift

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceRedshiftNamespace() *schema.Resource {
return &schema.Resource{
Description: `Gets the cluster namespace (unique ID) of the Amazon Redshift cluster.`,
Read: RedshiftResourceFunc(dataSourceRedshiftNamespaceRead),
Schema: map[string]*schema.Schema{},
}
}

func dataSourceRedshiftNamespaceRead(db *DBConnection, d *schema.ResourceData) error {
var namespace string
if err := db.QueryRow("SELECT CURRENT_NAMESPACE").Scan(&namespace); err != nil {
return err
}
d.SetId(namespace)
return nil
}
27 changes: 27 additions & 0 deletions redshift/data_source_redshift_namespace_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package redshift

import (
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccDataSourceRedshiftNamespace(t *testing.T) {
uuidRegex := regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$")
config := `
data "redshift_namespace" "namespace" {

}
`
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.TestMatchResourceAttr("data.redshift_namespace.namespace", "id", uuidRegex),
},
},
})
}
9 changes: 5 additions & 4 deletions redshift/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,11 @@ func Provider() *schema.Provider {
"redshift_database": redshiftDatabase(),
},
DataSourcesMap: map[string]*schema.Resource{
"redshift_user": dataSourceRedshiftUser(),
"redshift_group": dataSourceRedshiftGroup(),
"redshift_schema": dataSourceRedshiftSchema(),
"redshift_database": dataSourceRedshiftDatabase(),
"redshift_user": dataSourceRedshiftUser(),
"redshift_group": dataSourceRedshiftGroup(),
"redshift_schema": dataSourceRedshiftSchema(),
"redshift_database": dataSourceRedshiftDatabase(),
"redshift_namespace": dataSourceRedshiftNamespace(),
},
ConfigureFunc: providerConfigure,
}
Expand Down