Skip to content

Commit 2b85e6c

Browse files
Add MongoDB resource type and Kubernetes Terraform recipe (#21)
- mongodb.yaml schema - Terraform recipe (main.tf, variables.tf, outputs.tf) - README.md with usage instructions and manual testing notes Signed-off-by: Panagiotis Bellias <belliaspan@gmail.com>
1 parent 1e200e0 commit 2b85e6c

File tree

1 file changed

+68
-14
lines changed

1 file changed

+68
-14
lines changed

recipes/kubernetes/mongodb/README.md

Lines changed: 68 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,92 @@
22

33
This recipe provisions a MongoDB instance on Kubernetes using Terraform.
44

5+
---
6+
57
## Inputs
68

7-
- `name` (string, required): MongoDB instance name
8-
- `version` (string, default: 6.0): MongoDB version
9-
- `replicas` (int, default: 1): Number of replicas
10-
- `storage_size` (string, default: 10Gi): PVC size
11-
- `storage_class` (string, default: standard): Storage class
12-
- `username` (string, default: admin): Admin username
13-
- `password` (string, required): Admin password
14-
- `persistence` (bool, default: true): Enable persistence
15-
- `backup_enabled` (bool, default: false): Enable backups
16-
- `backup_schedule` (string): Cron schedule for backups
17-
- `resources` (object): CPU/memory requests/limits
9+
| Variable | Type | Default | Description |
10+
|-------------------|--------|-------------|------------------------------------|
11+
| `name` | string | required | MongoDB instance name |
12+
| `version` | string | 6.0 | MongoDB version |
13+
| `replicas` | int | 1 | Number of replicas |
14+
| `storage_size` | string | 10Gi | PVC size |
15+
| `storage_class` | string | standard | Kubernetes storage class |
16+
| `username` | string | admin | Admin username |
17+
| `password` | string | required | Admin password |
18+
| `persistence` | bool | true | Enable persistence |
19+
| `backup_enabled` | bool | false | Enable backups |
20+
| `backup_schedule` | string | "" | Cron schedule for backups |
21+
| `resources` | object | {} | CPU/memory requests and limits |
22+
23+
> **Note:** For CI or ephemeral testing, `persistence` should be set to `false` to avoid PVC-related delays in Kind clusters.
24+
25+
---
1826

1927
## Outputs
2028

2129
- `mongodb_service_name`: Kubernetes service name
2230
- `mongodb_credentials_secret`: Secret containing credentials
2331

32+
---
33+
2434
## Manual Testing
2535

2636
1. Apply Terraform:
2737
```bash
2838
terraform init
29-
terraform apply -var="name=mydb" -var="password=MySecretPass123"
39+
terraform apply \
40+
-var="name=mydb" \
41+
-var="password=MySecretPass123" \
42+
-auto-approve
3043
```
3144

32-
2. Connect to MongoDB:
45+
2. Check pod status:
46+
```bash
47+
kubectl get pods
48+
# Ensure test-mongodb-0 is READY=1/1
49+
```
50+
51+
3. Connect to MongoDB:
3352
```bash
3453
kubectl run mongo-client --rm -it --image=mongo -- \
3554
mongo "mongodb://$(kubectl get svc mydb-svc -o jsonpath='{.spec.clusterIP}'):27017" \
3655
-u admin -p MySecretPass123
3756
```
3857

39-
3. Verify database operations.
58+
4. Verify database operations.
59+
60+
5. Clean up (optional):
61+
```bash
62+
terraform destroy -var="name=mydb" -var="password=MySecretPass123" -auto-approve
63+
```
64+
65+
---
66+
67+
## CI / GitHub Actions Testing
68+
69+
This recipe is automatically tested in GitHub Actions for pull requests and branch pushes.
70+
71+
- A temporary Kind cluster is created.
72+
- Terraform applies the recipe with `persistence=false` for fast ephemeral testing.
73+
- The workflow waits for MongoDB pods to become ready.
74+
- Terraform destroys the resources and deletes the Kind cluster after the test.
75+
76+
Workflow file: `.github/workflows/test-mongodb-recipe.yml`
77+
78+
Example ephemeral test run:
79+
```bash
80+
terraform apply -var="name=test-mongodb" -var="password=MySecretPass123" -var="persistence=false" -auto-approve
81+
kubectl get pods
82+
terraform destroy -var="name=test-mongodb" -var="password=MySecretPass123" -var="persistence=false" -auto-approve
83+
```
84+
85+
> Make sure the MongoDB pod shows `READY=1/1` before connecting.
86+
87+
---
88+
89+
## References
90+
91+
- Radius MongoDB Resource Schema: https://docs.radapp.io/reference/resource-schema/databases/mongodb/
92+
- Example Kubernetes Recipe: https://github.com/radius-project/recipes/blob/main/local-dev/mongodatabases.bicep
93+

0 commit comments

Comments
 (0)