Skip to content

Commit 6c5d076

Browse files
authored
[DPE-6349] add sharded tf (#381)
* fix install timeout * update poetry + workflows * remove fields related to packages * fix linting issues * duplicate requirements in separate parts * migrate to use charm_version file per Carls suggestion * give workflow in tox access to poetry export * update charm version to pep format * PR feedback * remove build wrapper * add simple replica set terraform * add latest changes for ci fixes with terraform * remove dir * remove lock * add missing integrations * move tests to modules * add a sharded module * apply changes from PR review on VM * fixes for k8s * remove lock file * use the correct module * remove files * pr feedback
1 parent afe4eb8 commit 6c5d076

File tree

10 files changed

+268
-10
lines changed

10 files changed

+268
-10
lines changed

.github/workflows/ci.yaml

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ jobs:
5656
- name: Run tests
5757
run: tox run -e unit
5858

59-
terraform-test:
60-
name: Terraform - Lint and Simple Deployment
59+
terraform-lint:
60+
name: Terraform - Lint
6161
runs-on: ubuntu-22.04
62-
timeout-minutes: 120
62+
timeout-minutes: 10
6363
steps:
6464
- name: Checkout repo
6565
uses: actions/checkout@v4
@@ -80,7 +80,31 @@ jobs:
8080
terraform init
8181
terraform fmt
8282
terraform validate
83-
- name: run checks - prepare
83+
84+
terraform-test:
85+
name: Terraform - Run terraform tests
86+
needs:
87+
- terraform-lint
88+
runs-on: ubuntu-22.04
89+
timeout-minutes: 120
90+
strategy:
91+
matrix:
92+
module:
93+
- name: replica set tests
94+
working_directory: terraform/modules/replica_set
95+
model_name: test-rs
96+
- name: sharded tests
97+
working_directory: terraform/modules/sharded_cluster
98+
model_name: test-sc
99+
steps:
100+
- name: Checkout repo
101+
uses: actions/checkout@v4
102+
with:
103+
fetch-depth: 0
104+
- name: Install terraform snap
105+
run: |
106+
sudo snap install terraform --channel=latest/stable --classic
107+
- name: juju set up
84108
run: |
85109
sudo snap install juju --channel=3.6/beta --classic
86110
sudo snap install juju-wait --channel=latest/stable --classic
@@ -99,11 +123,13 @@ jobs:
99123
run: |
100124
sg 'lxd' -c "juju bootstrap 'localhost' --config model-logs-size=10G"
101125
juju model-defaults logging-config='<root>=INFO; unit=DEBUG'
102-
juju add-model test
103-
- name: Terraform deploy
104-
working-directory: ./terraform/modules
126+
- name: Terraform deploy ${{ matrix.module.name }}
127+
working-directory: ${{ matrix.module.working_directory }}
128+
105129
run: |
106-
terraform apply -var "model_name=test" -target null_resource.simple_deployment_juju_wait_deployment -auto-approve
130+
juju add-model ${{ matrix.module.model_name }}
131+
terraform init
132+
terraform apply -var "model_name=${{ matrix.module.model_name }}" -target null_resource.juju_wait_deployment -auto-approve
107133
108134
build:
109135
strategy:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ build/
33
*.charm
44

55
coverage*
6+
*.terraform*
67
.coverage
78
__pycache__/
89
*.py[cod]

terraform/modules/simple_deployment.tf renamed to terraform/modules/replica_set/simple_deployment.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module "mongodb-k8s" {
2-
source = "../"
2+
source = "../../"
33
app_name = var.app_name
44
model = var.model_name
55
units = var.simple_mongodb_units

terraform/modules/variables.tf renamed to terraform/modules/replica_set/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ variable "model_name" {
44
}
55

66
variable "app_name" {
7-
description = "MongoDB app name"
7+
description = "mongodb app name"
88
type = string
99
default = "mongodb-k8s"
1010
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
resource "null_resource" "preamble" {
2+
provisioner "local-exec" {
3+
command = <<-EOT
4+
sudo snap install juju-wait --classic || true
5+
EOT
6+
}
7+
}
8+
9+
resource "juju_application" "self-signed-certificates" {
10+
charm {
11+
name = "self-signed-certificates"
12+
channel = "latest/stable"
13+
}
14+
model = var.model_name
15+
depends_on = [null_resource.preamble]
16+
}
17+
18+
resource "juju_application" "data-integrator" {
19+
charm {
20+
name = "data-integrator"
21+
channel = "latest/stable"
22+
}
23+
model = var.model_name
24+
depends_on = [null_resource.preamble]
25+
}
26+
27+
resource "juju_application" "s3-integrator" {
28+
charm {
29+
name = "s3-integrator"
30+
channel = "latest/stable"
31+
}
32+
model = var.model_name
33+
depends_on = [null_resource.preamble]
34+
}
35+
36+
resource "juju_application" "mongos-k8s" {
37+
charm {
38+
name = "mongos-k8s"
39+
channel = "6/stable"
40+
}
41+
model = var.model_name
42+
depends_on = [null_resource.preamble]
43+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
terraform {
2+
required_providers {
3+
juju = {
4+
source = "juju/juju"
5+
version = "~> 0.14.0"
6+
}
7+
http = {
8+
source = "hashicorp/http"
9+
version = "~> 3.4.5"
10+
}
11+
external = {
12+
source = "hashicorp/external"
13+
version = "~> 2.3.4"
14+
}
15+
}
16+
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
locals {
2+
mongodb_apps = merge(
3+
{
4+
"config-server" = {
5+
app_name = var.config_server_app_name
6+
units = var.config_server_replicas
7+
role = "config-server"
8+
}
9+
},
10+
{ for shard in var.shards : shard.name => {
11+
app_name = shard.name
12+
units = shard.replicas
13+
role = "shard"
14+
}
15+
}
16+
)
17+
}
18+
19+
module "mongodb-k8s" {
20+
for_each = local.mongodb_apps
21+
source = "../../"
22+
app_name = each.value.app_name
23+
model = var.model_name
24+
units = each.value.units
25+
channel = "6/edge"
26+
config = {
27+
role = each.key
28+
}
29+
}
30+
31+
32+
resource "juju_integration" "data-integrator_mongos-integration" {
33+
model = var.model_name
34+
35+
application {
36+
name = juju_application.data-integrator.name
37+
}
38+
application {
39+
name = juju_application.mongos-k8s.name
40+
}
41+
depends_on = [
42+
juju_application.data-integrator,
43+
juju_application.mongos-k8s
44+
]
45+
46+
}
47+
48+
resource "juju_integration" "config-server_integrations" {
49+
for_each = tomap({
50+
for shard in var.shards : shard.name => {
51+
app_name = shard.name
52+
}
53+
})
54+
55+
model = var.model_name
56+
57+
application {
58+
name = var.config_server_app_name
59+
endpoint = "config-server"
60+
}
61+
62+
application {
63+
name = each.value.app_name
64+
endpoint = "sharding"
65+
}
66+
67+
depends_on = [
68+
module.mongodb-k8s,
69+
]
70+
}
71+
72+
resource "juju_integration" "mongodb_mongos-integration" {
73+
model = var.model_name
74+
75+
application {
76+
name = juju_application.mongos-k8s.name
77+
}
78+
application {
79+
name = var.config_server_app_name
80+
}
81+
depends_on = [
82+
juju_application.mongos-k8s,
83+
module.mongodb-k8s,
84+
juju_integration.data-integrator_mongos-integration
85+
]
86+
87+
}
88+
89+
resource "juju_integration" "tls-operator_mongodb-integration" {
90+
for_each = merge(
91+
local.mongodb_apps,
92+
{
93+
"mongos-k8s" = {
94+
app_name = "mongos-k8s"
95+
units = 1
96+
}
97+
}
98+
)
99+
100+
model = var.model_name
101+
102+
application {
103+
name = juju_application.self-signed-certificates.name
104+
}
105+
106+
application {
107+
name = each.value.app_name
108+
}
109+
110+
depends_on = [
111+
juju_application.self-signed-certificates,
112+
juju_integration.mongodb_mongos-integration,
113+
juju_integration.config-server_integrations
114+
]
115+
}
116+
117+
resource "juju_integration" "s3-integrator_mongodb-integration" {
118+
model = var.model_name
119+
120+
application {
121+
name = juju_application.s3-integrator.name
122+
}
123+
application {
124+
name = var.config_server_app_name
125+
}
126+
depends_on = [
127+
juju_application.s3-integrator,
128+
juju_integration.config-server_integrations,
129+
]
130+
131+
}
132+
133+
resource "null_resource" "juju_wait_deployment" {
134+
provisioner "local-exec" {
135+
command = <<-EOT
136+
juju-wait -v --model ${var.model_name}
137+
EOT
138+
}
139+
140+
depends_on = [juju_integration.tls-operator_mongodb-integration]
141+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
variable "model_name" {
2+
description = "Model name"
3+
type = string
4+
}
5+
6+
variable "config_server_app_name" {
7+
description = "config-server app name"
8+
type = string
9+
default = "config-server"
10+
}
11+
12+
variable "config_server_replicas" {
13+
description = "Node count"
14+
type = number
15+
default = 3
16+
}
17+
18+
variable "shards" {
19+
description = "A list of shards containing their name and number of replicas"
20+
type = list(object({
21+
name = string
22+
replicas = number
23+
}))
24+
default = [
25+
{ name = "shard0", replicas = 3 },
26+
{ name = "shard1", replicas = 3 }
27+
]
28+
}
29+
30+
31+

0 commit comments

Comments
 (0)