Deploy charm module¶
The MySQL charm Terraform module is the smallest unit that can be deployed using Terraform, only containing the MySQL Server charm. It is supposed to be deployed alongside other charms to build a more complex setup.
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-operator.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¶
If everything looks correct, deploy the resources (skip the approval):
terraform apply -auto-approve -var 'model=<model-uuid>'
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      1  mysql  8.0/stable  366  no
Unit      Workload  Agent  Machine  Public address  Ports           Message
mysql/0*  active    idle   0        10.101.248.220  3306,33060/tcp  Primary
Machine  State    Address         Inst id        Base          AZ  Message
0        started  10.101.248.220  juju-c4a403-0  [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!
