Deploy product module

The MySQL product Terraform module is the set of recommended charms to be deployed using Terraform, only containing Data-Platform owned charms by default. It could be extended with the addition of TLS and COS (Canonical Observability Stack) charms to build more complex setups.

Install Terraform tooling

This guide assumes Juju is installed, and you have an LXD controller already bootstrapped. For more information, check the Charmed MySQL tutorial.

Let’s install the Terraform and YQ snaps:

sudo snap install terraform --classic
sudo snap install yq

Switch to the LXD provider and create a new model:

juju switch lxd
juju add-model my-model
juju show-model my-model | yq '."my-model"."model-uuid"'

Clone the MySQL operator repository and navigate to the terraform module:

git clone https://github.com/canonical/mysql-bundle.git
cd terraform

Initialise the Juju Terraform Provider:

terraform init

Verify the deployment

Open the main.tf file to see the brief contents of the Terraform module, and run terraform plan to get a preview of the changes that will be made:

terraform plan -var 'model=<model-uuid>'

Apply the deployment

Default charms

The default MySQL product module deploys MySQL Server, MySQL Router and S3 Integrator charms. In order to deploy those resources:

terraform apply -auto-approve \
    -var 'model=<model-uuid>'

Extended charms

The extended MySQL product module deploys self-signed-certificates and grafana-agent charms on top. In order to deploy all resources:

terraform apply -auto-approve \
    -var 'model=<model-uuid>' \
    -var 'tls_offer=certificates' \
    -var 'cos_offers={"dashboard"="cos-agent"}'

It is possible to substitute both of these charms by overwriting some of the module variables.

For instance, the self-signed-certificates charm is used to provide the TLS certificates, but it is not a production-ready charm. It must be changed before deploying on a real environment. As an alternative, the manual-tls-certificates could be used.

terraform apply -auto-approve \
    -var 'model=<model-uuid>' \
    -var 'tls_offer=certificates' \
    -var 'certificates={"app_name"="manual-tls-certificates","base"="[email protected]","channel"="latest/stable"}'

Configure the deployment

The S3 Integrator charm needs to be configured for it to work properly. Wait until it reaches blocked status and run:

juju run s3-integrator/leader sync-s3-credentials \
    access-key=<access-key> \
    secret-key=<secret-key>

Check deployment status

Check the deployment status with

juju status --model lxd:my-model --watch 1s

Sample output:

Model     Controller      Cloud/Region         Version  SLA          Timestamp
my-model  lxd-controller  localhost/localhost  3.5.3    unsupported  12:49:34Z

App            Version          Status  Scale  Charm          Channel        Rev  Exposed  Message                                
mysql          8.0.41-0ubun...  active      3  mysql          8.0/stable     366  no
mysql-router                    unknown     0  mysql-router   dpe/candidate  355  no
s3-integrator                   active      1  s3-integrator  1/stable       241  no

Unit              Workload  Agent  Machine  Public address  Ports           Message
mysql/0*          active    idle   0        10.101.248.220  3306,33060/tcp  Primary
mysql/1           active    idle   1        10.101.248.221                  Primary
mysql/2           active    idle   2        10.101.248.222                  Primary
s3-integrator/0*  active    idle   3        10.101.248.223

Machine  State    Address         Inst id        Base          AZ  Message
0        started  10.101.248.220  juju-c4a403-0  [email protected]      Running
1        started  10.101.248.221  juju-c4a403-1  [email protected]      Running
2        started  10.101.248.222  juju-c4a403-2  [email protected]      Running
3        started  10.101.248.223  juju-c4a403-3  [email protected]      Running

Continue to operate the charm as usual from here or apply further Terraform changes.

Clean up

To keep the house clean, remove the newly deployed MySQL charm by running

terraform destroy -var 'model=<model-uuid>'

Feel free to contact us if you have any question and collaborate with us on GitHub!