Terraform variables for setting MySQL database flags

Are there Terraform variables for setting Cloud MySQL database flags?

For starters, such as:

sql_mode

activate_all_roles_on_login

Thanks

Gillian

1 Like

Hi @Gillian ,

Welcome to Google Cloud Community!

Yes, Terraform provides variables for setting flags for Google Cloud SQL databases. You can use the google_sql_database_instance resource in Terraform to configure your MySQL database, including setting flags such as sql_mode and activate_all_roles_on_login.

Here’s an example of how you can set the sql_mode flag in Terraform (python):

resource "google_sql_database_instance" "instance" {
    name = "example-instance"
    database_version = "MYSQL_8_0"
    settings {
        tier = "db-n1-standard-2" 
        activation_policy = "ALWAYS" 
        database_flags { 
            name = "sql_mode" 
            value = "STRICT_TRANS_TABLES" 
        } 
    } 
}

And here’s an example of how you can set the activate_all_roles_on_login flag:

resource "google_sql_database_instance" "instance" { 
    name = "example-instance" 
    database_version = "MYSQL_8_0" 
    settings { 
        tier = "db-n1-standard-2" 
        activation_policy = "ALWAYS" 
        database_flags { 
            name = "activate_all_roles_on_login"
            value = "ON" 
        } 
    } 
}

You may check this documentation on Google Cloud SQL Guides: Configure database flags.

Thank you.

1 Like