Skip to content

Commit 8551dfc

Browse files
[DPE-8291] Extend Terraform deployment docs (#695)
1 parent 3e7eaea commit 8551dfc

File tree

5 files changed

+245
-140
lines changed

5 files changed

+245
-140
lines changed

docs/how-to/deploy/index.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ AWS EC2 <aws-ec2>
1111
GCE <gce>
1212
Azure <azure>
1313
Multi-AZ <multi-az>
14-
Terraform <terraform>
1514
Air-gapped <air-gapped>
1615
Juju spaces <juju-spaces>
1716
```
17+
18+
## Terraform
19+
20+
```{toctree}
21+
:titlesonly:
22+
:maxdepth: 2
23+
24+
Terraform <terraform/index>
25+
```

docs/how-to/deploy/terraform.md

Lines changed: 0 additions & 139 deletions
This file was deleted.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Deploy charm module
2+
3+
The MySQL _charm_ Terraform module is the smallest unit that can be deployed using Terraform,
4+
only containing the MySQL Server charm. It is supposed to be deployed alongside other charms
5+
to build a more complex setup.
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-operator.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_name=my-model'
40+
```
41+
42+
## Apply the deployment
43+
44+
If everything looks correct, deploy the resources (skip the approval):
45+
46+
```shell
47+
terraform apply -auto-approve -var 'model_name=my-model'
48+
```
49+
50+
## Check deployment status
51+
52+
Check the deployment status with
53+
54+
```shell
55+
juju status --model lxd:my-model --watch 1s
56+
```
57+
58+
Sample output:
59+
60+
```shell
61+
Model Controller Cloud/Region Version SLA Timestamp
62+
my-model lxd-controller localhost/localhost 3.5.3 unsupported 12:49:34Z
63+
64+
App Version Status Scale Charm Channel Rev Exposed Message
65+
mysql 8.0.41-0ubun... active 1 mysql 8.0/stable 366 no
66+
67+
Unit Workload Agent Machine Public address Ports Message
68+
mysql/0* active idle 0 10.101.248.220 3306,33060/tcp Primary
69+
70+
Machine State Address Inst id Base AZ Message
71+
0 started 10.101.248.220 juju-c4a403-0 [email protected] Running
72+
```
73+
74+
Continue to operate the charm as usual from here or apply further Terraform changes.
75+
76+
## Clean up
77+
78+
To keep the house clean, remove the newly deployed MySQL charm by running
79+
```shell
80+
terraform destroy -var 'model_name=my-model'
81+
```
82+
83+
---
84+
85+
Feel free to [contact us](/reference/contacts) if you have any question and collaborate with us on GitHub!
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# How to deploy using Terraform
2+
3+
[Terraform](https://www.terraform.io/) is an infrastructure automation tool to provision and manage resources in clouds or data centers.
4+
To deploy Charmed MySQL using Terraform and Juju, you can use the [Juju Terraform Provider](https://registry.terraform.io/providers/juju/juju/latest).
5+
6+
For an in-depth introduction to the Juju Terraform Provider, read [this Discourse post](https://discourse.charmhub.io/t/6939).
7+
8+
```{toctree}
9+
:titlesonly:
10+
:maxdepth: 2
11+
12+
Charm <charm>
13+
Product <product>
14+
```
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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

Comments
 (0)