-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from trocco-io/feats/connections
Add connection resource
- Loading branch information
Showing
16 changed files
with
1,009 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "trocco_connection Resource - trocco" | ||
subcategory: "" | ||
description: |- | ||
Provides a TROCCO connection resource. | ||
--- | ||
|
||
# trocco_connection (Resource) | ||
|
||
Provides a TROCCO connection resource. | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `connection_type` (String) The type of the connection. It must be one of `bigquery` or `snowflake`. | ||
- `name` (String) The name of the connection. | ||
|
||
### Optional | ||
|
||
- `auth_method` (String) Snowflake: The authentication method for the Snowflake user. It must be one of `key_pair` or `user_password`. | ||
- `description` (String) The description of the connection. | ||
- `host` (String) Snowflake: The host of a Snowflake account. | ||
- `password` (String, Sensitive) Snowflake: The password for the Snowflake user. | ||
- `private_key` (String, Sensitive) Snowflake: A private key for the Snowflake user. | ||
- `project_id` (String) BigQuery: A GCP project ID. | ||
- `resource_group_id` (Number) The ID of the resource group the connection belongs to. | ||
- `role` (String) Snowflake: A role attached to the Snowflake user. | ||
- `service_account_json_key` (String, Sensitive) BigQuery: A GCP service account key. | ||
- `user_name` (String) Snowflake: The name of a Snowflake user. | ||
|
||
### Read-Only | ||
|
||
- `id` (Number) The ID of the connection. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
resource "trocco_connection" "bigquery" { | ||
connection_type = "bigquery" | ||
|
||
name = "BigQuery Example" | ||
description = "This is a BigQuery connection example" | ||
|
||
project_id = "example" | ||
service_account_json_key = "{\"type\":\"service_account\", ...}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
terraform import trocco_connection.example <connection_type>,<id> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
resource "trocco_connection" "snowflake" { | ||
connection_type = "snowflake" | ||
|
||
name = "Snowflake Example" | ||
description = "This is a Snowflake connection example" | ||
|
||
host = "exmaple.snowflakecomputing.com" | ||
auth_method = "user_password" | ||
user_name = "<User Name>" | ||
password = "<Password>" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"net/url" | ||
) | ||
|
||
type ConnectionList struct { | ||
Connections []*Connection `json:"connections"` | ||
NextCursor string `json:"next_cursor"` | ||
} | ||
|
||
type Connection struct { | ||
// Common Fields | ||
ID int64 `json:"id"` | ||
Name *string `json:"name"` | ||
Description *string `json:"description"` | ||
ResourceGroupID *int64 `json:"resource_group_id"` | ||
|
||
// BigQuery Fields | ||
ProjectID *string `json:"project_id"` | ||
IsOAuth *bool `json:"is_oauth"` | ||
HasServiceAccountJSONKey *bool `json:"has_service_account_json_key"` | ||
GoogleOAuth2CredentialID *int64 `json:"google_oauth2_credential_id"` | ||
|
||
// Snowflake Fields | ||
Host *string `json:"host"` | ||
UserName *string `json:"user_name"` | ||
Role *string `json:"role"` | ||
AuthMethod *string `json:"auth_method"` | ||
AWSPrivateLinkEnabled *bool `json:"aws_privatelink_enabled"` | ||
Driver *string `json:"driver"` | ||
} | ||
|
||
type GetConnectionsInput struct { | ||
Limit int `json:"limit"` | ||
Cursor string `json:"cursor"` | ||
} | ||
|
||
type CreateConnectionInput struct { | ||
// Common Fields | ||
Name string `json:"name"` | ||
Description *string `json:"description,omitempty"` | ||
ResourceGroupID *NullableInt64 `json:"resource_group_id,omitempty"` | ||
|
||
// BigQuery Fields | ||
ProjectID *string `json:"project_id,omitempty"` | ||
ServiceAccountJSONKey *string `json:"service_account_json_key,omitempty"` | ||
|
||
// Snowflake Fields | ||
Host *string `json:"host,omitempty"` | ||
UserName *string `json:"user_name,omitempty"` | ||
Role *string `json:"role,omitempty"` | ||
AuthMethod *string `json:"auth_method,omitempty"` | ||
Password *string `json:"password,omitempty"` | ||
PrivateKey *string `json:"private_key,omitempty"` | ||
} | ||
|
||
type UpdateConnectionInput struct { | ||
// Common Fields | ||
Name *string `json:"name,omitempty"` | ||
Description *string `json:"description,omitempty"` | ||
ResourceGroupID *NullableInt64 `json:"resource_group_id,omitempty"` | ||
|
||
// BigQuery Fields | ||
ProjectID *string `json:"project_id,omitempty"` | ||
ServiceAccountJSONKey *string `json:"service_account_json_key"` | ||
|
||
// Snowflake Fields | ||
Host *string `json:"host,omitempty"` | ||
UserName *string `json:"user_name,omitempty"` | ||
Role *string `json:"role,omitempty"` | ||
AuthMethod *string `json:"auth_method,omitempty"` | ||
Password *string `json:"password,omitempty"` | ||
PrivateKey *string `json:"private_key,omitempty"` | ||
} | ||
|
||
func (c *TroccoClient) GetConnections(connectionType string, in *GetConnectionsInput) (*ConnectionList, error) { | ||
params := url.Values{} | ||
if in != nil { | ||
if in.Limit != 0 { | ||
params.Add("limit", fmt.Sprintf("%d", in.Limit)) | ||
} | ||
|
||
if in.Cursor != "" { | ||
params.Add("cursor", in.Cursor) | ||
} | ||
} | ||
|
||
out := &ConnectionList{} | ||
if err := c.do( | ||
http.MethodGet, | ||
fmt.Sprintf("/api/connections/%s/?%s", connectionType, params.Encode()), | ||
nil, | ||
out, | ||
); err != nil { | ||
return nil, err | ||
} | ||
return out, nil | ||
} | ||
|
||
func (c *TroccoClient) GetConnection(connectionType string, id int64) (*Connection, error) { | ||
out := &Connection{} | ||
if err := c.do( | ||
http.MethodGet, | ||
fmt.Sprintf("/api/connections/%s/%d", connectionType, id), | ||
nil, | ||
out, | ||
); err != nil { | ||
return nil, err | ||
} | ||
return out, nil | ||
} | ||
|
||
func (c *TroccoClient) CreateConnection(connectionType string, in *CreateConnectionInput) (*Connection, error) { | ||
out := &Connection{} | ||
if err := c.do( | ||
http.MethodPost, | ||
fmt.Sprintf("/api/connections/%s", connectionType), | ||
in, | ||
out, | ||
); err != nil { | ||
return nil, err | ||
} | ||
return out, nil | ||
} | ||
|
||
func (c *TroccoClient) UpdateConnection(connectionType string, id int64, in *UpdateConnectionInput) (*Connection, error) { | ||
out := &Connection{} | ||
if err := c.do( | ||
http.MethodPatch, | ||
fmt.Sprintf("/api/connections/%s/%d", connectionType, id), | ||
in, | ||
out, | ||
); err != nil { | ||
return nil, err | ||
} | ||
return out, nil | ||
} | ||
|
||
func (c *TroccoClient) DeleteConnection(connectionType string, id int64) error { | ||
return c.do( | ||
http.MethodDelete, | ||
fmt.Sprintf("/api/connections/%s/%d", connectionType, id), | ||
nil, | ||
nil, | ||
) | ||
} |
Oops, something went wrong.