| 
 | 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 | +# (Optional) Reference to instances and environments from previous setup  | 
 | 18 | +# You should already have bytebase_instance.test and bytebase_instance.prod defined  | 
 | 19 | + | 
 | 20 | +# (Optional) List existing databases for introspection:  | 
 | 21 | +data "bytebase_database_list" "all" {  | 
 | 22 | +  parent = "workspaces/-"  | 
 | 23 | +}  | 
 | 24 | + | 
 | 25 | +output "current_databases" {  | 
 | 26 | +  value = data.bytebase_database_list.all.databases  | 
 | 27 | +}  | 
 | 28 | + | 
 | 29 | +# Create a new project and assign specific databases  | 
 | 30 | +resource "bytebase_project" "another" {  | 
 | 31 | +  depends_on = [  | 
 | 32 | +    bytebase_instance.test  | 
 | 33 | +  ]  | 
 | 34 | +  resource_id = "another-project"  | 
 | 35 | +  title       = "Another project"  | 
 | 36 | + | 
 | 37 | +  databases = [  | 
 | 38 | +    "instances/mysql-test/databases/demo"  | 
 | 39 | +  ]  | 
 | 40 | +}  | 
 | 41 | + | 
 | 42 | +# (Optional) Add more databases using multiple instances  | 
 | 43 | +# resource "bytebase_project" "another_with_more" {  | 
 | 44 | +#   depends_on = [  | 
 | 45 | +#     bytebase_instance.test,  | 
 | 46 | +#     bytebase_instance.prod  | 
 | 47 | +#   ]  | 
 | 48 | +#   resource_id = "another-with-more"  | 
 | 49 | +#   title       = "Another project with more"  | 
 | 50 | +#   | 
 | 51 | +#   databases = [  | 
 | 52 | +#     "instances/mysql-test/databases/demo",  | 
 | 53 | +#     "instances/mysql-prod/databases/app_prod"  | 
 | 54 | +#   ]  | 
 | 55 | +# }  | 
 | 56 | + | 
 | 57 | +# (Optional)  Use all databases from an instance dynamically  | 
 | 58 | +# resource "bytebase_project" "test_apps" {  | 
 | 59 | +#   depends_on = [  | 
 | 60 | +#     bytebase_instance.test  | 
 | 61 | +#   ]  | 
 | 62 | +#   resource_id = "test-applications"  | 
 | 63 | +#   title       = "Test Applications"  | 
 | 64 | +#   | 
 | 65 | +#   databases = bytebase_instance.test.databases  | 
 | 66 | +# }  | 
0 commit comments