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

KeyRequiredDescriptionExample
nameyThe name of your resource.sql
locationyThe location of your resource. See common values for more information.global
propertiesyProperties of the resource.See below

Properties

PropertyRequiredDescriptionExample(s)
applicationnThe ID of the application resource this resource belongs to.app.id
environmentyThe ID of the environment resource this resource belongs to.env.id
resourceProvisioningnSpecifies 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
recipenConfiguration for the Recipe which will deploy the backing infrastructure.See below
resourcesnAn array of IDs of the underlying resources.See below
servernThe fully qualified domain name of the SQL server.mydatabase.database.windows.net
databasenThe name of the SQL database.mydatabase
portnThe SQL database port.1433
usernamenThe username for the SQL database.'myusername'
secretsnSecrets used when building the resource from values.See below

Secrets

PropertyRequiredDescriptionExample(s)
connectionStringnThe connection string for the SQL database. Write only.Server=tcp:<database-server-name>.database.windows.net,1433;Initial Catalog=<database-name>...
passwordnThe password for the SQL database. Write only.mypassword

Recipe

PropertyRequiredDescriptionExample(s)
namenSpecifies the name of the Recipe that should be deployed. If not set, the name defaults to default.name: 'azure-prod'
parametersnAn object that contains a list of parameters to set on the Recipe.{ size: 'large' }

Resources

PropertyRequiredDescriptionExample(s)
idnResource 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 variableExample(s)
CONNECTION_MYCONNECTION_DATABASEmydatabase
CONNECTION_MYCONNECTION_SERVERmydatabase.database.windows.net
CONNECTION_MYCONNECTION_PORT1433
CONNECTION_MYCONNECTION_USERNAMEmyusername
CONNECTION_MYCONNECTION_PASSWORDmypassword
CONNECTION_MYCONNECTION_CONNECTIONSTRINGServer=tcp:<database-server-name>.database.windows.net,1433;Initial Catalog=<database-name>...