Microsoft SQL Server database

Sample application running on a user-managed Azure SQL Database

Overview

This application showcases how Radius can use a user-managed Azure SQL Database.

Resource format


resource db 'Applications.Datastores/sqlDatabases@2023-10-01-preview' = {
  name: 'db'
  properties: {
    environment: environment
    application: app.id
    recipe: {
      // Name a specific Recipe to use
      name: 'azure-sqldb'
      // Optionally set recipe parameters if needed (specific to the Recipe)
      parameters: {
        server: '*******'
      }
    }
  }
}

resource db 'Applications.Datastores/sqlDatabases@2023-10-01-preview' = {
  name: 'db'
  properties: {
    environment: environment
    application: app.id
    resourceProvisioning: 'manual'
    resources:[
      {
        id: sqldb::dbinner.id
      }
    ]
    server: sqldb.properties.fullyQualifiedDomainName
    database: sqldb::dbinner.name
    port: port
    username: username
    secrets:{
      password: password
      connectionString: 'Data Source=tcp:${sqldb.properties.fullyQualifiedDomainName},${port};Initial Catalog=${sqldb::dbinner.name};User Id=${username};Password=${password};Encrypt=True;TrustServerCertificate=True'
    }
  }
}

Top-level

Key Required Description Example
name y The name of your resource. sql
location y The location of your resource. See common values for more information. global
properties y Properties of the resource. See below

Properties

Property Required Description Example(s)
application n The ID of the application resource this resource belongs to. app.id
environment y The ID of the environment resource this resource belongs to. env.id
resourceProvisioning n Specifies how the underlying service/resource is provisioned and managed. Options are to provision automatically via ‘recipe’ or provision manually via ‘manual’. Selection determines which set of fields to additionally require. Defaults to ‘recipe’. manual
recipe n Configuration for the Recipe which will deploy the backing infrastructure. See below
resources n An array of IDs of the underlying resources. See below
server n The fully qualified domain name of the SQL server. mydatabase.database.windows.net
database n The name of the SQL database. mydatabase
port n The SQL database port. 1433
username n The username for the SQL database. 'myusername'
secrets n Secrets used when building the resource from values. See below

Secrets

Property Required Description Example(s)
connectionString n The connection string for the SQL database. Write only. Server=tcp:<database-server-name>.database.windows.net,1433;Initial Catalog=<database-name>...
password n The password for the SQL database. Write only. mypassword

Recipe

Property Required Description Example(s)
name n Specifies the name of the Recipe that should be deployed. If not set, the name defaults to default. name: 'azure-prod'
parameters n An object that contains a list of parameters to set on the Recipe. { size: 'large' }

Resources

Property Required Description Example(s)
id n Resource ID of the supporting resource. sqlDb.id

Resource provisioning

Provision with a Recipe

Recipes automate infrastructure provisioning using approved templates. When no Recipe configuration is set Radius will use the Recipe registered as the default in the environment for the given resource. Otherwise, a Recipe name and parameters can optionally be set.

Provision manually

If you want to manually manage your infrastructure provisioning outside of Recipes, you can set resourceProvisioning to 'manual' and provide all necessary parameters and values and values that enable Radius to deploy or connect to the desired infrastructure.

Environment variables for connections

Other Radius resources, such as containers, may connect to a Azure SQL resource via connections. When a connection to Azure SQL named, for example, myconnection is declared, Radius injects values into environment variables that are then used to access the connected Azure SQL resource:

Environment variable Example(s)
CONNECTION_MYCONNECTION_DATABASE mydatabase
CONNECTION_MYCONNECTION_SERVER mydatabase.database.windows.net
CONNECTION_MYCONNECTION_PORT 1433
CONNECTION_MYCONNECTION_USERNAME myusername
CONNECTION_MYCONNECTION_PASSWORD mypassword
CONNECTION_MYCONNECTION_CONNECTIONSTRING Server=tcp:<database-server-name>.database.windows.net,1433;Initial Catalog=<database-name>...