# Read current environment settings from Bytebasedata "bytebase_setting" "environments" { name = "settings/ENVIRONMENT"}# Display all environmentsoutput "all_environments" { value = data.bytebase_setting.environments}
Run these commands:
Copy
Ask AI
terraform planterraform apply
You’ll see the existing test and prod environments.
# Define environments as Infrastructure as Coderesource "bytebase_setting" "environments" { name = "settings/ENVIRONMENT" environment_setting { # Test environment - for development environment { id = "test" title = "Test" protected = false } # Production environment - needs protection environment { id = "prod" title = "Prod" ## Bytebase will attach a shield icon 🛡️ besides the environment name. protected = true } }}
roles is the list of roles that are allowed to click the button to roll out the changes manually. Even automatic rollout is enabled, manual approval is still needed while there is any automatic check failure.
# Prevent copying data in SQL Editor from productionresource "bytebase_policy" "disable_copy_data_policy_prod" { depends_on = [bytebase_setting.environments] parent = bytebase_setting.environments.environment_setting[0].environment[1].name type = "DISABLE_COPY_DATA" disable_copy_data_policy { enable = true # Block data copy }}# Restrict SQL execution in SQL Editor from productionresource "bytebase_policy" "data_source_query_policy_prod" { depends_on = [bytebase_setting.environments] parent = bytebase_setting.environments.environment_setting[0].environment[1].name type = "DATA_SOURCE_QUERY" data_source_query_policy { restriction = "RESTRICTION_UNSPECIFIED" disallow_ddl = true # No schema changes via SQL Editor disallow_dml = true # No data changes via SQL Editor }}
Here data protection policy is only applied to the Prod environment. Which means in Test environment, by default, users may execute DDL and DML statements or copy data directly in SQL Editor.