Skip to content

Commit a529fb5

Browse files
author
Abdelkarim Boujida
committed
Fix lint issues
1 parent 7e8c8f5 commit a529fb5

9 files changed

Lines changed: 133 additions & 20 deletions

File tree

docs/index.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,3 @@ provider "cloudsqlpostgresql" {
3232

3333
<!-- schema generated by tfplugindocs -->
3434
## Schema
35-
36-
### Optional
37-
38-
- `connection_name` (String) The connection name of the Google Cloud SQL Postgresql instance. The `connection_name` format should be `<project>:<region>:<instance>`
39-
- `password` (String, Sensitive) The password to use to authenticate using the built-in database authentication
40-
- `private_ip` (Boolean) Use the private IP address of the Cloud SQL Postgresql instance to connect to
41-
- `proxy` (String) Proxy socks url if used. Format needs to be `socks5://<ip>:<port>`
42-
- `psc` (Boolean) Use the Private Service Connect endpoint of the Cloud SQL Postgresql instance to connect to
43-
- `ssl_mode` (String) Determine the security of the connection to the Cloud SQL Postgresql instance
44-
- `username` (String) The username to use to authenticate with the Cloud SQL Postgresql instance

docs/resources/default_privileges.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The `cloudsqlpostgresql_default_privileges` resource allows to set the privilege
1717

1818
### Required
1919

20-
- `database` (String) The database
20+
- `connection_config` (Attributes) The connection properties for the Cloud SQL instance. (see [below for nested schema](#nestedatt--connection_config))
2121
- `owner` (String) The target role
2222
- `privileges` (Attributes Set) A list of privileges (see [below for nested schema](#nestedatt--privileges))
2323
- `role` (String) The role
@@ -27,6 +27,24 @@ The `cloudsqlpostgresql_default_privileges` resource allows to set the privilege
2727
- `object_type` (String) The object type, can be `TABLES`, `SEQUENCES`, `FUNCTIONS`, `ROUTINES`, `TYPES` or `SCHEMAS`. Defaults to `TABLES`.
2828
- `schema` (String) The schema
2929

30+
<a id="nestedatt--connection_config"></a>
31+
### Nested Schema for `connection_config`
32+
33+
Required:
34+
35+
- `connection_name` (String) The connection name of the Google Cloud SQL Postgresql instance. The `connection_name` format should be `<project>:<region>:<instance>`
36+
- `password` (String, Sensitive) The password to use to authenticate using the built-in database authentication
37+
- `username` (String) The username to use to authenticate with the Cloud SQL Postgresql instance
38+
39+
Optional:
40+
41+
- `database` (String) The database to connect to. Defaults to `postgres`.
42+
- `private_ip` (Boolean) Use the private IP address of the Cloud SQL Postgresql instance to connect to
43+
- `proxy` (String) Proxy socks url if used. Format needs to be `socks5://<ip>:<port>`
44+
- `psc` (Boolean) Use the Private Service Connect endpoint of the Cloud SQL Postgresql instance to connect to
45+
- `ssl_mode` (String) Determine the security of the connection to the Cloud SQL Postgresql instance
46+
47+
3048
<a id="nestedatt--privileges"></a>
3149
### Nested Schema for `privileges`
3250

docs/resources/grant_database.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,29 @@ resource "cloudsqlpostgresql_grant_database" "default" {
2929

3030
### Required
3131

32+
- `connection_config` (Attributes) The connection properties for the Cloud SQL instance. (see [below for nested schema](#nestedatt--connection_config))
3233
- `database` (String) The database on which the privileges will be granted for this role.
3334
- `privileges` (Attributes Set) A list of privileges to grant on the database for this role. (see [below for nested schema](#nestedatt--privileges))
3435
- `role` (String) The name of the role to grant privileges on the database. Can be username or role.
3536

37+
<a id="nestedatt--connection_config"></a>
38+
### Nested Schema for `connection_config`
39+
40+
Required:
41+
42+
- `connection_name` (String) The connection name of the Google Cloud SQL Postgresql instance. The `connection_name` format should be `<project>:<region>:<instance>`
43+
- `password` (String, Sensitive) The password to use to authenticate using the built-in database authentication
44+
- `username` (String) The username to use to authenticate with the Cloud SQL Postgresql instance
45+
46+
Optional:
47+
48+
- `database` (String) The database to connect to. Defaults to `postgres`.
49+
- `private_ip` (Boolean) Use the private IP address of the Cloud SQL Postgresql instance to connect to
50+
- `proxy` (String) Proxy socks url if used. Format needs to be `socks5://<ip>:<port>`
51+
- `psc` (Boolean) Use the Private Service Connect endpoint of the Cloud SQL Postgresql instance to connect to
52+
- `ssl_mode` (String) Determine the security of the connection to the Cloud SQL Postgresql instance
53+
54+
3655
<a id="nestedatt--privileges"></a>
3756
### Nested Schema for `privileges`
3857

docs/resources/grant_role.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,27 @@ The `cloudsqlpostgresql_grant_role` resource creates and manages role membership
1717

1818
### Required
1919

20+
- `connection_config` (Attributes) The connection properties for the Cloud SQL instance. (see [below for nested schema](#nestedatt--connection_config))
2021
- `group_role` (String) The `group_role` that will get the `role` as member
2122
- `role` (String) The `role` that will be a member of the `group_role`
2223

2324
### Optional
2425

2526
- `admin_option` (Boolean) Enable admin option
27+
28+
<a id="nestedatt--connection_config"></a>
29+
### Nested Schema for `connection_config`
30+
31+
Required:
32+
33+
- `connection_name` (String) The connection name of the Google Cloud SQL Postgresql instance. The `connection_name` format should be `<project>:<region>:<instance>`
34+
- `password` (String, Sensitive) The password to use to authenticate using the built-in database authentication
35+
- `username` (String) The username to use to authenticate with the Cloud SQL Postgresql instance
36+
37+
Optional:
38+
39+
- `database` (String) The database to connect to. Defaults to `postgres`.
40+
- `private_ip` (Boolean) Use the private IP address of the Cloud SQL Postgresql instance to connect to
41+
- `proxy` (String) Proxy socks url if used. Format needs to be `socks5://<ip>:<port>`
42+
- `psc` (Boolean) Use the Private Service Connect endpoint of the Cloud SQL Postgresql instance to connect to
43+
- `ssl_mode` (String) Determine the security of the connection to the Cloud SQL Postgresql instance

docs/resources/grant_schema.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,29 @@ resource "cloudsqlpostgresql_grant_database" "default" {
3030

3131
### Required
3232

33-
- `database` (String) The database where the schema resides.
33+
- `connection_config` (Attributes) The connection properties for the Cloud SQL instance. (see [below for nested schema](#nestedatt--connection_config))
3434
- `privileges` (Attributes Set) A list of privileges to grant on the schema for this role. (see [below for nested schema](#nestedatt--privileges))
3535
- `role` (String) The name of the role to grant privileges on the schema. Can be username or role.
3636
- `schema` (String) The schema on which the privileges will be granted for this role.
3737

38+
<a id="nestedatt--connection_config"></a>
39+
### Nested Schema for `connection_config`
40+
41+
Required:
42+
43+
- `connection_name` (String) The connection name of the Google Cloud SQL Postgresql instance. The `connection_name` format should be `<project>:<region>:<instance>`
44+
- `password` (String, Sensitive) The password to use to authenticate using the built-in database authentication
45+
- `username` (String) The username to use to authenticate with the Cloud SQL Postgresql instance
46+
47+
Optional:
48+
49+
- `database` (String) The database to connect to. Defaults to `postgres`.
50+
- `private_ip` (Boolean) Use the private IP address of the Cloud SQL Postgresql instance to connect to
51+
- `proxy` (String) Proxy socks url if used. Format needs to be `socks5://<ip>:<port>`
52+
- `psc` (Boolean) Use the Private Service Connect endpoint of the Cloud SQL Postgresql instance to connect to
53+
- `ssl_mode` (String) Determine the security of the connection to the Cloud SQL Postgresql instance
54+
55+
3856
<a id="nestedatt--privileges"></a>
3957
### Nested Schema for `privileges`
4058

docs/resources/grant_table.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,30 @@ resource "cloudsqlpostgresql_grant_table" "default" {
3434

3535
### Required
3636

37-
- `database` (String) The database where the table resides.
37+
- `connection_config` (Attributes) The connection properties for the Cloud SQL instance. (see [below for nested schema](#nestedatt--connection_config))
3838
- `privileges` (Attributes Set) A list of privileges to grant on the table for this role. (see [below for nested schema](#nestedatt--privileges))
3939
- `role` (String) The name of the role to grant privileges on the table. Can be username or role.
4040
- `schema` (String) The schema where the table resides.
4141
- `table` (String) The table on which the privileges will be granted for this role.
4242

43+
<a id="nestedatt--connection_config"></a>
44+
### Nested Schema for `connection_config`
45+
46+
Required:
47+
48+
- `connection_name` (String) The connection name of the Google Cloud SQL Postgresql instance. The `connection_name` format should be `<project>:<region>:<instance>`
49+
- `password` (String, Sensitive) The password to use to authenticate using the built-in database authentication
50+
- `username` (String) The username to use to authenticate with the Cloud SQL Postgresql instance
51+
52+
Optional:
53+
54+
- `database` (String) The database to connect to. Defaults to `postgres`.
55+
- `private_ip` (Boolean) Use the private IP address of the Cloud SQL Postgresql instance to connect to
56+
- `proxy` (String) Proxy socks url if used. Format needs to be `socks5://<ip>:<port>`
57+
- `psc` (Boolean) Use the Private Service Connect endpoint of the Cloud SQL Postgresql instance to connect to
58+
- `ssl_mode` (String) Determine the security of the connection to the Cloud SQL Postgresql instance
59+
60+
4361
<a id="nestedatt--privileges"></a>
4462
### Nested Schema for `privileges`
4563

docs/resources/role.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The `cloudsqlpostgresql_role` resource creates and manages a role. The superuser
1717

1818
### Required
1919

20+
- `connection_config` (Attributes) The connection properties for the Cloud SQL instance. (see [below for nested schema](#nestedatt--connection_config))
2021
- `name` (String) The name of the role
2122

2223
### Optional
@@ -30,3 +31,20 @@ The `cloudsqlpostgresql_role` resource creates and manages a role. The superuser
3031
- `is_user` (Boolean) Is this role a user that can login
3132
- `is_valid_until` (String) Sets a date and time after which the role's password is no longer valid
3233
- `password` (String, Sensitive) Sets the role's password
34+
35+
<a id="nestedatt--connection_config"></a>
36+
### Nested Schema for `connection_config`
37+
38+
Required:
39+
40+
- `connection_name` (String) The connection name of the Google Cloud SQL Postgresql instance. The `connection_name` format should be `<project>:<region>:<instance>`
41+
- `password` (String, Sensitive) The password to use to authenticate using the built-in database authentication
42+
- `username` (String) The username to use to authenticate with the Cloud SQL Postgresql instance
43+
44+
Optional:
45+
46+
- `database` (String) The database to connect to. Defaults to `postgres`.
47+
- `private_ip` (Boolean) Use the private IP address of the Cloud SQL Postgresql instance to connect to
48+
- `proxy` (String) Proxy socks url if used. Format needs to be `socks5://<ip>:<port>`
49+
- `psc` (Boolean) Use the Private Service Connect endpoint of the Cloud SQL Postgresql instance to connect to
50+
- `ssl_mode` (String) Determine the security of the connection to the Cloud SQL Postgresql instance

internal/provider/config.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ func (c *Config) connectToPostgresql(ctx context.Context, cc *ConnectionConfig)
2929
c.dbRegistryMutex.Lock()
3030
defer c.dbRegistryMutex.Unlock()
3131

32-
id := cc.Id()
32+
id, err := cc.Id()
33+
if err != nil {
34+
return nil, err
35+
}
3336

3437
if c.dbRegistry[id] != nil {
3538
return c.dbRegistry[id], nil
3639
}
3740

38-
err := createSqlDriver(ctx, cc)
41+
err = createSqlDriver(ctx, cc)
3942
if err != nil {
4043
return nil, err
4144
}
@@ -69,7 +72,12 @@ func createSqlDriver(ctx context.Context, cc *ConnectionConfig) error {
6972
options = append(options, cloudsqlconn.WithDialFunc(createDialer(cc.Proxy.ValueString(), ctx)))
7073
}
7174

72-
_, err := pgxv4.RegisterDriver(cc.Id(), options...)
75+
id, err := cc.Id()
76+
if err != nil {
77+
return err
78+
}
79+
80+
_, err = pgxv4.RegisterDriver(id, options...)
7381

7482
return err
7583
}

internal/provider/connection_config.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ func (c *ConnectionConfig) Dsn() string {
4444
sslMode)
4545
}
4646

47-
func (c *ConnectionConfig) Id() string {
47+
func (c *ConnectionConfig) Id() (string, error) {
4848
var buf bytes.Buffer
4949
encoder := base64.NewEncoder(base64.StdEncoding, &buf)
50-
json.NewEncoder(encoder).Encode(c)
51-
encoder.Close()
52-
return buf.String()
50+
defer encoder.Close()
51+
err := json.NewEncoder(encoder).Encode(c)
52+
if err != nil {
53+
return "", err
54+
}
55+
return buf.String(), nil
5356
}
5457

5558
func connectionConfigSchemaAttribute() schema.Attribute {
@@ -101,18 +104,21 @@ func connectionConfigSchemaAttribute() schema.Attribute {
101104
MarkdownDescription: "Use the private IP address of the Cloud SQL Postgresql instance to connect to",
102105
Description: "Use the private IP address of the Cloud SQL Postgresql instance to connect to",
103106
Optional: true,
107+
Computed: true,
104108
Default: booldefault.StaticBool(false),
105109
},
106110
"psc": schema.BoolAttribute{
107111
MarkdownDescription: "Use the Private Service Connect endpoint of the Cloud SQL Postgresql instance to connect to",
108112
Description: "Use the Private Service Connect endpoint of the Cloud SQL Postgresql instance to connect to",
109113
Optional: true,
114+
Computed: true,
110115
Default: booldefault.StaticBool(false),
111116
},
112117
"ssl_mode": schema.StringAttribute{
113118
MarkdownDescription: "Determine the security of the connection to the Cloud SQL Postgresql instance",
114119
Description: "Determine the security of the connection to the Cloud SQL Postgresql instance",
115120
Optional: true,
121+
Computed: true,
116122
Default: stringdefault.StaticString("disable"),
117123
Validators: []validator.String{
118124
stringvalidator.RegexMatches(regexp.MustCompile(`^(disable|allow|prefer|require)$`),

0 commit comments

Comments
 (0)