Skip to content

Add Azure Bicep recipe for postgreSqlDatabases - #157

Draft
willtsai wants to merge 13 commits into
mainfrom
willtsai/add-postgresql-azure-aws-recipes
Draft

Add Azure Bicep recipe for postgreSqlDatabases#157
willtsai wants to merge 13 commits into
mainfrom
willtsai/add-postgresql-azure-aws-recipes

Conversation

@willtsai

Copy link
Copy Markdown
Contributor

Motivation

The Radius.Data/postgreSqlDatabases resource type only has recipes for Kubernetes-hosted PostgreSQL instances. This PR adds an Azure recipe that provisions Azure Database for PostgreSQL Flexible Server, giving platform engineers a cloud-managed option for PostgreSQL databases.

Approach

The new Bicep recipe at Data/postgreSqlDatabases/recipes/azure/bicep/azure-postgresql.bicep provisions:

  • An Azure Database for PostgreSQL Flexible Server with configurable version (default 16) and storage
  • A database on that server with UTF-8 charset and en_US.utf8 collation
  • A firewall rule allowing Azure services access (dev/test default)

Key design decisions:

  • Credentials from connected secrets -- follows the ACI recipe pattern where the recipe reads USERNAME and PASSWORD from context.resource.connections using the secretName property. This works with the Radius.Security/secrets resource backed by Azure Key Vault, so no @secure() recipe parameters are needed.
  • Size-to-SKU mapping -- maps the size property (S/M/L) to Azure SKU tiers: S -> Burstable B1ms, M -> GeneralPurpose D2s_v3, L -> MemoryOptimized E2ds_v4
  • Globally unique naming -- uses uniqueString(context.resource.id) to generate collision-free server names across environments
  • Safe navigation -- uses .? throughout for optional context paths per Bicep best practices, and - instead of / in Azure tag names

Notes

  • The firewall rule (0.0.0.0) allows all Azure services -- production recipes should use private endpoints or scoped rules
  • The recipe outputs host, port, and database in result.values, matching the resource type's read-only properties

willtsai and others added 4 commits May 14, 2026 17:55
Add recipes to provision PostgreSQL on Azure (Azure Database for PostgreSQL
Flexible Server) and AWS (Amazon RDS for PostgreSQL):

- Azure Bicep recipe with size-to-SKU mapping (S/M/L), firewall rule for
  Azure services, and credentials output via result.secrets
- Azure Terraform recipe using azurerm provider with k8s secret-based
  credentials, flexible server + database + firewall rule
- AWS Terraform recipe using terraform-aws-modules/rds/aws with VPC
  security group, k8s secret-based credentials, and size-to-instance
  class mapping
- Updated README with new recipe entries

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Will Tsai <28876888+willtsai@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Will Tsai <28876888+willtsai@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Will Tsai <28876888+willtsai@users.noreply.github.com>
Replace @secure() adminUsername/adminPassword recipe parameters with the
connected secrets pattern from the ACI recipe. The recipe now reads
USERNAME and PASSWORD from context.resource.connections using the
secretName property, which resolves to the Radius.Security/secrets
resource backed by Azure Key Vault.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Will Tsai <28876888+willtsai@users.noreply.github.com>
@willtsai
willtsai force-pushed the willtsai/add-postgresql-azure-aws-recipes branch from 25bcdec to 9a869cb Compare May 15, 2026 00:55
@willtsai

Copy link
Copy Markdown
Contributor Author

@copilot - take a look at this PR where an initSql property was added and implemented in the Kubernetes postgreSQL recipe. Please implement the same functionality in the Azure PostreSQL recipe here.

Copilot AI commented May 18, 2026

Copy link
Copy Markdown
Contributor

@copilot - take a look at this PR where an initSql property was added and implemented in the Kubernetes postgreSQL recipe. Please implement the same functionality in the Azure PostreSQ...

Added initSql support to the Azure recipe in c7fdf6a. Since Azure Database for PostgreSQL Flexible Server has no /docker-entrypoint-initdb.d/ equivalent, the recipe now provisions a Microsoft.Resources/deploymentScripts (Azure CLI container) when initSql is non-empty. It installs postgresql-client and runs the SQL via psql -v ON_ERROR_STOP=1 against the newly created database, using the same admin credentials read from the connected secret. The SQL is passed as a secureValue so it doesn't leak into deployment logs, and the script depends on the firewall rule so it can reach the server.

Comment thread Data/postgreSqlDatabases/recipes/azure/bicep/azure-postgresql.bicep
willtsai and others added 6 commits May 19, 2026 10:05
Replace postgresServer.properties.fullyQualifiedDomainName with a
manually constructed FQDN string to avoid ARM reference() calls that
fail when Radius deploys the recipe as a nested template. Also use
the database variable directly instead of postgresDb.name.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Will Tsai <28876888+willtsai@users.noreply.github.com>
Radius's deployment engine resolves resource IDs differently from
standard ARM, causing 'not defined in the template' validation errors
when dependsOn references a parent resource. ARM should infer the
parent-child ordering from the slash-separated name format. Also add
location to firewall rule resource.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Will Tsai <28876888+willtsai@users.noreply.github.com>
…dation

Radius's deployment engine cannot resolve ARM child resource references
(firewallRules, databases under flexibleServers). Replace them with a
single Azure CLI deployment script that creates the firewall rule,
database, and runs optional init SQL after the server is provisioned.
This avoids parent-child resource type declarations entirely.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Will Tsai <28876888+willtsai@users.noreply.github.com>
Use parent: for child resources and .properties.fullyQualifiedDomainName
in the output, matching the proven azure-sqlserverdb.bicep pattern.
Remove the resources array from output since the SQL recipe doesn't
use it. The earlier 'not defined in template' error was likely caused
by the resources array referencing postgresServer.id, not by the
parent: syntax itself.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Will Tsai <28876888+willtsai@users.noreply.github.com>
Signed-off-by: Will Tsai <28876888+willtsai@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants