Skip to content
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
13 changes: 13 additions & 0 deletions docs/data-sources/global_connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ data dbtcloud_global_connection my_connection {
- `snowflake` (Attributes) Snowflake connection configuration (see [below for nested schema](#nestedatt--snowflake))
- `starburst` (Attributes) Starburst/Trino connection configuration. (see [below for nested schema](#nestedatt--starburst))
- `synapse` (Attributes) Azure Synapse Analytics connection configuration. (see [below for nested schema](#nestedatt--synapse))
- `teradata` (Attributes) Teradata connection configuration. (see [below for nested schema](#nestedatt--teradata))

<a id="nestedatt--apache_spark"></a>
### Nested Schema for `apache_spark`
Expand Down Expand Up @@ -222,3 +223,15 @@ Read-Only:
- `port` (Number) The port to connect to for this connection. Default=1433
- `query_timeout` (Number) The number of seconds used to wait for a query before failing. Defaults to 0, which means that the timeout is disabled or uses the default system settings.
- `retries` (Number) The number of automatic times to retry a query before failing. Defaults to 1. Queries with syntax errors will not be retried. This setting can be used to overcome intermittent network issues.


<a id="nestedatt--teradata"></a>
### Nested Schema for `teradata`

Read-Only:

- `host` (String) The hostname of the database.
- `port` (String) The port to connect to for this connection. Default=1025
- `request_timeout` (Number) The number of seconds used to establish a connection before failing. Defaults to 0, which means that the timeout is disabled or uses the default system settings.
- `retries` (Number) The number of automatic times to retry a query before failing. Defaults to 1. Queries with syntax errors will not be retried. This setting can be used to overcome intermittent network issues.
- `tmode` (String) The transaction mode to use for the connection.
29 changes: 29 additions & 0 deletions docs/data-sources/teradata_credential.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "dbtcloud_teradata_credential Data Source - dbtcloud"
subcategory: ""
description: |-
Teradata credential data source
---

# dbtcloud_teradata_credential (Data Source)

Teradata credential data source



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

### Required

- `credential_id` (Number) Credential ID
- `project_id` (Number) Project ID

### Read-Only

- `id` (String) The ID of this resource. Contains the project ID and the credential ID.
- `password` (String, Sensitive) The password for the Teradata account
- `schema` (String) The schema where to create models
- `threads` (Number) The number of threads to use. Default is 1
- `user` (String) The username for the Teradata account
16 changes: 16 additions & 0 deletions docs/resources/global_connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ resource "dbtcloud_global_connection" "synapse" {
- `snowflake` (Attributes) Snowflake connection configuration (see [below for nested schema](#nestedatt--snowflake))
- `starburst` (Attributes) Starburst/Trino connection configuration. (see [below for nested schema](#nestedatt--starburst))
- `synapse` (Attributes) Azure Synapse Analytics connection configuration. (see [below for nested schema](#nestedatt--synapse))
- `teradata` (Attributes) Teradata connection configuration. (see [below for nested schema](#nestedatt--teradata))

### Read-Only

Expand Down Expand Up @@ -381,6 +382,21 @@ Optional:
- `query_timeout` (Number) The number of seconds used to wait for a query before failing. Defaults to 0, which means that the timeout is disabled or uses the default system settings.
- `retries` (Number) The number of automatic times to retry a query before failing. Defaults to 1. Queries with syntax errors will not be retried. This setting can be used to overcome intermittent network issues.


<a id="nestedatt--teradata"></a>
### Nested Schema for `teradata`

Required:

- `host` (String) The hostname of the database.
- `tmode` (String) The transaction mode to use for the connection.

Optional:

- `port` (String) The port to connect to for this connection. Default=1025
- `request_timeout` (Number) The number of seconds used to establish a connection before failing. Defaults to 0, which means that the timeout is disabled or uses the default system settings.
- `retries` (Number) The number of automatic times to retry a query before failing. Defaults to 1. Queries with syntax errors will not be retried. This setting can be used to overcome intermittent network issues.

## Import

Import is supported using the following syntax:
Expand Down
32 changes: 32 additions & 0 deletions docs/resources/teradata_credential.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
page_title: "dbtcloud_teradata_credential Resource - dbtcloud"
subcategory: ""
description: |-
Teradata credential resource
---

# dbtcloud_teradata_credential (Resource)


Teradata credential resource



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

### Required

- `password` (String, Sensitive) The password for the Teradata account
- `project_id` (Number) Project ID to create the Teradata/Trino credential in
- `schema` (String) The schema where to create models
- `user` (String) The username for the Teradata account

### Optional

- `threads` (Number) The number of threads to use. Default is 1

### Read-Only

- `credential_id` (Number) The internal credential ID
- `id` (String) The ID of this resource. Contains the project ID and the credential ID.
12 changes: 12 additions & 0 deletions pkg/dbt_cloud/global_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,15 @@ type ApacheSparkConfig struct {
func (ApacheSparkConfig) AdapterVersion() string {
return "apache_spark_v0"
}

type TeradataConfig struct {
Port *string `json:"port,omitempty"`
TMode *string `json:"tmode,omitempty"`
Host *string `json:"host,omitempty"`
Retries *int64 `json:"retries,omitempty"`
RequestTimeout *int64 `json:"request_timeout,omitempty"`
}

func (TeradataConfig) AdapterVersion() string {
return "teradata_v0"
}
243 changes: 243 additions & 0 deletions pkg/dbt_cloud/teradata_credential.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
package dbt_cloud

import (
"context"
"encoding/json"
"fmt"
"net/http"
"strings"

"github.com/hashicorp/terraform-plugin-log/tflog"
)

type TeradataCredentialResponse struct {
Data TeradataCredentialData `json:"data"`
Status ResponseStatus `json:"status"`
}

type TeradataUnencryptedCredentialDetails struct {
Schema string `json:"schema"`
TargetName string `json:"target_name"`
Threads int `json:"threads"`
}

// TeradataCredentialData represents the data returned by the API for an Teradata credential
type TeradataCredentialData struct {
ID *int `json:"id"`
AccountID int `json:"account_id"`
Threads int `json:"threads"`
TargetName string `json:"target_name"`
AdapterID int `json:"adapter_id"`
AdapterVersion string `json:"adapter_version,omitempty"`
UnencryptedCredentialDetails TeradataUnencryptedCredentialDetails `json:"unencrypted_credential_details"`
}

// TeradataCredentialRequest is used for creating and updating Teradata credentials
// It doesn't include the UnencryptedCredentialDetails field which is only returned by the API
type TeradataCredentialRequest struct {
ID *int `json:"id,omitempty"`
AccountID int `json:"account_id"`
ProjectID int `json:"project_id"`
Type string `json:"type"`
State int `json:"state"`
Threads int `json:"threads"`
TargetName string `json:"target_name"`
AdapterID int `json:"adapter_id,omitempty"`
AdapterVersion string `json:"adapter_version,omitempty"`
CredentialDetails AdapterCredentialDetails `json:"credential_details"`
}

func (c *Client) GetTeradataCredential(
projectId int,
credentialId int,
) (*TeradataCredentialData, error) {
req, err := http.NewRequest(
"GET",
fmt.Sprintf(
"%s/v3/accounts/%d/projects/%d/credentials/%d/?include_related=[adapter]",
c.HostURL,
c.AccountID,
projectId,
credentialId,
),
nil,
)
if err != nil {
return nil, err
}

body, err := c.doRequest(req)
if err != nil {
return nil, err
}

credentialResponse := TeradataCredentialResponse{}
err = json.Unmarshal(body, &credentialResponse)
if err != nil {
return nil, err
}

return &credentialResponse.Data, nil
}

func (c *Client) CreateTeradataCredential(
ctx context.Context,
projectId int,
username string,
password string,
schema string,
threads int,
) (*TeradataCredentialData, error) {
credentialDetails, err := GenerateTeradataCredentialDetails(
username,
password,
schema,
threads,
)
if err != nil {
return nil, err
}

credential := TeradataCredentialRequest{
ID: nil,
AccountID: c.AccountID,
ProjectID: projectId,
Type: "adapter",
State: STATE_ACTIVE,
TargetName: DEFAULT_TARGET_NAME,
Threads: threads,
CredentialDetails: credentialDetails,
AdapterVersion: "teradata_v0",
}

rb, err := json.Marshal(credential)
if err != nil {
return nil, err
}
tflog.Debug(ctx, fmt.Sprintf("CreateTeradataCredential: %s", string(rb)))

req, err := http.NewRequest(
"POST",
fmt.Sprintf(
"%s/v3/accounts/%d/projects/%d/credentials/",
c.HostURL,
c.AccountID,
projectId,
),
strings.NewReader(string(rb)),
)
if err != nil {
return nil, err
}

body, err := c.doRequest(req)
if err != nil {
return nil, err
}

tflog.Debug(ctx, fmt.Sprintf("CreateTeradataCredentialResponse: %s", string(body)))

credentialResponse := TeradataCredentialResponse{}
err = json.Unmarshal(body, &credentialResponse)
if err != nil {
return nil, err
}

return &credentialResponse.Data, nil
}

func (c *Client) UpdateTeradataCredential(
projectId int,
credentialId int,
teradataCredential TeradataCredentialRequest,
) (*TeradataCredentialData, error) {
rb, err := json.Marshal(teradataCredential)
if err != nil {
return nil, err
}

req, err := http.NewRequest(
"POST",
fmt.Sprintf(
"%s/v3/accounts/%d/projects/%d/credentials/%d/",
c.HostURL,
c.AccountID,
projectId,
credentialId,
),
strings.NewReader(string(rb)),
)
if err != nil {
return nil, err
}

body, err := c.doRequest(req)
if err != nil {
return nil, err
}

credentialResponse := TeradataCredentialResponse{}
err = json.Unmarshal(body, &credentialResponse)
if err != nil {
return nil, err
}

return &credentialResponse.Data, nil
}

func GenerateTeradataCredentialDetails(
username string,
password string,
schema string,
threads int,
) (AdapterCredentialDetails, error) {
// Create the credential details structure based on the payload example
fields := map[string]AdapterCredentialField{
"user": {
Metadata: AdapterCredentialFieldMetadata{
Label: "Teradata username",
Description: "The username",
Field_Type: "text",
Encrypt: false,
Overrideable: false,
Validation: AdapterCredentialFieldMetadataValidation{Required: true},
},
Value: username,
},
"password": {
Metadata: AdapterCredentialFieldMetadata{
Label: "Teradata password",
Description: "User's password",
Field_Type: "text",
Encrypt: true,
Overrideable: false,
Validation: AdapterCredentialFieldMetadataValidation{Required: true},
},
Value: password,
},
"schema": {
Metadata: AdapterCredentialFieldMetadata{
Label: "Schema",
Description: "The schema to build models into",
Field_Type: "text",
Encrypt: false,
Overrideable: false,
Validation: AdapterCredentialFieldMetadataValidation{Required: true},
},
Value: schema,
},
"threads": {
Metadata: AdapterCredentialFieldMetadata{
Label: "Threads",
Description: "The number of threads to use for dbt operations",
Field_Type: "number",
Encrypt: false,
Overrideable: false,
Validation: AdapterCredentialFieldMetadataValidation{Required: true},
},
Value: threads,
},
}

return AdapterCredentialDetails{Fields: fields}, nil
}
Loading
Loading