Skip to content

Commit 489218d

Browse files
authored
chore: support query_data_policy (#150)
* chore: support query_data_policy * fix: lint
1 parent 182cb3c commit 489218d

File tree

17 files changed

+242
-160
lines changed

17 files changed

+242
-160
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.9.3
1+
3.9.4

docs/data-sources/policy.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ The policy data source.
2626
- `disable_copy_data_policy` (Block List, Max: 1) Restrict data copying in SQL Editor (Admins/DBAs allowed) (see [below for nested schema](#nestedblock--disable_copy_data_policy))
2727
- `global_masking_policy` (Block List, Max: 1) (see [below for nested schema](#nestedblock--global_masking_policy))
2828
- `masking_exception_policy` (Block List, Max: 1) (see [below for nested schema](#nestedblock--masking_exception_policy))
29+
- `query_data_policy` (Block List, Max: 1) The policy for query data (see [below for nested schema](#nestedblock--query_data_policy))
2930
- `rollout_policy` (Block List, Max: 1) Control issue rollout. Learn more: https://docs.bytebase.com/administration/environment-policy/rollout-policy (see [below for nested schema](#nestedblock--rollout_policy))
3031

3132
### Read-Only
@@ -102,6 +103,20 @@ Optional:
102103

103104

104105

106+
<a id="nestedblock--query_data_policy"></a>
107+
### Nested Schema for `query_data_policy`
108+
109+
Required:
110+
111+
- `disable_export` (Boolean) Disable export data in the SQL editor
112+
113+
Optional:
114+
115+
- `maximum_result_rows` (Number) The return rows limit. If the value <= 0, will be treated as no limit. The default value is -1.
116+
- `maximum_result_size` (Number) The size limit in bytes. The default value is 100MB, we will use the default value if the limit <= 0.
117+
- `timeout_in_seconds` (Number) The maximum time allowed for a query to run in SQL Editor. No limit when the value <= 0
118+
119+
105120
<a id="nestedblock--rollout_policy"></a>
106121
### Nested Schema for `rollout_policy`
107122

docs/data-sources/policy_list.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Read-Only:
3636
- `inherit_from_parent` (Boolean)
3737
- `masking_exception_policy` (List of Object) (see [below for nested schema](#nestedobjatt--policies--masking_exception_policy))
3838
- `name` (String)
39+
- `query_data_policy` (List of Object) (see [below for nested schema](#nestedobjatt--policies--query_data_policy))
3940
- `rollout_policy` (List of Object) (see [below for nested schema](#nestedobjatt--policies--rollout_policy))
4041
- `type` (String)
4142

@@ -100,6 +101,17 @@ Read-Only:
100101

101102

102103

104+
<a id="nestedobjatt--policies--query_data_policy"></a>
105+
### Nested Schema for `policies.query_data_policy`
106+
107+
Read-Only:
108+
109+
- `disable_export` (Boolean)
110+
- `maximum_result_rows` (Number)
111+
- `maximum_result_size` (Number)
112+
- `timeout_in_seconds` (Number)
113+
114+
103115
<a id="nestedobjatt--policies--rollout_policy"></a>
104116
### Nested Schema for `policies.rollout_policy`
105117

docs/data-sources/setting.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ The setting data source.
2424
- `classification` (Block List, Max: 1) Classification for data masking. Require ENTERPRISE subscription. (see [below for nested schema](#nestedblock--classification))
2525
- `password_restriction` (Block List, Max: 1) Restrict for login password (see [below for nested schema](#nestedblock--password_restriction))
2626
- `semantic_types` (Block Set) Semantic types for data masking. Require ENTERPRISE subscription. (see [below for nested schema](#nestedblock--semantic_types))
27-
- `sql_query_restriction` (Block List, Max: 1) Restrict for SQL query result (see [below for nested schema](#nestedblock--sql_query_restriction))
2827
- `workspace_profile` (Block List, Max: 1) (see [below for nested schema](#nestedblock--workspace_profile))
2928

3029
### Read-Only
@@ -159,15 +158,6 @@ Required:
159158

160159

161160

162-
<a id="nestedblock--sql_query_restriction"></a>
163-
### Nested Schema for `sql_query_restriction`
164-
165-
Optional:
166-
167-
- `maximum_result_rows` (Number) The return rows limit. If the value <= 0, will be treated as no limit. The default value is -1.
168-
- `maximum_result_size` (Number) The size limit in bytes. The default value is 100MB, we will use the default value if the setting not exists, or the limit <= 0.
169-
170-
171161
<a id="nestedblock--workspace_profile"></a>
172162
### Nested Schema for `workspace_profile`
173163

docs/resources/policy.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The policy resource.
2828
- `global_masking_policy` (Block List, Max: 1) (see [below for nested schema](#nestedblock--global_masking_policy))
2929
- `inherit_from_parent` (Boolean) Decide if the policy should inherit from the parent.
3030
- `masking_exception_policy` (Block List, Max: 1) (see [below for nested schema](#nestedblock--masking_exception_policy))
31+
- `query_data_policy` (Block List, Max: 1) The policy for query data (see [below for nested schema](#nestedblock--query_data_policy))
3132
- `rollout_policy` (Block List, Max: 1) Control issue rollout. Learn more: https://docs.bytebase.com/administration/environment-policy/rollout-policy (see [below for nested schema](#nestedblock--rollout_policy))
3233

3334
### Read-Only
@@ -102,6 +103,20 @@ Optional:
102103

103104

104105

106+
<a id="nestedblock--query_data_policy"></a>
107+
### Nested Schema for `query_data_policy`
108+
109+
Required:
110+
111+
- `disable_export` (Boolean) Disable export data in the SQL editor
112+
113+
Optional:
114+
115+
- `maximum_result_rows` (Number) The return rows limit. If the value <= 0, will be treated as no limit. The default value is -1.
116+
- `maximum_result_size` (Number) The size limit in bytes. The default value is 100MB, we will use the default value if the limit <= 0.
117+
- `timeout_in_seconds` (Number) The maximum time allowed for a query to run in SQL Editor. No limit when the value <= 0
118+
119+
105120
<a id="nestedblock--rollout_policy"></a>
106121
### Nested Schema for `rollout_policy`
107122

docs/resources/setting.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ The setting resource.
2626
- `environment_setting` (Block List) The environment (see [below for nested schema](#nestedblock--environment_setting))
2727
- `password_restriction` (Block List, Max: 1) Restrict for login password (see [below for nested schema](#nestedblock--password_restriction))
2828
- `semantic_types` (Block Set) Semantic types for data masking. Require ENTERPRISE subscription. (see [below for nested schema](#nestedblock--semantic_types))
29-
- `sql_query_restriction` (Block List, Max: 1) Restrict for SQL query result (see [below for nested schema](#nestedblock--sql_query_restriction))
3029
- `workspace_profile` (Block List, Max: 1) (see [below for nested schema](#nestedblock--workspace_profile))
3130

3231
### Read-Only
@@ -235,15 +234,6 @@ Required:
235234

236235

237236

238-
<a id="nestedblock--sql_query_restriction"></a>
239-
### Nested Schema for `sql_query_restriction`
240-
241-
Optional:
242-
243-
- `maximum_result_rows` (Number) The return rows limit. If the value <= 0, will be treated as no limit. The default value is -1.
244-
- `maximum_result_size` (Number) The size limit in bytes. The default value is 100MB, we will use the default value if the setting not exists, or the limit <= 0.
245-
246-
247237
<a id="nestedblock--workspace_profile"></a>
248238
### Nested Schema for `workspace_profile`
249239

examples/setup/main.tf

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
terraform {
22
required_providers {
33
bytebase = {
4-
version = "3.9.2"
4+
version = "3.9.4"
55
# For local development, please use "terraform.local/bytebase/bytebase" instead
66
source = "registry.terraform.io/bytebase/bytebase"
77
}
@@ -18,7 +18,6 @@ locals {
1818
project_id = "project-sample"
1919
}
2020

21-
2221
provider "bytebase" {
2322
# You need to replace the account and key with your Bytebase service account.
2423
service_account = local.service_account
@@ -36,3 +35,14 @@ resource "bytebase_setting" "workspace_profile" {
3635
domains = ["bytebase.com"]
3736
}
3837
}
38+
39+
resource "bytebase_policy" "query_data_policy" {
40+
parent = "workspaces/-"
41+
type = "DATA_QUERY"
42+
query_data_policy {
43+
maximum_result_size = 200 * 1024 * 1024 # 200MB
44+
maximum_result_rows = 100
45+
disable_export = false
46+
timeout_in_seconds = 60 # 60 seconds
47+
}
48+
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ go 1.24.4
55
toolchain go1.24.5
66

77
require (
8-
buf.build/gen/go/bytebase/bytebase/connectrpc/go v1.18.1-20250821091751-ab434d709c89.1
9-
buf.build/gen/go/bytebase/bytebase/protocolbuffers/go v1.36.8-20250821091751-ab434d709c89.1
8+
buf.build/gen/go/bytebase/bytebase/connectrpc/go v1.18.1-20250908030532-58bfc338601e.1
9+
buf.build/gen/go/bytebase/bytebase/protocolbuffers/go v1.36.8-20250908030532-58bfc338601e.1
1010
connectrpc.com/connect v1.18.1
1111
github.com/hashicorp/go-cty v1.5.0
1212
github.com/hashicorp/terraform-plugin-docs v0.13.0

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
buf.build/gen/go/bytebase/bytebase/connectrpc/go v1.18.1-20250821091751-ab434d709c89.1 h1:ZmVAFhx6C+5hh2JwHIicGVXPU0P+dWWUMYsSzXJGSZM=
2-
buf.build/gen/go/bytebase/bytebase/connectrpc/go v1.18.1-20250821091751-ab434d709c89.1/go.mod h1:cCayz9URf5ApvJZGfIE7bfasYECFG9ECIVNNOm4Vci0=
3-
buf.build/gen/go/bytebase/bytebase/protocolbuffers/go v1.36.8-20250821091751-ab434d709c89.1 h1:uHBwD119t1nqozj6q/Zh/+NBfzUb/qLVRK/dhvZkbqw=
4-
buf.build/gen/go/bytebase/bytebase/protocolbuffers/go v1.36.8-20250821091751-ab434d709c89.1/go.mod h1:dwdKUX0jGgJ7OJe024SNHvANb1TKuBzIrZOzL/3Njtk=
1+
buf.build/gen/go/bytebase/bytebase/connectrpc/go v1.18.1-20250908030532-58bfc338601e.1 h1:FQEei3tpJ+OjhAAfLOTzqm+XaFboZI+UpWbXEiQJ1m4=
2+
buf.build/gen/go/bytebase/bytebase/connectrpc/go v1.18.1-20250908030532-58bfc338601e.1/go.mod h1:/jFGXncqA/NGlTsADOmP7o1PaKo05HUP64uWe4g7UZg=
3+
buf.build/gen/go/bytebase/bytebase/protocolbuffers/go v1.36.8-20250908030532-58bfc338601e.1 h1:9VCImLW8Zda6Tay+4zoS85Y8RwX94/x5XlZeeyQHZ38=
4+
buf.build/gen/go/bytebase/bytebase/protocolbuffers/go v1.36.8-20250908030532-58bfc338601e.1/go.mod h1:dwdKUX0jGgJ7OJe024SNHvANb1TKuBzIrZOzL/3Njtk=
55
connectrpc.com/connect v1.18.1 h1:PAg7CjSAGvscaf6YZKUefjoih5Z/qYkyaTrBW8xvYPw=
66
connectrpc.com/connect v1.18.1/go.mod h1:0292hj1rnx8oFrStN7cB4jjVBeqs+Yx5yDIC2prWDO8=
77
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=

provider/data_source_policy.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func dataSourcePolicy() *schema.Resource {
4747
v1pb.PolicyType_DISABLE_COPY_DATA.String(),
4848
v1pb.PolicyType_DATA_SOURCE_QUERY.String(),
4949
v1pb.PolicyType_ROLLOUT_POLICY.String(),
50+
v1pb.PolicyType_DATA_QUERY.String(),
5051
}, false),
5152
Description: "The policy type.",
5253
},
@@ -70,6 +71,7 @@ func dataSourcePolicy() *schema.Resource {
7071
"disable_copy_data_policy": getDisableCopyDataPolicySchema(true),
7172
"data_source_query_policy": getDataSourceQueryPolicySchema(true),
7273
"rollout_policy": getRolloutPolicySchema(true),
74+
"query_data_policy": getDataQueryPolicySchema(true),
7375
},
7476
}
7577
}
@@ -223,6 +225,44 @@ func getGlobalMaskingPolicySchema(computed bool) *schema.Schema {
223225
}
224226
}
225227

228+
func getDataQueryPolicySchema(computed bool) *schema.Schema {
229+
return &schema.Schema{
230+
Computed: computed,
231+
Optional: true,
232+
Default: nil,
233+
Type: schema.TypeList,
234+
MaxItems: 1,
235+
MinItems: 1,
236+
Description: "The policy for query data",
237+
Elem: &schema.Resource{
238+
Schema: map[string]*schema.Schema{
239+
"maximum_result_size": {
240+
Type: schema.TypeInt,
241+
Optional: true,
242+
Default: 100 * 1024 * 1024,
243+
Description: "The size limit in bytes. The default value is 100MB, we will use the default value if the limit <= 0.",
244+
},
245+
"maximum_result_rows": {
246+
Type: schema.TypeInt,
247+
Optional: true,
248+
Default: -1,
249+
Description: "The return rows limit. If the value <= 0, will be treated as no limit. The default value is -1.",
250+
},
251+
"disable_export": {
252+
Type: schema.TypeBool,
253+
Required: true,
254+
Description: "Disable export data in the SQL editor",
255+
},
256+
"timeout_in_seconds": {
257+
Type: schema.TypeInt,
258+
Optional: true,
259+
Description: "The maximum time allowed for a query to run in SQL Editor. No limit when the value <= 0",
260+
},
261+
},
262+
},
263+
}
264+
}
265+
226266
func getDisableCopyDataPolicySchema(computed bool) *schema.Schema {
227267
return &schema.Schema{
228268
Computed: computed,
@@ -397,6 +437,11 @@ func flattenPolicyPayload(policy *v1pb.Policy) (string, interface{}, diag.Diagno
397437
rolloutPolicy := flattenRolloutPolicy(p)
398438
return "rollout_policy", rolloutPolicy, nil
399439
}
440+
case v1pb.PolicyType_DATA_QUERY:
441+
if p := policy.GetQueryDataPolicy(); p != nil {
442+
rolloutPolicy := flattenQueryDataPolicy(p)
443+
return "query_data_policy", rolloutPolicy, nil
444+
}
400445
}
401446

402447
return "", nil, diag.Errorf("unsupported policy: %s", policy.Name)
@@ -429,6 +474,16 @@ func flattenDisableCopyDataPolicy(p *v1pb.DisableCopyDataPolicy) []interface{} {
429474
return []interface{}{policy}
430475
}
431476

477+
func flattenQueryDataPolicy(p *v1pb.QueryDataPolicy) []interface{} {
478+
policy := map[string]interface{}{
479+
"maximum_result_size": int(p.MaximumResultSize),
480+
"maximum_result_rows": int(p.MaximumResultRows),
481+
"disable_export": p.DisableExport,
482+
"timeout_in_seconds": int(p.Timeout.Seconds),
483+
}
484+
return []interface{}{policy}
485+
}
486+
432487
func flattenGlobalMaskingPolicy(p *v1pb.MaskingRulePolicy) ([]interface{}, error) {
433488
ruleList := []interface{}{}
434489

0 commit comments

Comments
 (0)