Define your MySQL Configuration Variables on OCI with Terraform

With Terraform OCI provider 4.90.0 (released August 24th, 2022), we have added the possibility to specify the value of editable configuration variables directly from Terraform.

These variables must be defined in a resource of type oci_mysql_mysql_configuration like this:

resource "oci_mysql_mysql_configuration" "mds_mysql_configuration" {
	#Required
	compartment_id = var.compartment_ocid
    shape_name   = var.mysql_shape

	#Optional
	description = "MDS configuration created by terraform"
	display_name = "MDS terraform configuration"
	parent_configuration_id = data.oci_mysql_mysql_configurations.mds_mysql_configurations.configurations[0].id
	variables {
		#Optional
		max_connections = "501"
        binlog_expire_logs_seconds = "7200"
	}
}

We can see from the code above that we have changed the value of two variables: max_connections and binlog_expire_logs_seconds.

We can also notice that a parent configuration id must be provided. The parent configuration id can be selected from the existing configurations (default or custom). This is how you can define the parent configuration:

data "oci_mysql_mysql_configurations" "mds_mysql_configurations" {
  compartment_id = var.compartment_ocid

  #Optional
  state        = "ACTIVE"
  shape_name   = var.mysql_shape
}

And finally the MySQL configuration resource created must be applied to the MySQL instance resource we want to deploy (line 6 on the code below):

resource "oci_mysql_mysql_db_system" "MDSinstance" {
    admin_password = var.admin_password
    admin_username = var.admin_username
    availability_domain = var.availability_domain
    compartment_id = var.compartment_ocid
    configuration_id = oci_mysql_mysql_configuration.mds_mysql_configuration.id
    shape_name = var.mysql_shape
    subnet_id = var.subnet_id
    data_storage_size_in_gb = var.mysql_data_storage_in_gb
    display_name = var.display_name

    count = var.existing_mds_instance_id == "" ? 1 : 0

    is_highly_available = var.deploy_ha
}

When the Terraform environment is deployed, in OCI’s console we can see that a the MySQL DB system is using the new configuration we created:

If we verify the value of the variables in this configuration we can see that it contains the default values for all the variables but the two we defined in our Terraform file:

Many people were requesting this feature that is now available !

Don’t forget that not all variables can be modified in MySQL HeatWave Database Service. Only those called User Variables can be modified. You can find the list of those User Variables on this page.

A full example to deploy a MySQL Database Service on OCI is available on this GitHub repo.

Don’t forget that if you want to connect to your MySQL DB instance as a developer, the easiest way is to use MySQL Shell for Visual Studio Code:

As usual, enjoy MySQL and happy deployment on OCI with Terraform !

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Leave a Reply

Your email address will not be published. Required fields are marked *

As MySQL Community Manager, I am an employee of Oracle and the views expressed on this blog are my own and do not necessarily reflect the views of Oracle.

You can find articles I wrote on Oracle’s blog.