diff --git a/docs/content/guides/author-apps/portable-resources/howto-share-resources/index.md b/docs/content/guides/author-apps/portable-resources/howto-share-resources/index.md new file mode 100644 index 000000000..b50aefcf9 --- /dev/null +++ b/docs/content/guides/author-apps/portable-resources/howto-share-resources/index.md @@ -0,0 +1,98 @@ +--- +type: docs +title: "How-To: Share portable resources between applications" +linkTitle: "Share between apps" +description: "Learn how to share portable resources between applications" +weight: 400 +categories: "Overview" +--- + +This guide will show you how you can share portable resources between Radius applications. + +## Pre-requisites + +- [rad CLI]({{< ref "/guides/tooling/rad-cli/overview" >}}) +- [rad development environment]({{< red "getting-started" >}}) + +## Step 1: Define an environment-scoped resource + +Portable resources can be environment-scoped, where they follow the lifecycle of an environment instead of an application. Define a resource, such as a Redis cache, in your app.bicep file: + +{{< rad file="snippets/app.bicep" embed=true >}} + +## Step 2: Deploy resource + +Deploy the resource with [`rad deploy`]({{< ref rad_deploy >}}), using the 'local-dev' Recipe: + +```bash +rad deploy app.bicep +``` + +You should see the resource deployed into your environment: + +```Building .\app.bicep... +Deploying template '.\app.bicep' into environment 'default' from workspace 'default'... + +Deployment In Progress... + +... shared-cache Applications.Datastores/redisCaches + +Deployment Complete + +Resources: + shared-cache Applications.Datastores/redisCaches +``` + +## Step 3: Verify the resource was deployed + +Run [`rad resource show`]({{< ref rad_resource_show >}}) to verify the resource was deployed into the environment's Kubernetes namespace: + +```bash +rad resource show rediscaches shared-cache -o json +``` + +You should see the raw JSON output, including the `outputResources` property which shows the Kubernetes namespace the Redis cache was deployed into. It will match the environment's namespace ('default') and not an application's ('default-app1', 'default-app2'): + +``` +{ + "id": "/planes/radius/local/resourcegroups/default/providers/Applications.Datastores/redisCaches/shared-cache", + "location": "global", + "name": "shared-cache", + "properties": { + "application": "", + "environment": "/planes/radius/local/resourceGroups/default/providers/applications.core/environments/default", + "host": "redis-bvempevrr4ygm.default.svc.cluster.local", + "port": 6379, + "provisioningState": "Succeeded", + "recipe": { + "name": "default" + }, + "resourceProvisioning": "recipe", + "status": { + "outputResources": [ + { + "id": "/planes/kubernetes/local/namespaces/default/providers/core/Service/redis-bvempevrr4ygm", + "radiusManaged": true + }, + { + "id": "/planes/kubernetes/local/namespaces/default/providers/apps/Deployment/redis-bvempevrr4ygm", + "radiusManaged": true + } + ] + }, + "tls": false, + "username": "" + }, + "systemData": {}, + "tags": {}, + "type": "Applications.Datastores/redisCaches" +} +``` + +## Done + +Now that you have an environment-scoped resource you can define connections to it from any Radius container from any application. You can also cleanup with the resource with [`rad resource delete`]({{< ref rad_resource_delete >}}): + +```bash +rad resource delete rediscaches shared-cache -y +``` diff --git a/docs/content/guides/author-apps/portable-resources/howto-share-resources/snippets/app.bicep b/docs/content/guides/author-apps/portable-resources/howto-share-resources/snippets/app.bicep new file mode 100644 index 000000000..00187759b --- /dev/null +++ b/docs/content/guides/author-apps/portable-resources/howto-share-resources/snippets/app.bicep @@ -0,0 +1,12 @@ +import radius as rad + +@description('Environment ID of the Radius environment being deployed into. Injected automatically by the rad CLI.') +param environment string + +resource sharedCache 'Applications.Datastores/redisCaches@2023-10-01-preview' = { + name: 'shared-cache' + properties: { + environment: environment + // No application property defined as this resource follows the lifecycle of the environment + } +}