Created
June 25, 2025 15:04
-
-
Save andrewmatveychuk/93d714be53ec9e625364e0e64e227fd5 to your computer and use it in GitHub Desktop.
A sample Radius recipe to provision a MySQL database as a container
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
| @description('Information about what resource is calling this Recipe. Generated by Radius.') | |
| param context object | |
| @description('MySQL database name') | |
| param database string = context.application.name | |
| @description('MySQL username') | |
| param user string = '${context.application.name}-user' | |
| @description('MySQL password') | |
| @secure() | |
| param password string = uniqueString(context.resource.id, newGuid()) | |
| @description('MySQL root password') | |
| @secure() | |
| param root_password string = uniqueString(context.resource.id, newGuid()) | |
| @description('Tag to pull for the MySQL container image.') | |
| param tag string = 'latest' | |
| extension kubernetes with { | |
| kubeConfig: '' | |
| namespace: context.runtime.kubernetes.namespace | |
| } as kubernetes | |
| var uniqueName = 'mysql-${uniqueString(context.resource.id)}' | |
| var port = 3306 | |
| resource mysql 'apps/Deployment@v1' = { | |
| metadata: { | |
| name: uniqueName | |
| } | |
| spec: { | |
| selector: { | |
| matchLabels: { | |
| app: context.application.name | |
| tier: 'mysql' | |
| } | |
| } | |
| template: { | |
| metadata: { | |
| labels: { | |
| app: context.application.name | |
| tier: 'mysql' | |
| 'radapp.io/application': context.application == null ? '' : context.application.name | |
| } | |
| } | |
| spec: { | |
| containers: [ | |
| { | |
| name: 'mysql' | |
| image: 'mysql:${tag}' | |
| ports: [ | |
| { | |
| containerPort: port | |
| } | |
| ] | |
| env: [ | |
| { | |
| name: 'MYSQL_ROOT_PASSWORD' | |
| value: root_password | |
| } | |
| { | |
| name: 'MYSQL_USER' | |
| value: user | |
| } | |
| { | |
| name: 'MYSQL_PASSWORD' | |
| value: password | |
| } | |
| { | |
| name: 'MYSQL_DATABASE' | |
| value: database | |
| } | |
| ] | |
| } | |
| ] | |
| } | |
| } | |
| } | |
| } | |
| resource svc 'core/Service@v1' = { | |
| metadata: { | |
| name: 'mysql' | |
| labels: { | |
| app: context.application.name | |
| } | |
| } | |
| spec: { | |
| type: 'ClusterIP' | |
| selector: { | |
| app: context.application.name | |
| tier: 'mysql' | |
| } | |
| ports: [ | |
| { | |
| port: port | |
| } | |
| ] | |
| } | |
| } | |
| output result object = { | |
| resources: [ | |
| '/planes/kubernetes/local/namespaces/${svc.metadata.namespace}/providers/core/Service/${svc.metadata.name}' | |
| '/planes/kubernetes/local/namespaces/${mysql.metadata.namespace}/providers/apps/Deployment/${mysql.metadata.name}' | |
| ] | |
| values: { | |
| host: '${svc.metadata.name}.${svc.metadata.namespace}.svc.cluster.local' | |
| port: port | |
| database: database | |
| user: user | |
| } | |
| secrets: { | |
| #disable-next-line outputs-should-not-contain-secrets | |
| password: password | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment