Skip to content

Add tutorial to create a resource type in Radius #1409

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

Merged
merged 105 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
35b542e
Add udt tutorial
Reshrahim Mar 28, 2025
959073a
Updates
Reshrahim Mar 28, 2025
e65c08a
Updates
Reshrahim Mar 31, 2025
f38cc7d
Fix rad file
Reshrahim Mar 31, 2025
fcbb511
Add Bicep outputs
Reshrahim Mar 31, 2025
21d4b7f
Refine steps
Reshrahim Apr 1, 2025
1144242
Merge branch 'edge' into re/udt
Reshrahim Apr 1, 2025
eb99e9a
Fix bicep config
Reshrahim Apr 1, 2025
5b8832b
Merge branch 're/udt' of https://github.com/radius-project/docs into …
Reshrahim Apr 1, 2025
1f86c1b
Fix formatting
Reshrahim Apr 1, 2025
f068aa3
Fixes to docs and bicep files
Reshrahim Apr 4, 2025
e2312b3
Fix Recipes reference
Reshrahim Apr 4, 2025
e674ccc
Fix naming
Reshrahim Apr 4, 2025
90d4145
Fix errors
Reshrahim Apr 4, 2025
6612df4
Updates
Reshrahim Apr 4, 2025
2424eb8
Fix code snippet formatting
Reshrahim Apr 4, 2025
5ce2d2d
Fix code snippet formatting
Reshrahim Apr 4, 2025
9fe4076
Fix code snippet formatting
Reshrahim Apr 4, 2025
e7eaf4c
Address feedback
Reshrahim Apr 4, 2025
1ae227a
Fix refernce
Reshrahim Apr 4, 2025
bbf436a
Fix refernce
Reshrahim Apr 4, 2025
3f48129
Fix refernce
Reshrahim Apr 4, 2025
395daf3
Fix refernce
Reshrahim Apr 4, 2025
4333f91
Fix refernce to guides
Reshrahim Apr 4, 2025
975b59e
Address feddback
Reshrahim Apr 4, 2025
b4e40ec
Fix todoapp image
Reshrahim Apr 4, 2025
f97622a
Fix snippets
Reshrahim Apr 4, 2025
9bb65e5
Updates
Reshrahim Apr 4, 2025
25aa751
Update docs/content/tutorials/tutorial-resource-type/index.md
Reshrahim Apr 7, 2025
e63dc84
Update docs/content/tutorials/tutorial-resource-type/index.md
Reshrahim Apr 7, 2025
10e935e
Update docs/content/tutorials/tutorial-resource-type/index.md
Reshrahim Apr 7, 2025
7bf98cb
Address feedback
Reshrahim Apr 7, 2025
dfb81b6
Merge branch 're/udt' of https://github.com/radius-project/docs into …
Reshrahim Apr 7, 2025
ff22421
Address feedback
Reshrahim Apr 7, 2025
411530b
Address feedback
Reshrahim Apr 7, 2025
3952365
fix image
Reshrahim Apr 7, 2025
73f9f83
fix image
Reshrahim Apr 7, 2025
597388b
Apply suggestions from code review
Reshrahim Apr 8, 2025
5d160ca
Apply suggestions from code review
Reshrahim Apr 8, 2025
01beeb2
Apply suggestions from code review
Reshrahim Apr 9, 2025
02eba8c
Address PR review feedback
Reshrahim Apr 9, 2025
07b72cc
Fix bicep validation error
Reshrahim Apr 9, 2025
c93d797
Merge branch 'edge' into re/udt
Reshrahim Apr 9, 2025
da0f460
Update docs/content/tutorials/tutorial-resource-type/snippets/app.bicep
Reshrahim Apr 9, 2025
b97ee0d
Add caution on secrets
Reshrahim Apr 10, 2025
989cf94
Updates
Reshrahim Apr 10, 2025
ec75bf5
Updates
Reshrahim Apr 10, 2025
8ed29b3
Updates
Reshrahim Apr 10, 2025
9784700
Add local registry
Reshrahim Apr 11, 2025
8fbe694
fix tabs
Reshrahim Apr 11, 2025
00b72c6
Nits
Reshrahim Apr 11, 2025
34b9820
Trigger Build
Reshrahim Apr 11, 2025
6a309de
Fixes
Reshrahim Apr 14, 2025
3bfa9ee
Fixes
Reshrahim Apr 14, 2025
a3b68a3
Fixes
Reshrahim Apr 14, 2025
2699f36
Fixes
Reshrahim Apr 14, 2025
a35a37b
Add terraform recipes
Reshrahim Apr 22, 2025
fca31af
Spell check
Reshrahim Apr 22, 2025
3bf8b15
Fix pre-reqs
Reshrahim Apr 22, 2025
78813cf
Fix pre-reqs
Reshrahim Apr 22, 2025
7d1543e
Fix order
Reshrahim Apr 22, 2025
3c7e7e5
Fix env variables
Reshrahim Apr 23, 2025
427f2c1
Fix env variables
Reshrahim Apr 23, 2025
a5b140d
Add app
Reshrahim Apr 23, 2025
603f930
Update tf Recipe
Reshrahim Apr 23, 2025
8d62a89
Fix typo
Reshrahim Apr 24, 2025
64ddd92
Fix typo
Reshrahim Apr 24, 2025
e71d1de
Add tf example
Reshrahim Apr 24, 2025
9c56a7e
Update docs/content/tutorials/tutorial-resource-type/index.md
Reshrahim Apr 24, 2025
ed3045e
Add tf example
Reshrahim Apr 24, 2025
a4cbc99
tf module sources
Reshrahim Apr 24, 2025
9e5d3ff
update tf
Reshrahim Apr 24, 2025
6ca5293
Update index.md
jonvsm Apr 25, 2025
39b7434
Add application flag
Reshrahim Apr 25, 2025
6e529cc
Merge branch 're/udt' of https://github.com/radius-project/docs into …
Reshrahim Apr 25, 2025
d5ecdf7
Update docs for v0.46.0
rad-ci-bot May 2, 2025
d24985b
Add customizable property size to the definitions
Reshrahim May 6, 2025
55d7638
Merge branch 'edge' into re/udt
Reshrahim May 6, 2025
0af86b3
Add recipe outputs changes
Reshrahim May 7, 2025
ceea7a1
Merge branch 're/udt' of https://github.com/radius-project/docs into …
Reshrahim May 7, 2025
4c8530a
Add warning
Reshrahim May 8, 2025
1c57ed8
Add app graph
Reshrahim May 8, 2025
28dd461
swapping out for correct demo-dashboard-appgraph
jonvsm May 9, 2025
42f46b8
rename namespace and app defn
Reshrahim May 12, 2025
00024be
Rename to types.yaml
Reshrahim May 12, 2025
27e88c3
Reove mycompany refernce
Reshrahim May 12, 2025
506eebe
Merge branch 'edge' into re/udt
Reshrahim May 21, 2025
19bb64b
Added composite recipe tutorial
zachcasper May 23, 2025
4bcc253
Updated all three tuturials to work together
zachcasper May 27, 2025
4e2eef5
Merge branch 'edge' into re/udt
Reshrahim May 28, 2025
b33e9af
Spellcheck
Reshrahim May 28, 2025
518382b
Spell check and Bicep validation fix
Reshrahim May 28, 2025
fc130b3
Minor edits
Reshrahim May 28, 2025
1f300b0
Merge branch 're/udt' of https://github.com/radius-project/docs into …
zachcasper May 28, 2025
9b02074
Updated diagrams
zachcasper May 28, 2025
03b933a
Minor edits
Reshrahim May 28, 2025
5733cd8
Update body-end.html
Reshrahim May 28, 2025
df2eb48
Link updates
Reshrahim May 28, 2025
846f2c9
Update config.toml
Reshrahim May 28, 2025
af3a1bc
Lowercased webservices to render properly
zachcasper May 28, 2025
1f8c18b
Resolved comments from Will
zachcasper May 28, 2025
2d1b022
Spelling
zachcasper May 28, 2025
1ec74ed
Spelling
zachcasper May 28, 2025
eb9f432
Spelling
zachcasper May 28, 2025
37d1ff3
Fixed case for postgresql.bicep
zachcasper May 28, 2025
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
6 changes: 5 additions & 1 deletion .github/config/en-custom.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,8 @@ DeploymentTemplate
gitops
auditable
bicepparam
cleartext
MyCompany
backendRequest
GatewayRouteTimeoutPolicy
timeoutPolicy
Expand All @@ -1309,4 +1311,6 @@ aci
managedIdentity
gatewayID
Ngroup
dns
resourcegroups
webservices
webServices
Binary file modified docs/content/getting-started/demo-dashboard-appgraph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
228 changes: 228 additions & 0 deletions docs/content/tutorials/composite-recipe/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
---
type: docs
title: "Tutorial: Create a composite Recipe"
linkTitle: "Create a composite Recipe"
description: "Learn how to create a composite recipe for a custom resource type"
weight: 140
categories: ["Tutorial"]
---
## Overview

This tutorial introduces composite Recipes. Rather than being composed of infrastructure or cloud resources like typical Recipes, composite Recipes are composed of other Radius resource types. Composite Recipes are authored in Bicep and can include any Radius resource types including built-in types, other custom types, AWS types, and/or Azure types.

The previous tutorial demonstrated how to define a custom resource type for a PostgreSQL database, author a Recipe for deploying the database on Kubernetes, and adding the new Resource Type to an application. The sample Todo List application used the built-in Containers resource type for the frontend service. This tutorial continues using the same application but extends the Containers resource type with additional functionality.

This tutorial demonstrates:

* Creating a web service custom resource type which adds an `ingress` property to the Containers schema
* Creating a composite Recipe in Bicep which creates a Gateway resource when the ingress property is true
* Modifying the Todo List application to use the new web service

{{< image src="tutorial3.png" alt="Diagram of the Todo List application with using a web service" width=600px >}}

## Prerequisites

This tutorial assumes you have completed the [Add a custom resource type]({{< ref "/tutorials/custom-resource-type" >}}) tutorial and have the demo application deployed with a PostgreSQL database and have Radius installed and configured.

Composite Recipes are only written in Bicep. If you used Terraform in the previous tutorial for your Recipes, you will need an OCI registry to store your Recipe. While Terraform-based Recipes are stored in Git, Bicep-based Recipes can only be published to OCI registry.

## Step 1: Create the web service resource type

Create or modify the `types.yaml` file so that it has both the `postgreSQL` type from the previous tutorial and the new `webServices` type. The schema for the new web services resource type is lengthy, so it is best to download the fully prepared file with both resource types.

{{< button text="Download types.yaml" link="snippets/types.yaml" newtab="true" >}}

This web services schema is simpler than it appears:

* `environment` and `application` have the same purpose as in the previous PostgreSQL example. These properties are on all resource types.
* `connections` is used to create dependencies, see [How-To: Connect to dependencies]({{< ref "guides/author-apps/containers/howto-connect-dependencies" >}}) for more details
* `ingress` is the first property the developer can set. The purpose of this property is to expose an option for developers to specify if the web service is accessible to connections from outside the cluster. This functionality will be implemented in the Recipe in step 3.
* `container` is a duplication of the Containers schema. Since the web service resource type extended Containers, the original schema must be included here. As you will see when implementing the Recipe, duplicating the Containers schema exactly makes it simple to pass multiple properties in only a few lines of code.

Create the resource type using the [rad resource-type create]({{< ref rad_resource-type_create >}}) command.

```bash
rad resource-type create webServices -f types.yaml
```

```
$ rad resource-type create webServices -f types.yaml
Resource provider "Radius.Resources" found. Registering resource type "webServices".
Creating resource type Radius.Resources/webServices with capabilities SupportsRecipes
Creating API Version Radius.Resources/webServices@2023-10-01-preview
Updating location Radius.Resources/global with new resource type
Resource type Radius.Resources/webServices created successfully

TYPE NAMESPACE APIVERSION
Radius.Resources/webServices Radius.Resources ["2023-10-01-preview"]
```

You can confirm the resource type was created using [`rad resource-type list`]({{< ref rad_resource-type_list >}}) command.

```bash
rad resource-type list
```

```
$ rad resource-type list
TYPE NAMESPACE APIVERSION
...
Radius.Resources/postgreSQL Radius.Resources ["2023-10-01-preview"]
Radius.Resources/webServices Radius.Resources ["2023-10-01-preview"]
```

## Step 2: Update the Bicep extension

Generate the Bicep extension using the [rad bicep publish-extension]({{< ref rad_bicep_publish-extension >}}) command.

```bash
rad bicep publish-extension -f types.yaml --target radiusResources.tgz
```
```
$ rad bicep publish-extension -f types.yaml --target radiusResources.tgz
Writing types to /var/folders/w8/89pqzjp52pbg4g256z9cpkww0000gn/T/bicep-extension-542196227/types.json
Writing index to /var/folders/w8/89pqzjp52pbg4g256z9cpkww0000gn/T/bicep-extension-542196227/index.json
Writing documentation to /var/folders/w8/89pqzjp52pbg4g256z9cpkww0000gn/T/bicep-extension-542196227/index.md
WARNING: The 'publish-extension' CLI command group is an experimental feature. Experimental features should be enabled for testing purposes only, as there are no guarantees about the quality or stability of these features. Do not enable these settings for any production usage, or your production environment may be subject to breaking.
Successfully published Bicep extension "types.yaml" to "radiusResources.tgz"
```

Since the `bicepconfig.json` file was modified in the previous tutorial, it does not need to be further modified.

## Step 3: Create, publish, and register the composite Recipe

The previous tutorial demonstrated deploying a resource using Terraform or Bicep resource providers such as the Kubernetes provider. This tutorial creates a composite Recipes which uses only built-in Radius types. These composite Recipes are only possible using Bicep.

1. Create a new file called `webservices.bicep` and add the following:

{{% rad file="snippets/webservices.bicep" lang="bicep" embed=true %}}

Notice that the `container` and `connections` properties are passed to the `Applications.Core/containers` built-in type using a single line.

1. Publish the Recipe to an OCI registry. Make sure to replace `host` and `registry` with your container registry.

```bash
rad bicep publish --file webservices.bicep --target br:<host>/<registry>/webservices:latest
```
```
$ rad bicep publish --file webservices.bicep --target br:<host>/<registry>/tutorial/webservices:latest
Building webservices.bicep...
WARNING: The following experimental Bicep features have been enabled: Extensibility. Experimental features should be enabled for testing purposes only, as there are no guarantees about the quality or stability of these features. Do not enable these settings for any production usage, or your production environment may be subject to breaking.
Pushed to <host>/<registry>/webservices@...

Successfully published Bicep file "webservices.bicep" to "<host>/<registry>/tutorial/webservices:latest"
```

1. Register the Bicep template as the `default` Recipe in the `default` environment.

```bash
rad recipe register default --environment default \
--resource-type Radius.Resources/webServices \
--template-kind bicep \
--template-path <host>/<registry>/webservices:latest
```
```
Successfully linked recipe "default" to environment "default"
```

You can confirm the Recipe was registered using `rad recipe list` command.

```bash
rad recipe list
```
```
rad recipe list
RECIPE TYPE TEMPLATE KIND TEMPLATE VERSION TEMPLATE
...
default Radius.Resources/webServices bicep <host>/<registry>/webservices:latest
default Radius.Resources/postgreSQL terraform git::https://github.com/<github-user-name>/recipes.git//kubernetes/postgres
...
```

## Step 4: Replace the container resource with a web service

1. Using the same `app.bicep` file, change the resource type for the `demo` resource from `Applications.Core/containers` to `Radius.Resources/webServices`.

```diff
- resource demo 'Applications.Core/containers@2023-10-01-preview' = {
+ resource demo 'Radius.Resources/webServices@2023-10-01-preview' = {
```

1. Add `ingress: true` to the demo resource so that a Gateway gets deployed as part of the web service. The web service also needs an environment property similar to the database custom resource.

```diff
resource demo 'Radius.Resources/webServices@2023-10-01-preview' = {
name: 'demo'
properties: {
application: application
+ environment: environment
+ ingress: true
```

1. Since the web service resource type has a built-in Gateway, remove the Gateway resource.

```diff
- resource gateway 'Applications.Core/gateways@2023-10-01-preview' = {
- name: 'gateway'
- properties: {
- application: application
- routes: [
- {
- path: '/'
- destination: 'http://demo:3000'
- }
- ]
- }
- }
```

1. Run the application using `rad run`.

```bash
rad deploy app.bicep
```
```
$ rad deploy app.bicep
Building app.bicep...
WARNING: The following experimental Bicep features have been enabled: Extensibility. Experimental features should be enabled for testing purposes only, as there are no guarantees about the quality or stability of these features. Do not enable these settings for any production usage, or your production environment may be subject to breaking.
Deploying template 'app.bicep' for application 'todolist' and environment '/planes/radius/local/resourceGroups/default/providers/Applications.Core/environments/default' from workspace 'default'...

Deployment In Progress...

Completed postgresql Radius.Resources/postgreSQL
Completed backend Applications.Core/containers
Completed demo Radius.Resources/webServices

Deployment Complete

Resources:
backend Applications.Core/containers
postgresql Radius.Resources/postgreSQL
demo Radius.Resources/webServices
```

1. Unlike before, the Gateway URL is not automatically shown. Use the `rad resource show` command to get the URL of the application.

```bash
rad resource show Applications.Core/gateways gateway -o json | grep url
```
```
"url": "http://gateway.todolist.172.18.0.6.nip.io"
```

1. Open the URL in your browser. The application has not changed despite changing the demo from a container to a web service resource and removing the gateway.

## Step 6: Clean up

1. Delete the application and all resources created by the application.

```bash
rad application delete todolist
```

1. Delete the PostgreSQL and web service resource types.

```bash
rad resource-type delete Radius.Resources/postgreSQL
rad resource-type delete Radius.Resources/webServices
```
Loading
Loading