Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add How-To guide on sharing portable resources between applications #824

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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"
}
```

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ends with the deployment of portable resources, should we teach the sharing part of multiple applications deployed to an env connecting to this resource?

## 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
```
Original file line number Diff line number Diff line change
@@ -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
}
}
Loading