Skip to content

Commit ec54988

Browse files
add connection_type: PostgreSQL (#45)
* fix connection.md * add postgresql.tf * fix connection.go * fix connection_resource.go * fix connection.md * fix connection.go * fix error * remove recent change * remove recent change * connection.md * fix connection.go * fix * fix * fix enum value * fix * add connection.md.tmpl * fix validation * fix connection.md --------- Co-authored-by: kkatamot <[email protected]>
1 parent 834d68b commit ec54988

File tree

5 files changed

+199
-33
lines changed

5 files changed

+199
-33
lines changed

docs/resources/connection.md

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ resource "trocco_connection" "bigquery" {
3232
}
3333
```
3434

35-
### Snowflake
35+
### Snowflake
3636

3737
```terraform
3838
resource "trocco_connection" "snowflake" {
@@ -161,18 +161,20 @@ resource "trocco_connection" "s3_with_assume_role" {
161161
- `aws_auth_type` (String) S3: The authentication type for the S3 connection. It must be one of `iam_user` or `assume_role`.
162162
- `aws_iam_user` (Attributes) S3: IAM User configuration. (see [below for nested schema](#nestedatt--aws_iam_user))
163163
- `description` (String) The description of the connection.
164-
- `gateway` (Attributes) MySQL: Whether to connect via SSH (see [below for nested schema](#nestedatt--gateway))
165-
- `host` (String) Snowflake: The host of a Snowflake account.
166-
- `password` (String, Sensitive) Snowflake: The password for the Snowflake user.
167-
- `port` (Number) MySQL: The port of the MySQL server.
164+
- `driver` (String) PostgreSQL: The name of a PostgreSQL driver.
165+
- `gateway` (Attributes) MySQL, PostgreSQL: Whether to connect via SSH (see [below for nested schema](#nestedatt--gateway))
166+
- `host` (String) Snowflake, PostgreSQL: The host of a (Snowflake, PostgreSQL) account.
167+
- `password` (String, Sensitive) Snowflake, PostgreSQL: The password for the (Snowflake, PostgreSQL) user.
168+
- `port` (Number) MySQL, PostgreSQL: The port of the (MySQL, PostgreSQL) server.
168169
- `private_key` (String, Sensitive) Snowflake: A private key for the Snowflake user.
169170
- `project_id` (String) BigQuery, GCS: A GCP project ID.
170171
- `resource_group_id` (Number) The ID of the resource group the connection belongs to.
171172
- `role` (String) Snowflake: A role attached to the Snowflake user.
172173
- `service_account_email` (String, Sensitive) GCS: A GCP service account email.
173174
- `service_account_json_key` (String, Sensitive) BigQuery: A GCP service account key.
174-
- `ssl` (Attributes) MySQL: SSL configuration. (see [below for nested schema](#nestedatt--ssl))
175-
- `user_name` (String) Snowflake: The name of a Snowflake user.
175+
- `ssl` (Attributes) MySQL, PostgreSQL: SSL configuration. (see [below for nested schema](#nestedatt--ssl))
176+
- `ssl_mode` (String) PostgreSQL: SSL connection mode.
177+
- `user_name` (String) Snowflake, PostgreSQL: The name of a (Snowflake, PostgreSQL) user.
176178

177179
### Read-Only
178180

@@ -201,26 +203,72 @@ Optional:
201203

202204
Optional:
203205

204-
- `host` (String, Sensitive) MySQL: SSH Host
205-
- `key` (String, Sensitive) MySQL: SSH Private Key
206-
- `key_passphrase` (String, Sensitive) MySQL: SSH Private Key Passphrase
207-
- `password` (String, Sensitive) MySQL: SSH Password
208-
- `port` (Number, Sensitive) MySQL: SSH Port
209-
- `user_name` (String, Sensitive) MySQL: SSH User
206+
- `host` (String, Sensitive) MySQL, PostgreSQL: SSH Host
207+
- `key` (String, Sensitive) MySQL, PostgreSQL: SSH Private Key
208+
- `key_passphrase` (String, Sensitive) MySQL, PostgreSQL: SSH Private Key Passphrase
209+
- `password` (String, Sensitive) MySQL, PostgreSQL: SSH Password
210+
- `port` (Number, Sensitive) MySQL, PostgreSQL: SSH Port
211+
- `user_name` (String, Sensitive) MySQL, PostgreSQL: SSH User
210212

211213

212214
<a id="nestedatt--ssl"></a>
213215
### Nested Schema for `ssl`
214216

215217
Optional:
216218

217-
- `ca` (String, Sensitive) MySQL: CA certificate
218-
- `cert` (String, Sensitive) MySQL: Certificate (CRT file)
219-
- `key` (String, Sensitive) MySQL: Key (KEY file)
219+
- `ca` (String, Sensitive) MySQL, PostgreSQL: CA certificate
220+
- `cert` (String, Sensitive) MySQL, PostgreSQL: Certificate (CRT file)
221+
- `key` (String, Sensitive) MySQL, PostgreSQL: Key (KEY file)
220222

221223

222224

223225

226+
### PostgreSQL
227+
228+
```terraform
229+
resource "trocco_connection" "postgresql" {
230+
connection_type = "postgresql"
231+
name = "PostgreSQL Example"
232+
description = "This is a PostgreSQL connection example"
233+
host = "db.example.com"
234+
port = 5432
235+
user_name = "root"
236+
password = "password"
237+
ssl_mode = "require"
238+
driver = "postgresql_42_5_1"
239+
ssl = {
240+
ca = <<-SSL_CA
241+
-----BEGIN PRIVATE KEY-----
242+
...SSL CA...
243+
-----END PRIVATE KEY-----
244+
SSL_CA
245+
cert = <<-SSL_CERT
246+
-----BEGIN CERTIFICATE-----
247+
...SSL CRT...
248+
-----END CERTIFICATE-----
249+
SSL_CERT
250+
key = <<-SSL_KEY
251+
-----BEGIN PRIVATE KEY-----
252+
...SSL KEY...
253+
-----END PRIVATE KEY-----
254+
SSL_KEY
255+
}
256+
gateway = {
257+
host = "gateway.example.com"
258+
port = 1234
259+
user_name = "gateway-joe"
260+
password = "gateway-joepass"
261+
key = <<-GATEWAY_KEY
262+
-----BEGIN PRIVATE KEY-----
263+
... GATEWAY KEY...
264+
-----END PRIVATE KEY-----
265+
GATEWAY_KEY
266+
key_passphrase = "sample_passphrase"
267+
}
268+
resource_group_id = 1
269+
}
270+
```
271+
224272
## Import
225273

226274
Import is supported using the following syntax:
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
resource "trocco_connection" "postgresql" {
2+
connection_type = "postgresql"
3+
name = "PostgreSQL Example"
4+
description = "This is a PostgreSQL connection example"
5+
host = "db.example.com"
6+
port = 5432
7+
user_name = "root"
8+
password = "password"
9+
ssl_mode = "require"
10+
driver = "postgresql_42_5_1"
11+
ssl = {
12+
ca = <<-SSL_CA
13+
-----BEGIN PRIVATE KEY-----
14+
...SSL CA...
15+
-----END PRIVATE KEY-----
16+
SSL_CA
17+
cert = <<-SSL_CERT
18+
-----BEGIN CERTIFICATE-----
19+
...SSL CRT...
20+
-----END CERTIFICATE-----
21+
SSL_CERT
22+
key = <<-SSL_KEY
23+
-----BEGIN PRIVATE KEY-----
24+
...SSL KEY...
25+
-----END PRIVATE KEY-----
26+
SSL_KEY
27+
}
28+
gateway = {
29+
host = "gateway.example.com"
30+
port = 1234
31+
user_name = "gateway-joe"
32+
password = "gateway-joepass"
33+
key = <<-GATEWAY_KEY
34+
-----BEGIN PRIVATE KEY-----
35+
... GATEWAY KEY...
36+
-----END PRIVATE KEY-----
37+
GATEWAY_KEY
38+
key_passphrase = "sample_passphrase"
39+
}
40+
resource_group_id = 1
41+
}

internal/client/connection.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ type Connection struct {
4848
AWSSecretAccessKey *string `json:"aws_secret_access_key,omitempty"`
4949
AWSAssumeRoleAccountID *string `json:"aws_assume_role_account_id,omitempty"`
5050
AWSAssumeRoleName *string `json:"aws_assume_role_name,omitempty"`
51+
52+
// PostgreSQL Fields
53+
SSLMode *string `json:"ssl_mode,omitempty"`
5154
}
5255

5356
type GetConnectionsInput struct {
@@ -97,6 +100,12 @@ type CreateConnectionInput struct {
97100
AWSSecretAccessKey *string `json:"aws_secret_access_key,omitempty"`
98101
AWSAssumeRoleAccountID *string `json:"aws_assume_role_account_id,omitempty"`
99102
AWSAssumeRoleName *string `json:"aws_assume_role_name,omitempty"`
103+
104+
// PostgreSQL Fields
105+
SSLClientCa *string `json:"ssl_client_ca,omitempty"`
106+
SSLClientKey *string `json:"ssl_client_key,omitempty"`
107+
SSLMode *string `json:"ssl_mode,omitempty"`
108+
Driver *string `json:"driver,omitempty"`
100109
}
101110

102111
type UpdateConnectionInput struct {
@@ -141,6 +150,12 @@ type UpdateConnectionInput struct {
141150
AWSSecretAccessKey *string `json:"aws_secret_access_key,omitempty"`
142151
AWSAssumeRoleAccountID *string `json:"aws_assume_role_account_id,omitempty"`
143152
AWSAssumeRoleName *string `json:"aws_assume_role_name,omitempty"`
153+
154+
// PostgreSQL Fields
155+
SSLClientCa *string `json:"ssl_client_ca,omitempty"`
156+
SSLClientKey *string `json:"ssl_client_key,omitempty"`
157+
SSLMode *string `json:"ssl_mode,omitempty"`
158+
Driver *string `json:"driver,omitempty"`
144159
}
145160

146161
func (c *TroccoClient) GetConnections(connectionType string, in *GetConnectionsInput) (*ConnectionList, error) {

0 commit comments

Comments
 (0)