Skip to content
Open
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
9 changes: 9 additions & 0 deletions docs/resources/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ resource "redshift_database" "datashare_db" {
- `connection_limit` (Number) The maximum number of concurrent connections that can be made to this database. A value of -1 means no limit.
- `datashare_source` (Block List, Max: 1) Configuration for creating a database from a redshift datashare. (see [below for nested schema](#nestedblock--datashare_source))
- `owner` (String) Owner of the database, usually the user who created it
- `zeroetl_integration` (Block List, Max: 1) Configuration for creating a database from a zero ETL integration. (see [below for nested schema](#nestedblock--zeroetl_integration))

### Read-Only

Expand All @@ -69,3 +70,11 @@ Optional:

- `account_id` (String) The AWS account ID of the producer cluster.
- `with_permissions` (Boolean) Whether the database requires object-level permissions to access individual database objects


<a id="nestedblock--zeroetl_integration"></a>
### Nested Schema for `zeroetl_integration`

Required:

- `integration_id` (String) The unique identifier of the zero ETL integration
34 changes: 30 additions & 4 deletions redshift/resource_redshift_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const databaseDatashareSourceShareNameAttr = "share_name"
const databaseDatashareSourceNamespaceAttr = "namespace"
const databaseDatashareSourceAccountAttr = "account_id"
const databaseDatashareSourceWithPermissions = "with_permissions"
const databaseZeroETLIntegrationAttr = "zeroetl_integration"
const databaseZeroETLIntegrationIdAttr = "integration_id"

func redshiftDatabase() *schema.Resource {
return &schema.Resource{
Expand Down Expand Up @@ -55,10 +57,11 @@ func redshiftDatabase() *schema.Resource {
ValidateFunc: validation.IntAtLeast(-1),
},
databaseDatashareSourceAttr: {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: "Configuration for creating a database from a redshift datashare.",
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: "Configuration for creating a database from a redshift datashare.",
ExactlyOneOf: []string{databaseDatashareSourceAttr, databaseZeroETLIntegrationAttr},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
databaseDatashareSourceShareNameAttr: {
Expand Down Expand Up @@ -97,6 +100,23 @@ func redshiftDatabase() *schema.Resource {
},
},
},
databaseZeroETLIntegrationAttr: {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: "Configuration for creating a database from a zero ETL integration.",
ExactlyOneOf: []string{databaseDatashareSourceAttr, databaseZeroETLIntegrationAttr},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
databaseZeroETLIntegrationIdAttr: {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The unique identifier of the zero ETL integration",
},
},
},
},
},
}
}
Expand Down Expand Up @@ -174,6 +194,12 @@ func resourceRedshiftDatabaseCreateInternal(db *DBConnection, d *schema.Resource
dbName := d.Get(databaseNameAttr).(string)
query := fmt.Sprintf("CREATE DATABASE %s", pq.QuoteIdentifier(dbName))

// Handle Zero ETL integration source if specified
if _, isZeroETLIntegration := d.GetOk(fmt.Sprintf("%s.0.%s", databaseZeroETLIntegrationAttr, databaseZeroETLIntegrationIdAttr)); isZeroETLIntegration {
integrationId := d.Get(fmt.Sprintf("%s.0.%s", databaseZeroETLIntegrationAttr, databaseZeroETLIntegrationIdAttr)).(string)
query = fmt.Sprintf("%s FROM INTEGRATION %s", query, pq.QuoteLiteral(integrationId))
}

if v, ok := d.GetOk(databaseOwnerAttr); ok {
query = fmt.Sprintf("%s OWNER %s", query, pq.QuoteIdentifier(v.(string)))
}
Expand Down