Skip to content

Commit a9708b5

Browse files
authored
chore: optimize instance resource (#98)
* chore: optimize instance resource * chore: update docs * chore: update docs * fix: lint
1 parent f02c61e commit a9708b5

33 files changed

+596
-241
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.18
1+
1.0.19

api/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type Client interface {
5656
// GetDatabase gets the database by instance resource id and the database name.
5757
GetDatabase(ctx context.Context, databaseName string) (*v1pb.Database, error)
5858
// ListDatabase list the databases.
59-
ListDatabase(ctx context.Context, instanceID, filter string) ([]*v1pb.Database, error)
59+
ListDatabase(ctx context.Context, instanceID, filter string, listAll bool) ([]*v1pb.Database, error)
6060
// UpdateDatabase patches the database.
6161
UpdateDatabase(ctx context.Context, patch *v1pb.Database, updateMasks []string) (*v1pb.Database, error)
6262
// BatchUpdateDatabases batch updates databases.

api/setting.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ const (
88
SettingWorkspaceApproval SettingName = "bb.workspace.approval"
99
// SettingWorkspaceProfile is the setting name for workspace profile settings.
1010
SettingWorkspaceProfile SettingName = "bb.workspace.profile"
11-
// SettingWorkspaceExternalApproval is the setting name for workspace external approval config.
12-
SettingWorkspaceExternalApproval SettingName = "bb.workspace.approval.external"
1311
// SettingDataClassification is the setting name for data classification.
1412
SettingDataClassification SettingName = "bb.workspace.data-classification"
1513
// SettingSemanticTypes is the setting name for semantic types.

client/database.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (c *client) GetDatabase(ctx context.Context, databaseName string) (*v1pb.Da
2929
}
3030

3131
// ListDatabase list all databases.
32-
func (c *client) ListDatabase(ctx context.Context, parent, filter string) ([]*v1pb.Database, error) {
32+
func (c *client) ListDatabase(ctx context.Context, parent, filter string, listAll bool) ([]*v1pb.Database, error) {
3333
res := []*v1pb.Database{}
3434
pageToken := ""
3535
startTime := time.Now()
@@ -47,7 +47,7 @@ func (c *client) ListDatabase(ctx context.Context, parent, filter string) ([]*v1
4747
})
4848

4949
pageToken = resp.NextPageToken
50-
if pageToken == "" {
50+
if pageToken == "" || !listAll {
5151
break
5252
}
5353
}

docs/data-sources/instance.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ The instance data source.
1919

2020
- `resource_id` (String) The instance unique resource id.
2121

22+
### Optional
23+
24+
- `list_all_databases` (Boolean) List all databases in this instance. If false, will only list 500 databases.
25+
2226
### Read-Only
2327

28+
- `activation` (Boolean) Whether assign license for this instance or not.
2429
- `data_sources` (Set of Object) (see [below for nested schema](#nestedatt--data_sources))
2530
- `databases` (Set of String) The databases full name in the resource.
2631
- `engine` (String) The instance engine. Support MYSQL, POSTGRES, TIDB, SNOWFLAKE, CLICKHOUSE, MONGODB, SQLITE, REDIS, ORACLE, SPANNER, MSSQL, REDSHIFT, MARIADB, OCEANBASE.
@@ -39,6 +44,7 @@ The instance data source.
3944
Read-Only:
4045

4146
- `database` (String)
47+
- `external_secret` (List of Object) (see [below for nested schema](#nestedobjatt--data_sources--external_secret))
4248
- `host` (String)
4349
- `id` (String)
4450
- `password` (String)
@@ -49,4 +55,51 @@ Read-Only:
4955
- `type` (String)
5056
- `username` (String)
5157

58+
<a id="nestedobjatt--data_sources--external_secret"></a>
59+
### Nested Schema for `data_sources.external_secret`
60+
61+
Read-Only:
62+
63+
- `aws_secrets_manager` (List of Object) (see [below for nested schema](#nestedobjatt--data_sources--external_secret--aws_secrets_manager))
64+
- `gcp_secret_manager` (List of Object) (see [below for nested schema](#nestedobjatt--data_sources--external_secret--gcp_secret_manager))
65+
- `vault` (List of Object) (see [below for nested schema](#nestedobjatt--data_sources--external_secret--vault))
66+
67+
<a id="nestedobjatt--data_sources--external_secret--aws_secrets_manager"></a>
68+
### Nested Schema for `data_sources.external_secret.aws_secrets_manager`
69+
70+
Read-Only:
71+
72+
- `password_key_name` (String)
73+
- `secret_name` (String)
74+
75+
76+
<a id="nestedobjatt--data_sources--external_secret--gcp_secret_manager"></a>
77+
### Nested Schema for `data_sources.external_secret.gcp_secret_manager`
78+
79+
Read-Only:
80+
81+
- `secret_name` (String)
82+
83+
84+
<a id="nestedobjatt--data_sources--external_secret--vault"></a>
85+
### Nested Schema for `data_sources.external_secret.vault`
86+
87+
Read-Only:
88+
89+
- `app_role` (List of Object) (see [below for nested schema](#nestedobjatt--data_sources--external_secret--vault--app_role))
90+
- `engine_name` (String)
91+
- `password_key_name` (String)
92+
- `secret_name` (String)
93+
- `token` (String)
94+
- `url` (String)
95+
96+
<a id="nestedobjatt--data_sources--external_secret--vault--app_role"></a>
97+
### Nested Schema for `data_sources.external_secret.vault.url`
98+
99+
Read-Only:
100+
101+
- `role_id` (String)
102+
- `secret` (String)
103+
- `secret_type` (String)
104+
52105

docs/data-sources/instance_list.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ The instance data source list.
2929

3030
Read-Only:
3131

32+
- `activation` (Boolean)
3233
- `data_sources` (Set of Object) (see [below for nested schema](#nestedobjatt--instances--data_sources))
33-
- `databases` (Set of String)
3434
- `engine` (String)
3535
- `engine_version` (String)
3636
- `environment` (String)
@@ -47,6 +47,7 @@ Read-Only:
4747
Read-Only:
4848

4949
- `database` (String)
50+
- `external_secret` (List of Object) (see [below for nested schema](#nestedobjatt--instances--data_sources--external_secret))
5051
- `host` (String)
5152
- `id` (String)
5253
- `password` (String)
@@ -57,4 +58,51 @@ Read-Only:
5758
- `type` (String)
5859
- `username` (String)
5960

61+
<a id="nestedobjatt--instances--data_sources--external_secret"></a>
62+
### Nested Schema for `instances.data_sources.external_secret`
63+
64+
Read-Only:
65+
66+
- `aws_secrets_manager` (List of Object) (see [below for nested schema](#nestedobjatt--instances--data_sources--external_secret--aws_secrets_manager))
67+
- `gcp_secret_manager` (List of Object) (see [below for nested schema](#nestedobjatt--instances--data_sources--external_secret--gcp_secret_manager))
68+
- `vault` (List of Object) (see [below for nested schema](#nestedobjatt--instances--data_sources--external_secret--vault))
69+
70+
<a id="nestedobjatt--instances--data_sources--external_secret--aws_secrets_manager"></a>
71+
### Nested Schema for `instances.data_sources.external_secret.vault`
72+
73+
Read-Only:
74+
75+
- `password_key_name` (String)
76+
- `secret_name` (String)
77+
78+
79+
<a id="nestedobjatt--instances--data_sources--external_secret--gcp_secret_manager"></a>
80+
### Nested Schema for `instances.data_sources.external_secret.vault`
81+
82+
Read-Only:
83+
84+
- `secret_name` (String)
85+
86+
87+
<a id="nestedobjatt--instances--data_sources--external_secret--vault"></a>
88+
### Nested Schema for `instances.data_sources.external_secret.vault`
89+
90+
Read-Only:
91+
92+
- `app_role` (List of Object) (see [below for nested schema](#nestedobjatt--instances--data_sources--external_secret--vault--app_role))
93+
- `engine_name` (String)
94+
- `password_key_name` (String)
95+
- `secret_name` (String)
96+
- `token` (String)
97+
- `url` (String)
98+
99+
<a id="nestedobjatt--instances--data_sources--external_secret--vault--app_role"></a>
100+
### Nested Schema for `instances.data_sources.external_secret.vault.app_role`
101+
102+
Read-Only:
103+
104+
- `role_id` (String)
105+
- `secret` (String)
106+
- `secret_type` (String)
107+
60108

docs/data-sources/setting.md

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ The setting data source.
2828
### Read-Only
2929

3030
- `approval_flow` (Block List) Configure risk level and approval flow for different tasks. Require ENTERPRISE subscription. (see [below for nested schema](#nestedblock--approval_flow))
31-
- `external_approval_nodes` (Block List) Configure external nodes in the approval flow. Require ENTERPRISE subscription. (see [below for nested schema](#nestedblock--external_approval_nodes))
3231
- `id` (String) The ID of this resource.
3332

3433
<a id="nestedblock--classification"></a>
@@ -186,23 +185,3 @@ Read-Only:
186185
- `type` (String)
187186

188187

189-
190-
191-
192-
<a id="nestedblock--external_approval_nodes"></a>
193-
### Nested Schema for `external_approval_nodes`
194-
195-
Read-Only:
196-
197-
- `nodes` (Set of Object) (see [below for nested schema](#nestedatt--external_approval_nodes--nodes))
198-
199-
<a id="nestedatt--external_approval_nodes--nodes"></a>
200-
### Nested Schema for `external_approval_nodes.nodes`
201-
202-
Read-Only:
203-
204-
- `endpoint` (String)
205-
- `id` (String)
206-
- `title` (String)
207-
208-

docs/resources/instance.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ The instance resource.
2525

2626
### Optional
2727

28+
- `activation` (Boolean) Whether assign license for this instance or not.
2829
- `external_link` (String) The external console URL managing this instance (e.g. AWS RDS console, your in-house DB instance console)
30+
- `list_all_databases` (Boolean) List all databases in this instance. If false, will only list 500 databases.
2931
- `maximum_connections` (Number) The maximum number of connections.
3032
- `sync_interval` (Number) How often the instance is synced in seconds. Default 0, means never sync.
3133

@@ -44,15 +46,66 @@ Required:
4446
- `host` (String) Host or socket for your instance, or the account name if the instance type is Snowflake.
4547
- `id` (String) The unique data source id in this instance.
4648
- `port` (String) The port for your instance.
47-
- `type` (String) The data source type. Should be ADMIN or RO.
49+
- `type` (String) The data source type. Should be ADMIN or READ_ONLY.
4850

4951
Optional:
5052

5153
- `database` (String) The database for the instance, you can set this if the engine type is POSTGRES.
54+
- `external_secret` (Block List, Max: 1) The external secret to get the database password. Learn more: https://www.bytebase.com/docs/get-started/instance/#use-external-secret-manager (see [below for nested schema](#nestedblock--data_sources--external_secret))
5255
- `password` (String, Sensitive) The connection user password used by Bytebase to perform DDL and DML operations.
5356
- `ssl_ca` (String, Sensitive) The CA certificate. Optional, you can set this if the engine type is MYSQL, POSTGRES, TIDB or CLICKHOUSE.
5457
- `ssl_cert` (String, Sensitive) The client certificate. Optional, you can set this if the engine type is MYSQL, POSTGRES, TIDB or CLICKHOUSE.
5558
- `ssl_key` (String, Sensitive) The client key. Optional, you can set this if the engine type is MYSQL, POSTGRES, TIDB or CLICKHOUSE.
5659
- `username` (String) The connection user name used by Bytebase to perform DDL and DML operations.
5760

61+
<a id="nestedblock--data_sources--external_secret"></a>
62+
### Nested Schema for `data_sources.external_secret`
63+
64+
Optional:
65+
66+
- `aws_secrets_manager` (Block List, Max: 1) The AWS Secrets Manager to get the database password. Reference doc https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html (see [below for nested schema](#nestedblock--data_sources--external_secret--aws_secrets_manager))
67+
- `gcp_secret_manager` (Block List, Max: 1) The GCP Secret Manager to get the database password. Reference doc https://cloud.google.com/secret-manager/docs (see [below for nested schema](#nestedblock--data_sources--external_secret--gcp_secret_manager))
68+
- `vault` (Block List, Max: 1) The Valut to get the database password. Reference doc https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2 (see [below for nested schema](#nestedblock--data_sources--external_secret--vault))
69+
70+
<a id="nestedblock--data_sources--external_secret--aws_secrets_manager"></a>
71+
### Nested Schema for `data_sources.external_secret.aws_secrets_manager`
72+
73+
Required:
74+
75+
- `password_key_name` (String) The key name for the password.
76+
- `secret_name` (String) The secret name to store the password.
77+
78+
79+
<a id="nestedblock--data_sources--external_secret--gcp_secret_manager"></a>
80+
### Nested Schema for `data_sources.external_secret.gcp_secret_manager`
81+
82+
Required:
83+
84+
- `secret_name` (String) The secret name should be like "projects/{project-id}/secrets/{secret-id}".
85+
86+
87+
<a id="nestedblock--data_sources--external_secret--vault"></a>
88+
### Nested Schema for `data_sources.external_secret.vault`
89+
90+
Required:
91+
92+
- `engine_name` (String) The name for secret engine.
93+
- `password_key_name` (String) The key name for the password.
94+
- `secret_name` (String) The secret name in the engine to store the password.
95+
- `url` (String) The Vault URL.
96+
97+
Optional:
98+
99+
- `app_role` (Block List, Max: 1) The Vault app role to get the password. (see [below for nested schema](#nestedblock--data_sources--external_secret--vault--app_role))
100+
- `token` (String, Sensitive) The root token without TTL. Learn more: https://developer.hashicorp.com/vault/docs/commands/operator/generate-root
101+
102+
<a id="nestedblock--data_sources--external_secret--vault--app_role"></a>
103+
### Nested Schema for `data_sources.external_secret.vault.app_role`
104+
105+
Required:
106+
107+
- `role_id` (String, Sensitive) The app role id.
108+
- `secret` (String, Sensitive) The secret id for the role without ttl.
109+
- `secret_type` (String) The secret id type, can be PLAIN (plain text for the secret) or ENVIRONMENT (envirionment name for the secret).
110+
58111

docs/resources/setting.md

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ The setting resource.
2323

2424
- `approval_flow` (Block List) Configure risk level and approval flow for different tasks. Require ENTERPRISE subscription. (see [below for nested schema](#nestedblock--approval_flow))
2525
- `classification` (Block List, Max: 1) Classification for data masking. Require ENTERPRISE subscription. (see [below for nested schema](#nestedblock--classification))
26-
- `external_approval_nodes` (Block List) Configure external nodes in the approval flow. Require ENTERPRISE subscription. (see [below for nested schema](#nestedblock--external_approval_nodes))
2726
- `semantic_types` (Block Set) Semantic types for data masking. Require ENTERPRISE subscription. (see [below for nested schema](#nestedblock--semantic_types))
2827
- `workspace_profile` (Block List, Max: 1) (see [below for nested schema](#nestedblock--workspace_profile))
2928

@@ -119,24 +118,6 @@ Optional:
119118

120119

121120

122-
<a id="nestedblock--external_approval_nodes"></a>
123-
### Nested Schema for `external_approval_nodes`
124-
125-
Required:
126-
127-
- `nodes` (Block Set, Min: 1) (see [below for nested schema](#nestedblock--external_approval_nodes--nodes))
128-
129-
<a id="nestedblock--external_approval_nodes--nodes"></a>
130-
### Nested Schema for `external_approval_nodes.nodes`
131-
132-
Required:
133-
134-
- `endpoint` (String) The endpoint URL to receive the approval message. Learn more: https://www.bytebase.com/docs/api/external-approval
135-
- `id` (String) The unique external node id.
136-
- `title` (String) The external node title.
137-
138-
139-
140121
<a id="nestedblock--semantic_types"></a>
141122
### Nested Schema for `semantic_types`
142123

examples/environments/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
terraform {
33
required_providers {
44
bytebase = {
5-
version = "1.0.18"
5+
version = "1.0.19"
66
# For local development, please use "terraform.local/bytebase/bytebase" instead
77
source = "registry.terraform.io/bytebase/bytebase"
88
}

0 commit comments

Comments
 (0)