Skip to content

Commit 4af2605

Browse files
[DPE-7796] Define Terraform modules (#40)
1 parent 97671e8 commit 4af2605

File tree

13 files changed

+216
-1
lines changed

13 files changed

+216
-1
lines changed

.github/workflows/ci.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,18 @@ jobs:
3434
steps:
3535
- name: Checkout
3636
uses: actions/checkout@v5
37+
- name: Install terraform
38+
run: |
39+
sudo snap install terraform --classic
3740
- name: Install tox & poetry
3841
run: |
3942
pipx install tox
4043
pipx install poetry
4144
- name: Run linters
4245
working-directory: ${{ matrix.path }}
43-
run: tox run -e lint
46+
run: |
47+
tox run -e lint
48+
tox run -e lint-terraform
4449
4550
unit-test:
4651
strategy:

kubernetes/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ build/
88
.coverage
99
__pycache__/
1010
*.py[cod]
11+
12+
.terraform
13+
.terraform.lock.hcl

kubernetes/terraform/main.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
resource "juju_application" "mysql_router" {
2+
name = var.app_name
3+
model = var.model_name
4+
5+
charm {
6+
name = "mysql-router-k8s"
7+
base = var.base
8+
channel = var.channel
9+
revision = var.revision
10+
}
11+
12+
config = var.config
13+
constraints = var.constraints
14+
units = var.units
15+
}

kubernetes/terraform/outputs.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
output "app_name" {
2+
description = "Name of the MySQL Router K8s application"
3+
value = juju_application.mysql_router.name
4+
}
5+
6+
output "provides" {
7+
description = "Map of all the provided endpoints"
8+
value = {
9+
database = "database"
10+
grafana_dashboard = "grafana-dashboard"
11+
metrics_endpoint = "metrics-endpoint"
12+
}
13+
}
14+
15+
output "requires" {
16+
description = "Map of all the required endpoints"
17+
value = {
18+
backend_database = "backend-database"
19+
certificates = "certificates"
20+
logging = "logging"
21+
tracing = "tracing"
22+
}
23+
}

kubernetes/terraform/variables.tf

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
variable "model_name" {
2+
description = "Name of the juju model to deploy to"
3+
type = string
4+
}
5+
6+
variable "app_name" {
7+
description = "Name of the juju application"
8+
type = string
9+
default = "mysql-router-k8s"
10+
}
11+
12+
variable "base" {
13+
description = "Application base"
14+
type = string
15+
default = "ubuntu@22.04"
16+
}
17+
18+
variable "config" {
19+
description = "Application configuration. Details at https://charmhub.io/mysql-router-k8s/configurations"
20+
type = map(string)
21+
default = {}
22+
}
23+
24+
variable "constraints" {
25+
description = "Juju constraints for the application"
26+
type = string
27+
default = "arch=amd64"
28+
}
29+
30+
variable "channel" {
31+
description = "Charm channel to deploy from"
32+
type = string
33+
default = "8.0/stable"
34+
}
35+
36+
variable "revision" {
37+
description = "Charm revision to deploy"
38+
type = number
39+
default = null
40+
}
41+
42+
variable "units" {
43+
description = "Number of units to deploy"
44+
type = number
45+
default = 1
46+
}

kubernetes/terraform/versions.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.6.6"
3+
4+
required_providers {
5+
juju = {
6+
source = "juju/juju"
7+
version = ">= 0.20.0, < 1.0.0"
8+
}
9+
}
10+
}

kubernetes/tox.ini

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ env_list = lint, unit
99
src_path = "{tox_root}/src"
1010
tests_path = "{tox_root}/tests"
1111
scripts_path = "{tox_root}/scripts"
12+
terraform_path = "{tox_root}/terraform"
1213
all_path = {[vars]src_path} {[vars]tests_path} {[vars]scripts_path}
1314

1415
[testenv]
@@ -17,6 +18,7 @@ set_env =
1718
PY_COLORS = 1
1819
allowlist_externals =
1920
poetry
21+
terraform
2022

2123
[testenv:format]
2224
description = Apply coding style standards to code
@@ -37,6 +39,13 @@ commands =
3739
poetry run ruff check {[vars]all_path}
3840
poetry run ruff format --check --diff {[vars]all_path}
3941

42+
[testenv:lint-terraform]
43+
description = Check code against Terraform style standards
44+
commands =
45+
terraform fmt -check -diff -recursive {[vars]terraform_path}
46+
terraform -chdir={[vars]terraform_path} init -backend=false
47+
terraform -chdir={[vars]terraform_path} validate
48+
4049
[testenv:unit]
4150
description = Run unit tests
4251
commands_pre =

machines/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ build/
99
coverage.xml
1010
__pycache__/
1111
*.py[cod]
12+
13+
.terraform
14+
.terraform.lock.hcl

machines/terraform/main.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
resource "juju_application" "mysql_router" {
2+
name = var.app_name
3+
model = var.model_name
4+
5+
charm {
6+
name = "mysql-router"
7+
base = var.base
8+
channel = var.channel
9+
revision = var.revision
10+
}
11+
12+
config = var.config
13+
constraints = var.constraints
14+
units = var.units
15+
}

machines/terraform/outputs.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
output "app_name" {
2+
description = "Name of the MySQL Router VM application"
3+
value = juju_application.mysql_router.name
4+
}
5+
6+
output "provides" {
7+
description = "Map of all the provided endpoints"
8+
value = {
9+
database = "database"
10+
cos_agent = "cos-agent"
11+
}
12+
}
13+
14+
output "requires" {
15+
description = "Map of all the required endpoints"
16+
value = {
17+
backend_database = "backend-database"
18+
certificates = "certificates"
19+
tracing = "tracing"
20+
}
21+
}

0 commit comments

Comments
 (0)