Skip to content

Commit 0866b89

Browse files
Create main.tf
1 parent 4387299 commit 0866b89

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

tutorials/1_databases/main.tf

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
terraform {
2+
required_providers {
3+
bytebase = {
4+
version = "3.8.0"
5+
# For local development, please use "terraform.local/bytebase/bytebase" instead
6+
source = "registry.terraform.io/bytebase/bytebase"
7+
}
8+
}
9+
}
10+
11+
provider "bytebase" {
12+
service_account = "[email protected]"
13+
service_key = "bbs_xxxx"
14+
url = "https://xxx.xxx.xxx"
15+
}
16+
17+
# Local environment IDs
18+
locals {
19+
environment_id_test = "test"
20+
environment_id_prod = "prod"
21+
}
22+
23+
# Environment configuration (step 4a)
24+
resource "bytebase_setting" "environments" {
25+
name = "settings/ENVIRONMENT"
26+
27+
environment_setting {
28+
environment {
29+
id = local.environment_id_test
30+
title = "Test"
31+
protected = false
32+
}
33+
environment {
34+
id = local.environment_id_prod
35+
title = "Prod"
36+
protected = true
37+
}
38+
}
39+
}
40+
41+
# MySQL test instance
42+
resource "bytebase_instance" "test" {
43+
depends_on = [bytebase_setting.environments]
44+
resource_id = "mysql-test"
45+
environment = "environments/${local.environment_id_test}"
46+
title = "MySQL test"
47+
engine = "MYSQL"
48+
activation = false
49+
50+
data_sources {
51+
id = "admin data source mysql-test"
52+
type = "ADMIN"
53+
host = "host.docker.internal"
54+
port = "3307"
55+
username = "root"
56+
password = "testpwd1"
57+
}
58+
}
59+
60+
# MySQL production instance
61+
resource "bytebase_instance" "prod" {
62+
depends_on = [bytebase_setting.environments]
63+
resource_id = "mysql-prod"
64+
environment = "environments/${local.environment_id_prod}"
65+
title = "MySQL prod"
66+
engine = "MYSQL"
67+
activation = false
68+
69+
data_sources {
70+
id = "admin data source mysql-prod"
71+
type = "ADMIN"
72+
host = "host.docker.internal"
73+
port = "3308"
74+
username = "root"
75+
password = "testpwd1"
76+
}
77+
}

0 commit comments

Comments
 (0)