How-To: Model any resource with an extender

Learn how to use extenders in an application

This guide will walk you through how to use an extender in an application to model resources beyond those currently built into Radius. These might be abstractions or resources unique to your organization, or resources that don’t yet have a native Radius type.

Prerequisites

Step 1: Register an extender Recipe

In this guide you will leverage a Recipe to deploy backing infrastructure for your resource. Begin by registering the ’extender-postgresql’ Recipe in your environment:

rad recipe register postgresql --resource-type "Applications.Core/extenders" --template-kind bicep --template-path "ghcr.io/radius-project/recipes/local-dev/postgresql:latest"

Step 2: Define an extender

Open a new file named app.bicep and define an extender:

import radius as rad

@description('The ID of your Radius environment. Set automatically by the rad CLI.')
param environment string

@description('The ID of your Radius application. Set automatically by the rad CLI.')
param application string

resource extender 'Applications.Core/extenders@2023-10-01-preview' = {
  name: 'postgresql'
  properties: {
    environment: environment
    application: application
    recipe: {
      name: 'postgresql'
    }
  }
}

Step 3: Add a container

Add a container to your app.bicep file, accessing the extender’s properties and secrets:

resource demo 'Applications.Core/containers@2023-10-01-preview' = {
  name: 'demo'
  properties: {
    application: application
    container: {
      image: 'ghcr.io/radius-project/samples/demo:latest'
      env: {
        POSTGRESQL_HOST: extender.properties.host
        POSTGRESQL_PORT: extender.properties.port
        POSTGRESQL_USERNAME: extender.properties.username
        POSTGRESQL_PASSWORD: extender.secrets('password')
      }
      ports: {
        web: {
          containerPort: 3000
        }
      }
    }
    connections: {
      postgresql: {
        source: extender.id
      }
    }
  }
}

Step 4: Deploy the app

Deploy and run the app using the following command:

rad run app.bicep -a demo

You should see your application deployed:

Building .\app.bicep...
Deploying template '.\app.bicep' for application 'demo' and environment 'default' from workspace 'default'...

Deployment In Progress...


Deployment Complete

Resources:
    demo            Applications.Core/containers
    extender        Applications.Core/extenders

Starting log stream...

demo-bb9df8798-b68rc › demo
demo-bb9df8798-b68rc demo Using in-memory store: no connection string found
demo-bb9df8798-b68rc demo Server is running at http://localhost:3000
demo-bb9df8798-b68rc demo [port-forward] connected from localhost:3000 -> ::3000

Step 5: Test the app

Visit https://localhost:3000 to see your app running. You should see the environment variables and secrets you referenced in your container.

Cleanup

To clean up the resources created in this guide, run:

rad app delete demo -y