Repository navigation
Conversation
Add a Kubernetes Recipe in Terraform that runs a single MongoDB 7.0 server from the official mongo image, with authentication enabled. The administrator password comes from random_password and is kept in the Terraform state, stored in a Kubernetes Secret, and returned inside secrets.connectionString together with endpoint and database. Document the Recipe in the resource type README and a Recipe README. Fixes radius-project#21 Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com> Assisted-by: claude-opus-5-5 (via Claude Code)
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Database input handling can produce unusable connection strings or select an unintended database.
Review effort: Balanced
Findings: 2
Open (2)
What changed in this PR
Adds a Kubernetes Terraform recipe for the existing Radius.Data/mongoDatabases resource type, addressing #21.
Changes:
- Deploys an authenticated MongoDB server with ephemeral storage, a Service, and generated credentials.
- Returns endpoint, database, and secret-backed connection details.
- Documents usage and updates schema descriptions without changing the schema contract.
| File | Description |
|---|---|
Data/mongoDatabases/recipes/kubernetes/terraform/var.tf |
Defines the Radius context input. |
Data/mongoDatabases/recipes/kubernetes/terraform/README.md |
Documents recipe behavior and registration. |
Data/mongoDatabases/recipes/kubernetes/terraform/main.tf |
Implements MongoDB deployment, credentials, and outputs. |
Data/mongoDatabases/README.md |
Adds Kubernetes behavior, limitations, and usage guidance. |
Data/mongoDatabases/mongoDatabases.yaml |
Updates descriptions for Kubernetes support. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| tag = "7.0" | ||
| username = "admin" | ||
| database_input = try(var.context.resource.properties.database, null) | ||
| database = local.database_input != null ? local.database_input : "mongo_db" |
| # string sets authSource=admin and selects `database` as the default | ||
| # database. Radius materializes it into the managed Radius.Security/secrets | ||
| # resource; it is never written onto the resource. | ||
| connectionString = "mongodb://${local.username}:${random_password.password.result}@${local.host}:${local.port}/${local.database}?authSource=admin" |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Adds a Kubernetes Recipe in Terraform (
main.tf+var.tf) forRadius.Data/mongoDatabases, which until now only had the Azure (Cosmos DB for MongoDB) Recipe in the AKS pack. The resource type itself already exists, so acceptance criterion 1 is met and the schema is unchanged.This picks up #21 after the earlier attempt in #51 was closed; it takes the review feedback there into account. The module lives at
Data/mongoDatabases/recipes/kubernetes/terraform/. It is a Radius Recipe: it reads thecontextvariable and returns aresultoutput, with no separate outputs file. No properties are added to the schema, no workflow is added, and the README follows the contributing guide's structure.The module follows the existing Terraform Kubernetes Recipes (
redisCaches,postgreSqlDatabases):hashicorp/kubernetes >= 2.37.1constraint andlocals/ labels layout;kubernetes_deploymentwith theRecreatestrategy, aClusterIPkubernetes_service, and a credentialskubernetes_secret;resultoutput.It behaves the same as the Bicep Recipe proposed for #20 in #374: same image, settings, probe and outputs. The one difference is the password, which comes from
random_passwordand is kept in the Terraform state.mongo:7.0image. Storage is anemptyDir, matching the other non-persistent in-cluster Recipes. The WiredTiger cache is capped at 0.25 GB, and the memory request is512Mi.mongo:8.0,8.3and9.0all exit at startup with "Linux kernel versions 6.19 and newer has a known incompatibility with this version of MongoDB" (SERVER-121912).mongo:7.0does not have that check, so it also starts on current kernels.random_password(32 characters, no special characters) is stored with the user nameadminin a<name>-credentialsSecret. This adds ahashicorp/random >= 3.6.0provider requirement.secret_key_refasMONGO_INITDB_ROOT_USERNAME/MONGO_INITDB_ROOT_PASSWORD.admindatabase on first start and then runsmongodwith--auth.tcp_socketprobe on the namedmongodbport. While the entrypoint creates the administrator, it runs a temporary server bound to127.0.0.1only, so the port on the Pod IP opens only once the final server is up with authentication on.values.endpointis<name>.<namespace>.svc.cluster.local:27017.values.databaseisdatabase(defaultmongo_db, also whendatabaseis null), as the PostgreSQL Recipe returns it.secrets.connectionStringismongodb://admin:<password>@<endpoint>/<database>?authSource=admin. This is the keyData/mongoDatabases/test/app.bicepalready binds withsecretKeyRef.databaseon the first write; the Recipe does not create it in advance.Data/mongoDatabases/README.md.mongoDatabases.yamlso the type description,endpointandconnectionStringalso describe the Kubernetes Recipe. These are description-only, with no schema change, and match the Bicep PR's text exactly.About the Kubernetes Recipe Pack: this PR leaves
recipe-packs/kubernetes/default.bicepunchanged. #21 does not ask for a pack entry. That pack has one entry per resource type, and every entry iskind: 'bicep'with aghcr.io/radius-project/kube-recipes/...OCI source; nothing in the repository publishes Terraform modules to a registry. The pack'sRadius.Data/mongoDatabasesentry is added by the Bicep Recipe for #20 (#374). The CI-generatedterraformrecipepackpicks this module up automatically.Reason for change
Radius.Data/mongoDatabaseshad no Terraform Recipe for Kubernetes.Fixes #21
How to test
On a cluster with Radius installed:
To check authentication by hand after
rad deploy Data/mongoDatabases/test/app.bicep:What I validated locally:
terraform fmt -checkon the Recipe directory (Terraform 1.16.4): clean.terraform init -backend=falseandterraform validate: valid. The providers resolved tohashicorp/kubernetes3.3.0 andhashicorp/random3.9.1. The only warnings are the provider's deprecation notices forkubernetes_deployment/kubernetes_service/kubernetes_secret(use the_v1variants), which the existing Redis and PostgreSQL Terraform Recipes also produce. I kept the unversioned resources to match them.terraform consolewith sample Recipe contexts:local.databaseresolves tomongo_dbwhendatabaseis absent or null, and to the given name otherwise.local.hostis<name>.<namespace>.svc.cluster.local.make validate-recipe-packs: pass.cspell10.3.2 with.github/linters/.cspell.ymlon the changed files: 0 issues.mongoDatabases.yamlparses as YAML.mongo7.0 image'sdocker-entrypoint.sh: how it handlesMONGO_INITDB_ROOT_*,--auth, the127.0.0.1-only init server and--bind_ip_all.Live test on a cluster: I ran the same steps as the
terraformmatrix ofValidate Resource Types and Recipes, on a local kind cluster created withmake create-radius-cluster(Radius CLIedge):RECIPE_PLATFORM_FILTER=kubernetes make build RECIPE_PLATFORM_FILTER=kubernetes make generate-recipe-pack PACK_NAME=terraformrecipepack OUTPUT_FILE=recipe-pack-terraform.bicep make deploy-recipe-pack BICEP_FILE=recipe-pack-terraform.bicep make update-env-recipe-pack RECIPE_PACK_NAME=terraformrecipepack ENVIRONMENT=default RECIPE_PLATFORM_FILTER=kubernetes make test RESOURCE_TYPE_ROOT=Data/mongoDatabases ENVIRONMENT=default RECIPE_TYPE=terraformData/mongoDatabases/test/app.bicepdeployed withmongo(Radius.Data/mongoDatabases) anddemocontainer(Radius.Compute/containers, which readssecrets.connectionString), and the run reportedPassed: 1, Failed: 0. The cleanup step then deleted the Deployments, Services and secrets.rad deploydoes not wait for the MongoDB Pod to become ready, so I also deployed the test app by hand on the same cluster and checked:mongoPod became ready, and the resource showedendpointmongo.<namespace>.svc.cluster.local:27017anddatabasemongo_db.mongoshwith the connection string from the managed secret, going through the Service DNS name, wrote and read a document inmongo_db.insertfailed with "requires authentication", and a wrong password failed with "Authentication failed".rad deploy, the password was unchanged, the same Pod was still running, and the document was still there.The test VM is arm64 and
ghcr.io/radius-project/samples/demois amd64-only, sodemocontaineritself could not run there (exec format error). That is why the client check above usedmongosh. The CI workflow repeats the test on amd64 once a maintainer approves it.Automated coverage: no new test file is needed.
Data/mongoDatabases/test/app.bicepalready exists. The terraform matrix builds every*/recipes/kubernetes/terraformRecipe into a generated pack and deploys each type'stest/app.bicep, so this PR puts the MongoDB Terraform Recipe into that run. The test app bindssecrets.connectionStringthroughsecretKeyRef, so the run fails if the Recipe does not return that key.File change summary
Data/mongoDatabases/recipes/kubernetes/terraform/main.tfkubernetes_deploymentwith authentication +ClusterIPkubernetes_service+ credentialskubernetes_secretfromrandom_password, sensitiveresultwithendpoint,databaseandsecrets.connectionString.Data/mongoDatabases/recipes/kubernetes/terraform/var.tfcontextvariable, as in the Redis Terraform Recipe.Data/mongoDatabases/recipes/kubernetes/terraform/README.mdData/mongoDatabases/README.mdData/mongoDatabases/mongoDatabases.yamlendpoint/connectionStringcontain on Kubernetes.🤖 Generated with Claude Code