|
| 1 | +# Deploy product module |
| 2 | + |
| 3 | +The MySQL _product_ Terraform module is the set of recommended charms to be deployed using Terraform, |
| 4 | +only containing Data-Platform owned charms by default. It could be extended with the addition of |
| 5 | +TLS and COS (_Canonical Observability Stack_) charms to build more complex setups. |
| 6 | + |
| 7 | +## Install Terraform tooling |
| 8 | + |
| 9 | +This guide assumes Juju is installed, and you have an LXD controller already bootstrapped. |
| 10 | +For more information, check the [Charmed MySQL tutorial](/tutorial/index). |
| 11 | + |
| 12 | +Let's install Terraform Provider and example modules: |
| 13 | +```shell |
| 14 | +sudo snap install terraform --classic |
| 15 | +``` |
| 16 | + |
| 17 | +Switch to the LXD provider and create a new model: |
| 18 | +```shell |
| 19 | +juju switch lxd |
| 20 | +juju add-model my-model |
| 21 | +``` |
| 22 | + |
| 23 | +Clone the MySQL operator repository and navigate to the terraform module: |
| 24 | +```shell |
| 25 | +git clone https://github.com/canonical/mysql-bundle.git |
| 26 | +cd terraform |
| 27 | +``` |
| 28 | + |
| 29 | +Initialise the Juju Terraform Provider: |
| 30 | +```shell |
| 31 | +terraform init |
| 32 | +``` |
| 33 | + |
| 34 | +## Verify the deployment |
| 35 | + |
| 36 | +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: |
| 37 | + |
| 38 | +```shell |
| 39 | +terraform plan -var 'model=my-model' |
| 40 | +``` |
| 41 | + |
| 42 | +## Apply the deployment |
| 43 | + |
| 44 | +### Default charms |
| 45 | + |
| 46 | +The default MySQL product module deploys MySQL Server, MySQL Router and S3 Integrator charms. |
| 47 | +In order to deploy those resources: |
| 48 | + |
| 49 | +```shell |
| 50 | +terraform apply -auto-approve \ |
| 51 | + -var 'model=my-model' |
| 52 | +``` |
| 53 | + |
| 54 | +### Extended charms |
| 55 | + |
| 56 | +The extended MySQL product module deploys [self-signed-certificates](https://charmhub.io/self-signed-certificates) and [grafana-agent](https://charmhub.io/grafana-agent) charms on top. |
| 57 | +In order to deploy all resources: |
| 58 | + |
| 59 | +```shell |
| 60 | +terraform apply -auto-approve \ |
| 61 | + -var 'model=my-model' \ |
| 62 | + -var 'tls_offer=certificates' \ |
| 63 | + -var 'cos_offers={"dashboard"="cos-agent"}' |
| 64 | +``` |
| 65 | + |
| 66 | +It is possible to substitute both of these charms by overwriting some of the module variables. |
| 67 | + |
| 68 | +For instance, the `self-signed-certificates` charm is used to provide the TLS certificates, |
| 69 | +but it is not a _production-ready_ charm. It must be changed before deploying on a real environment. |
| 70 | +As an alternative, the [manual-tls-certificates](https://charmhub.io/manual-tls-certificates) could be used. |
| 71 | + |
| 72 | +```shell |
| 73 | +terraform apply -auto-approve \ |
| 74 | + -var 'model=my-model' \ |
| 75 | + -var 'tls_offer=certificates' \ |
| 76 | + -var 'certificates={"app_name"="manual-tls-certificates","base"="[email protected]","channel"="latest/stable"}' |
| 77 | +``` |
| 78 | + |
| 79 | +## Configure the deployment |
| 80 | + |
| 81 | +The S3 Integrator charm needs to be configured for it to work properly. |
| 82 | +Wait until it reaches `blocked` status and run: |
| 83 | + |
| 84 | +```shell |
| 85 | +juju run s3-integrator/leader sync-s3-credentials \ |
| 86 | + access-key=<access-key> \ |
| 87 | + secret-key=<secret-key> |
| 88 | +``` |
| 89 | + |
| 90 | +```{seealso} |
| 91 | +[](/how-to/back-up-and-restore/configure-s3-aws) |
| 92 | +``` |
| 93 | + |
| 94 | +## Check deployment status |
| 95 | + |
| 96 | +Check the deployment status with |
| 97 | + |
| 98 | +```shell |
| 99 | +juju status --model lxd:my-model --watch 1s |
| 100 | +``` |
| 101 | + |
| 102 | +Sample output: |
| 103 | + |
| 104 | +```shell |
| 105 | +Model Controller Cloud/Region Version SLA Timestamp |
| 106 | +my-model lxd-controller localhost/localhost 3.5.3 unsupported 12:49:34Z |
| 107 | + |
| 108 | +App Version Status Scale Charm Channel Rev Exposed Message |
| 109 | +mysql 8.0.41-0ubun... active 3 mysql 8.0/stable 366 no |
| 110 | +mysql-router unknown 0 mysql-router dpe/candidate 355 no |
| 111 | +s3-integrator active 1 s3-integrator 1/stable 241 no |
| 112 | + |
| 113 | +Unit Workload Agent Machine Public address Ports Message |
| 114 | +mysql/0* active idle 0 10.101.248.220 3306,33060/tcp Primary |
| 115 | +mysql/1 active idle 1 10.101.248.221 Primary |
| 116 | +mysql/2 active idle 2 10.101.248.222 Primary |
| 117 | +s3-integrator/0* active idle 3 10.101.248.223 |
| 118 | + |
| 119 | +Machine State Address Inst id Base AZ Message |
| 120 | +0 started 10.101.248.220 juju-c4a403-0 [email protected] Running |
| 121 | +1 started 10.101.248.221 juju-c4a403-1 [email protected] Running |
| 122 | +2 started 10.101.248.222 juju-c4a403-2 [email protected] Running |
| 123 | +3 started 10.101.248.223 juju-c4a403-3 [email protected] Running |
| 124 | +``` |
| 125 | + |
| 126 | +Continue to operate the charm as usual from here or apply further Terraform changes. |
| 127 | + |
| 128 | +## Clean up |
| 129 | + |
| 130 | +To keep the house clean, remove the newly deployed MySQL charm by running |
| 131 | +```shell |
| 132 | +terraform destroy -var 'model=my-model' |
| 133 | +``` |
| 134 | + |
| 135 | +--- |
| 136 | + |
| 137 | +Feel free to [contact us](/reference/contacts) if you have any question and collaborate with us on GitHub! |
0 commit comments