Skip to content

Commit c349890

Browse files
[DPE-7706] Update PostgreSQL TF module (#1052)
* [DPE-7706] Update PostgreSQL TF module * add README.md to describe usage and link to docs * add constraints/storage directive examples to README.md * add variable to define target machine to deploy charm * apply PG16 storage changes (redefine as map for storage directives) * sync laout with MySQL TF module * skip GH CI tests for TF only changes * ignore terraform runtime files * Update README.md to match branch 16/edge + layout fix * Make README.mb better readable * Align quotes style for all TF commands
1 parent 239322e commit c349890

File tree

6 files changed

+113
-14
lines changed

6 files changed

+113
-14
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ on:
1515
- '**.md'
1616
- .github/renovate.json5
1717
- 'docs/**'
18+
- 'terraform/**'
1819
schedule:
1920
- cron: '53 0 * * *' # Daily at 00:53 UTC
2021
# Triggered on push to branch "main" by .github/workflows/release.yaml

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@ requirements-last-build.txt
1515

1616
# LXD profile used for deployment on local development environment.
1717
lxd-profile.yaml
18+
19+
# Terraform runtime
20+
terraform/.terraform.lock.hcl
21+
terraform/.terraform/
22+
terraform/terraform.tfstate
23+
terraform/terraform.tfstate.backup

terraform/README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Terraform module for Charmed PostgreSQL
2+
3+
This is a Terraform module facilitating the deployment of Charmed PostgreSQL,
4+
using the [Terraform juju provider](https://github.com/juju/terraform-provider-juju/).
5+
For more information, refer to the provider
6+
[documentation](https://registry.terraform.io/providers/juju/juju/latest/docs)
7+
and [deployment tutorial](https://charmhub.io/postgresql/docs/h-deploy-terraform).
8+
9+
## Requirements
10+
11+
| Name | Version |
12+
|------|---------|
13+
| terraform | >= 1.6.6 |
14+
| juju provider | >= 0.14.0 |
15+
16+
## Usage
17+
18+
Users should ensure that Juju model has been created to deploy into:
19+
```
20+
juju add-model welcome
21+
```
22+
23+
To deploy Charmed PostgreSQL into the model `welcome`, run:
24+
```
25+
terraform apply -var='juju_model_name=welcome' -auto-approve
26+
```
27+
28+
By default, this Terraform module will deploy PostgreSQL with `1` unit only.
29+
To configure the module to deploy `3` units, run:
30+
```
31+
terraform apply -var='juju_model_name=welcome' -var='units=3' -auto-approve
32+
```
33+
34+
The juju storage directives config example:
35+
```
36+
terraform apply -var='juju_model_name=welcome' -auto-approve \
37+
-var='storage={data="10G", archive="2G,lxd", logs="3G", temp="tmpfs,2G"}'
38+
```
39+
40+
The juju constraints example:
41+
```
42+
terraform apply -var='juju_model_name=welcome' -auto-approve \
43+
-var='constraints=arch=amd64 cores=4 mem=4096M virt-type=virtual-machine'
44+
```
45+
46+
Example of deploying to the specific Juju machine:
47+
```
48+
juju add-machine
49+
> created machine 19
50+
51+
terraform apply -var='juju_model_name=welcome' -var='machine=19'
52+
```
53+
Note: the module variables `units` and `machine` are self-exclusive.
54+
55+
Check [Charmed PostgreSQL Deployment How-to](https://charmhub.io/postgresql/docs/h-deploy-terraform) for more examples.
56+
57+
## Inputs
58+
59+
| Name | Description | Type | Default | Required |
60+
|------|-------------|------|---------|:--------:|
61+
| juju_model_name | Juju model name (to deployed into) | `string` | n/a | yes |
62+
| charm_name | Name of the charm on charmhub.io to deploy | `string` | `postgresql` | no |
63+
| app_name | Name of the deployed application in the Juju model | `string` | `postgresql` | no |
64+
| channel | Charm channel to use when deploying | `string` | `16/stable` | no |
65+
| revision | Revision number to deploy charm | `number` | n/a | no |
66+
| base | Application base | `string` | `[email protected]` | no |
67+
| machine | Target Juju machine to deploy on | `string` | n/a | no |
68+
| units | Number of units to deploy | `number` | `1` | no |
69+
| constraints | Juju constraints to apply for this application | `string` | `arch=amd64` | no |
70+
| storage | Storage directive | `map(string)` | `{}` | no |
71+
| config | Application configuration. Details at https://charmhub.io/postgresql/configurations | `map(string)` | n/a | no |
72+
| enable_expose | Whether to expose the application | `bool` | `true` | no |
73+
74+
## Outputs
75+
76+
| Name | Description |
77+
|------|-------------|
78+
| application_name | Application name which make up this product module |
79+
| provides | Endpoints charm provides |
80+
| requires | Endpoints charm requires |
81+

terraform/main.tf

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@ resource "juju_application" "machine_postgresql" {
33
model = var.juju_model_name
44

55
charm {
6-
name = "postgresql"
6+
name = var.charm_name
77
channel = var.channel
88
revision = var.revision
99
base = var.base
1010
}
1111

12-
storage_directives = {
13-
pgdata = var.storage_size
14-
}
15-
16-
units = var.units
17-
constraints = var.constraints
18-
config = var.config
12+
machines = var.machine != null ? [var.machine] : null
13+
units = var.machine == null ? var.units : null
14+
config = var.config
15+
constraints = var.constraints
16+
storage_directives = var.storage
1917

2018
dynamic "expose" {
2119
for_each = var.enable_expose ? [1] : []

terraform/outputs.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ output "application_name" {
22
value = juju_application.machine_postgresql.name
33
}
44

5-
65
output "provides" {
76
value = {
87
database = "database",

terraform/variables.tf

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
variable "juju_model_name" {
22
description = "Juju model name"
33
type = string
4+
default = null
5+
}
6+
7+
variable "charm_name" {
8+
description = "Name of the charm on https://charmhub.io"
9+
type = string
10+
default = "postgresql"
11+
nullable = false
412
}
513

614
variable "app_name" {
@@ -39,10 +47,10 @@ variable "constraints" {
3947
default = "arch=amd64"
4048
}
4149

42-
variable "storage_size" {
43-
description = "Storage size"
44-
type = string
45-
default = "10G"
50+
variable "storage" {
51+
description = "Storage directive"
52+
type = map(string)
53+
default = {}
4654
}
4755

4856
variable "config" {
@@ -52,7 +60,13 @@ variable "config" {
5260
}
5361

5462
variable "enable_expose" {
63+
description = "Whether to expose the application"
5564
type = bool
5665
default = true
57-
description = "Whether to expose the application"
66+
}
67+
68+
variable "machine" {
69+
description = "Target Juju machine to deploy on"
70+
type = string
71+
default = null
5872
}

0 commit comments

Comments
 (0)