Skip to content

Commit 6529ab4

Browse files
authored
chore: update the docs (#44)
* feat: support policy data source * chore: support CRUD policy resource * chore: support config sql review rules * chore: update docs * chore: update version * chore: update docs * chore: update docs * chore: update docs
1 parent 5e93b41 commit 6529ab4

File tree

6 files changed

+80
-44
lines changed

6 files changed

+80
-44
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.7-alpha.4
1+
0.0.7-alpha.5

docs/data-sources/policy.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,9 @@ You can check [examples](https://github.com/bytebase/terraform-provider-bytebase
4343

4444
### Optional
4545

46-
#### Locate the policy resource
47-
4846
See [Locate the policy resource](https://registry.terraform.io/providers/bytebase/bytebase/latest/docs/resources/policy#optional) for details.
4947

5048
### Read-Only
5149

52-
#### The policy payload
53-
54-
See [The policy payload](https://registry.terraform.io/providers/bytebase/bytebase/latest/docs/resources/policy#the-policy-payload) for details.
50+
- The policy payload. See [The policy payload](https://registry.terraform.io/providers/bytebase/bytebase/latest/docs/resources/policy#the-policy-payload) for details.
51+
- `inherit_from_parent` (Boolean) Decide if the policy should inherit from the parent.

docs/resources/environment.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ You can check [examples](https://github.com/bytebase/terraform-provider-bytebase
4141
- `resource_id` (String) The environment **unique resource id**. For example, `dev`, `dev-env`.
4242
- `title` (String) The environment **unique name**. For example, `Dev`.
4343
- `order` (Number) The environment sorting order. Starting with 1. Lower number appears first in the deployment pipeline.
44-
45-
### Optional
46-
4744
- `environment_tier_policy` (String) Check [Environment Tier](https://www.bytebase.com/docs/administration/environment-policy/tier) for details. Should be one of:
4845
- `PROTECTED`
4946
- `UNPROTECTED`

docs/resources/policy.md

Lines changed: 75 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,23 @@ Must set the `deployment_approval_policy` if the policy type is `DEPLOYMENT_APPR
5353
- `default_strategy` (String) The default strategy, should be one of:
5454
- `MANUAL`: The pipeline should be manually approved by user to proceed.
5555
- `AUTOMATIC`: The pipeline will automatically be approved without user intervention.
56-
- `deployment_approval_strategies` (List of Object) A list contains multiply strategies for different approval groups. The object should contains:
57-
- `approval_group` (String) The approval group, should be one of:
58-
- `APPROVAL_GROUP_DBA`: Means the assignee can be selected from the workspace owners and DBAs.
59-
- `APPROVAL_GROUP_PROJECT_OWNER`: Means the assignee can be selected from the project owners.
60-
- `approval_strategy` (String) The approval strategy, should be one of:
61-
- `MANUAL`: The pipeline should be manually approved by user to proceed.
62-
- `AUTOMATIC`: The pipeline will automatically be approved without user intervention.
63-
- `deployment_type` (String) The deployment type, should be one of:
64-
- `DATABASE_CREATE`: The deployment type for creating databases.
65-
- `DATABASE_DDL`: The deployment type for updating database schemas (DDL).
66-
- `DATABASE_DDL_GHOST`: The deployment type for updating database schemas using gh-ost.
67-
- `DATABASE_DML`: The deployment type for updating database data (DML).
68-
- `DATABASE_RESTORE_PITR`: The deployment type for performing a Point-in-time Recovery.
69-
- `DATABASE_DML_ROLLBACK`: The deployment type for a generated rollback issue.
56+
- `deployment_approval_strategies` (List of Object) A list contains multiply strategies for different approval groups.
57+
58+
The object in `deployment_approval_strategies` should contains:
59+
60+
- `approval_group` (String) The approval group, should be one of:
61+
- `APPROVAL_GROUP_DBA`: Means the assignee can be selected from the workspace owners and DBAs.
62+
- `APPROVAL_GROUP_PROJECT_OWNER`: Means the assignee can be selected from the project owners.
63+
- `approval_strategy` (String) The approval strategy, should be one of:
64+
- `MANUAL`: The pipeline should be manually approved by user to proceed.
65+
- `AUTOMATIC`: The pipeline will automatically be approved without user intervention.
66+
- `deployment_type` (String) The deployment type, should be one of:
67+
- `DATABASE_CREATE`: The deployment type for creating databases.
68+
- `DATABASE_DDL`: The deployment type for updating database schemas (DDL).
69+
- `DATABASE_DDL_GHOST`: The deployment type for updating database schemas using gh-ost.
70+
- `DATABASE_DML`: The deployment type for updating database data (DML).
71+
- `DATABASE_RESTORE_PITR`: The deployment type for performing a Point-in-time Recovery.
72+
- `DATABASE_DML_ROLLBACK`: The deployment type for a generated rollback issue.
7073

7174
For example:
7275

@@ -122,12 +125,15 @@ Sensitive Data Policy is the policy configuration for sensitive data. It is only
122125

123126
Must set the `sensitive_data_policy` if the policy type if `SENSITIVE_DATA`. It contains following attributes:
124127

125-
- `sensitive_data` (List of Object)
126-
- `schema`: The database schema.
127-
- `table`: The database table.
128-
- `column`: The column in table.
129-
- `mask_type`: The sensitive data type to hide data with a default method. Should be one of:
130-
- `DEFAULT`: The default method is subject to change.
128+
- `sensitive_data` (List of Object) A list contains sensitive data.
129+
130+
The object in `sensitive_data` should contains:
131+
132+
- `schema`: The database schema.
133+
- `table`: The database table.
134+
- `column`: The column in table.
135+
- `mask_type`: The sensitive data type to hide data with a default method. Should be one of:
136+
- `DEFAULT`: The default method is subject to change.
131137

132138
For example:
133139

@@ -150,20 +156,44 @@ resource "bytebase_policy" "sensitive_data" {
150156
##### Access Control Policy
151157

152158
Access Control Policy is the policy configuration for database access control. It is only applicable to database and environment resource type.
153-
For environment resource type, `disallow_rules` defines the access control rule.
154-
For database resource type, the access control policy struct itself means allow to access.
159+
160+
- For environment resource type, if the `environment_tier_policy` is set to be `PROTECTED`, the `access_control_policy` is the disallow list for databases in this environment.
161+
- For database resource type, the access control policy means allow to access in this specific database.
155162

156163
Must set the `access_control_policy` if the policy type if `ACCESS_CONTROL`. It contains following attributes:
157164

158-
- `disallow_rules` (List of Object)
165+
- `disallow_rules` (List of Object) The object contains following attribute:
159166
- `full_database` (Boolean) will apply to the full database.
160167

161168
For example:
162169

163170
```terraform
171+
# The prod environment is marked as PROTECTED
172+
resource "bytebase_environment" "prod" {
173+
resource_id = "prod"
174+
title = "Prod"
175+
order = 1
176+
environment_tier_policy = "PROTECTED"
177+
}
178+
179+
# Disallow to access in prod
164180
resource "bytebase_policy" "access_control" {
165-
type = "SENSITIVE_DATA"
166-
environment = "<environment resource id>"
181+
type = "ACCESS_CONTROL"
182+
environment = bytebase_environment.prod.resource_id
183+
184+
access_control_policy {
185+
disallow_rules {
186+
full_database = true
187+
}
188+
}
189+
}
190+
191+
# Allow to access in employee database in prod environment.
192+
resource "bytebase_policy" "access_control" {
193+
type = "ACCESS_CONTROL"
194+
environment = bytebase_environment.prod.resource_id
195+
instance = "<instance resource id for the database>"
196+
database = "employee"
167197
168198
access_control_policy {
169199
disallow_rules {
@@ -180,13 +210,16 @@ SQL Review Policy is the policy for SQL review.
180210
Must set the `sql_review_policy` if the policy type if `SQL_REVIEW`. It contains following attributes:
181211

182212
- `title` (String) The title for SQL review.
183-
- `rules` (List of Object) List of SQL review rules. The rule should a object contains:
184-
- `type` (String) The SQL review rule type. You can check the [code](https://github.com/bytebase/terraform-provider-bytebase/blob/main/api/sql_review.go) to find supported rules.
185-
- `level` (String) The SQL review rule level. Should be one of:
186-
- `ERROR`
187-
- `WARNING`
188-
- `DISABLED`
189-
- `payload` (Object) The payload for SQL review rule.
213+
- `rules` (List of Object) List of SQL review rules.
214+
215+
The rule should a object contains:
216+
217+
- `type` (String) The SQL review rule type. You can check the [code](https://github.com/bytebase/terraform-provider-bytebase/blob/main/api/sql_review.go) to find supported rules.
218+
- `level` (String) The SQL review rule level. Should be one of:
219+
- `ERROR`
220+
- `WARNING`
221+
- `DISABLED`
222+
- `payload` (Object) The payload for SQL review rule.
190223

191224
Please check the doc for details: https://www.bytebase.com/docs/sql-review/review-rules/supported-rules
192225

@@ -240,7 +273,12 @@ Rules to limit the naming format:
240273
- `naming.index.idx`
241274
- `naming.index.uk`
242275

243-
For naming format rules, we need to set the `payload` with `max_length` and `format` attributes. For example:
276+
For naming format rules, we need to set the `payload` with `max_length` and `format` attributes.
277+
278+
- `max_length` (Number) Maximum length for the name.
279+
- `format` (String) Naming format in regex string.
280+
281+
For example:
244282

245283
```terraform
246284
resource "bytebase_policy" "sql_review" {
@@ -302,6 +340,8 @@ Rules to limit by a specific number.
302340

303341
For number limit rules, we need to set the `payload` with `number` attribute. For example:
304342

343+
- `number` (Number) The number limit.
344+
305345
```terraform
306346
resource "bytebase_policy" "sql_review" {
307347
type = "SQL_REVIEW"
@@ -332,6 +372,8 @@ Rules define the allow or disallow list.
332372

333373
For list limit rules, we need to set the `payload` with `list` attribute. For example:
334374

375+
- `list` (List of String) The allow or disallow list.
376+
335377
```terraform
336378
resource "bytebase_policy" "sql_review" {
337379
type = "SQL_REVIEW"

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Examples of using the Terraform Bytebase Provider to manage your resource:
66
- [environments](./environments): Use the Bytebase provider to query the environment.
77
- [instances](./instances): Use the Bytebase provider to query the instance.
88
- [role](./role): Use the Bytebase provider to manage instance role in your instance.
9+
- [policies](./policies): Use the Bytebase provider to query the policy.
910

1011
To run this provider on your local machine:
1112

provider/resource_environment.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ func resourceEnvironment() *schema.Resource {
4747
},
4848
"environment_tier_policy": {
4949
Type: schema.TypeString,
50-
Optional: true,
51-
Default: "UNPROTECTED",
50+
Required: true,
5251
ValidateFunc: validation.StringInSlice([]string{
5352
"PROTECTED",
5453
"UNPROTECTED",

0 commit comments

Comments
 (0)