Skip to content

Commit 5c57f7f

Browse files
authored
chore: update terraform provider example (#63)
1 parent b93f074 commit 5c57f7f

File tree

11 files changed

+42
-38
lines changed

11 files changed

+42
-38
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ jobs:
5151
go test -v -cover ./...
5252
env:
5353
TF_ACC: '1'
54-
BYTEBASE_SERVICE_ACCOUNT: 'test@service.bytebase.com'
55-
BYTEBASE_SERVICE_KEY: 'test_secret'
56-
BYTEBASE_URL: 'https://bytebase.example.com'
54+
BYTEBASE_SERVICE_ACCOUNT: 'terraform@service.bytebase.com'
55+
BYTEBASE_SERVICE_KEY: ${{ secrets.BTYEBASE_SERVICE_KEY }}
56+
BYTEBASE_URL: 'https://tf.bytebase.com'

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ examples/terraform.*
1414
crash.log
1515
crash.*.log
1616

17+
# Misc
18+
**/.DS_Store
19+
1720
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
1821
# password, private keys, and other secrets. These should not be part of version
1922
# control as they are data points which are potentially sensitive and subject

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ cd terraform-provider-bytebase && make install
4646

4747
# initialize the terraform for your example
4848
# you need to set the service_account and service_key to your own
49-
cd examples && terraform init
49+
cd examples/setup && terraform init
5050

5151
# check the changes
5252
terraform plan
@@ -77,5 +77,5 @@ Follow [this doc](https://developer.hashicorp.com/terraform/registry/providers/p
7777
> We need to publish a new tag for a new version, the tag must be a valid [Semantic Version](https://semver.org/) **preceded with a v (for example, v1.2.3)**. There must not be a branch name with the same name as the tag.
7878
7979
1. Develop and merge the feature code.
80-
2. Create a new PR to update the version in [`./VERSION`](./VERSION)
81-
3. After the version is updated, the action [`./.github/workflows/release.yml`](./.github/workflows/release.yml) will use the newest version `x.y.z` to create a new tag `vx.y.z`, then use the tag to create the release.
80+
1. Create a new PR to update the version in [`./VERSION`](./VERSION)
81+
1. After the version is updated, the action [`./.github/workflows/release.yml`](./.github/workflows/release.yml) will use the newest version `x.y.z` to create a new tag `vx.y.z`, then use the tag to create the release.

examples/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ Examples of using the Terraform Bytebase Provider to manage your resource:
55
- [setup](./setup): Initialize the data.
66
- [environments](./environments): Use the Bytebase provider to query the environment.
77
- [instances](./instances): Use the Bytebase provider to query the instance.
8-
- [roles](./roles): Use the Bytebase provider to manage instance role in your instance.
9-
- [projects](./projects): Use the Bytebase provider to query projects in your Bytebase instance.
8+
- [roles](./roles): Use the Bytebase provider to manage instance role in your instance.
9+
- [projects](./projects): Use the Bytebase provider to query projects in your Bytebase instance.
1010

1111
To run this provider on your local machine:
1212

1313
1. Run your Bytebase service, then you can access the service via `http://localhost:8080`.
14-
2. Create the service account. Docs [Create service account](https://www.bytebase.com/docs/get-started/terraform#create-service-account).
15-
3. Replace the `service_account` and `service_key` with your Bytebase service account, and replace the `url` with your Bytebase service URL.
16-
4. Go to the [setup](./setup) to initialize the data.
17-
5. Go to the `environments`/`instances`/`role`/`projects` folder to query the data.
18-
6. Go to the [setup](./setup) and run `terraform destory` to delete the test resources.
14+
1. Create the service account. Docs [Create service account](https://www.bytebase.com/docs/get-started/terraform#create-service-account).
15+
1. Replace the `service_account` and `service_key` with your Bytebase service account, and replace the `url` with your Bytebase service URL.
16+
1. Go to the [setup](./setup) to initialize the data.
17+
1. Go to the `environments`/`instances`/`role`/`projects` folder to query the data.
18+
1. Go to the [setup](./setup) and run `terraform destory` to delete the test resources.
1919

2020
To run this provider for development and testing:
2121

2222
1. Replace the source `registry.terraform.io/bytebase/bytebase` with `terraform.local/bytebase/bytebase`.
23-
2. Run `make install` under the `terraform-provider-bytebase` folder.
24-
3. Go to example folders and run `terraform init`.
23+
1. Run `make install` under the `terraform-provider-bytebase` folder.
24+
1. Go to example folders and run `terraform init`.

examples/instances/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ provider "bytebase" {
1919
}
2020

2121
locals {
22-
instance_id_test = "test-instance"
23-
instance_id_prod = "prod-instance"
22+
instance_id_test = "test-sample-instance"
23+
instance_id_prod = "prod-sample-instance"
2424
}
2525

2626
# List all instances in all environments

examples/projects/main.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ provider "bytebase" {
1919
}
2020

2121
locals {
22-
project_id_test = "project-test"
22+
project_id = "project-sample"
2323
}
2424

2525
# List all projects
@@ -30,10 +30,10 @@ output "all_projects" {
3030
}
3131

3232
# Find a specific project by name
33-
data "bytebase_project" "test_project" {
34-
resource_id = local.project_id_test
33+
data "bytebase_project" "sample_project" {
34+
resource_id = local.project_id
3535
}
3636

37-
output "test_project" {
38-
value = data.bytebase_project.test_project
37+
output "sample_project" {
38+
value = data.bytebase_project.sample_project
3939
}

examples/roles/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ provider "bytebase" {
1919

2020
locals {
2121
role_name = "role_test_terraform"
22-
instance_id_test = "test-instance"
22+
instance_id_test = "test-sample-instance"
2323
}
2424

2525
# Find the instance
2626
data "bytebase_instance" "test" {
2727
resource_id = local.instance_id_test
2828
}
2929

30-
# Find the role "role_test_terraform" in the instance "test-instance"
30+
# Find the role "role_test_terraform" in the instance "test-sample-instance"
3131
data "bytebase_instance_role" "test" {
3232
name = local.role_name
3333
instance = data.bytebase_instance.test.resource_id
@@ -37,7 +37,7 @@ output "role" {
3737
value = data.bytebase_instance_role.test
3838
}
3939

40-
# List all roles in the instance "test-instance"
40+
# List all roles in the instance "test-sample-instance"
4141
data "bytebase_instance_role_list" "all" {
4242
instance = data.bytebase_instance.test.resource_id
4343
}

examples/setup/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ We will create two environments named `dev` and `prod`. Each environment contain
66
Before you start, please make sure you have running your Bytebase service and have created the service account, and replace the provider initial variables. Check the [README](../README.md) for details.
77

88
1. Run `terraform init` to install the provider.
9-
2. Run `terraform plan` to check the changes.
10-
3. Run `terraform apply` to apply the changes.
9+
1. Run `terraform plan` to check the changes.
10+
1. Run `terraform apply` to apply the changes.

examples/setup/main.tf

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ provider "bytebase" {
1717
url = "https://bytebase.example.com"
1818
}
1919

20+
# Correspond to the sample data Bytebase generates during onboarding.
2021
locals {
2122
environment_id_test = "test"
2223
environment_id_prod = "prod"
23-
instance_id_test = "test-instance"
24-
instance_id_prod = "prod-instance"
24+
instance_id_test = "test-sample-instance"
25+
instance_id_prod = "prod-sample-instance"
2526
role_name = "role_test_terraform"
26-
project_id_test = "project-test"
27+
project_id = "project-sample"
2728
}
2829

2930
# Create a new environment named "Test"
@@ -89,10 +90,10 @@ resource "bytebase_instance" "prod" {
8990
}
9091
}
9192

92-
# Create a new role named "role_test_terraform" in the instance "test-instance"
93+
# Create a new role named "role_test_terraform" in the instance "test-sample-instance"
9394
resource "bytebase_instance_role" "test" {
9495
name = local.role_name
95-
instance = bytebase_instance.test.resource_id
96+
instance = bytebase_instance.sample.resource_id
9697

9798
password = "123456"
9899
connection_limit = 10
@@ -110,10 +111,10 @@ resource "bytebase_instance_role" "test" {
110111
}
111112

112113
# Create a new project
113-
resource "bytebase_project" "test_project" {
114-
resource_id = local.project_id_test
115-
title = "Test project"
116-
key = "BYT"
114+
resource "bytebase_project" "sample_project" {
115+
resource_id = local.project_id
116+
title = "Sample project"
117+
key = "SAM"
117118
workflow = "UI"
118119
schema_version = "SEMANTIC"
119120
schema_change = "DDL"

provider/data_source_database_role_list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
func TestAccInstanceRoleListDataSource(t *testing.T) {
13-
instanceName := "test-instance"
13+
instanceName := "test-sample-instance"
1414
roleName := "test_role"
1515
outputName := "role_list"
1616
resourceName := fmt.Sprintf("data.bytebase_instance_role_list.%s", outputName)

0 commit comments

Comments
 (0)