From bb33b85d96e18fecdeccc2596b1bfc19f77253de Mon Sep 17 00:00:00 2001 From: Justin Kotalik Date: Tue, 13 Dec 2022 12:25:22 -0800 Subject: [PATCH] Making tutorial match docs version --- tutorial/app.bicep | 15 ++++++++-- tutorial/azure-cosmosdb.bicep | 3 +- tutorial/mongo-container.bicep | 55 ++++++++++++++++++---------------- 3 files changed, 44 insertions(+), 29 deletions(-) diff --git a/tutorial/app.bicep b/tutorial/app.bicep index 70c3b2e4..4ca25c1c 100644 --- a/tutorial/app.bicep +++ b/tutorial/app.bicep @@ -1,3 +1,4 @@ +//APPBASE import radius as radius param environment string @@ -9,7 +10,9 @@ resource app 'Applications.Core/applications@2022-03-15-privatepreview' = { environment: environment } } +//APPBASE +//CONTAINER resource frontend 'Applications.Core/containers@2022-03-15-privatepreview' = { name: 'frontend' location: 'global' @@ -39,7 +42,9 @@ resource frontendRoute 'Applications.Core/httpRoutes@2022-03-15-privatepreview' application: app.id } } +//CONTAINER +//GATEWAY resource gateway 'Applications.Core/gateways@2022-03-15-privatepreview' = { name: 'public' location: 'global' @@ -53,7 +58,9 @@ resource gateway 'Applications.Core/gateways@2022-03-15-privatepreview' = { ] } } +//GATEWAY +//DATABASE LINK resource db 'Applications.Link/mongoDatabases@2022-03-15-privatepreview' = { name: 'db' location: 'global' @@ -61,14 +68,18 @@ resource db 'Applications.Link/mongoDatabases@2022-03-15-privatepreview' = { environment: app.properties.environment application: app.id mode: 'values' - host: mongo.outputs.name + host: mongo.outputs.host port: mongo.outputs.port secrets: { - connectionString: 'mongodb://${mongo.outputs.name}:${mongo.outputs.port}/${mongo.outputs.dbName}?authSource=admin' + // Manually build the link from the connectionString value + connectionString: mongo.outputs.connectionString } } } +//DATABASE LINK +//MONGOMODULE module mongo 'mongo-container.bicep' = { name: 'mongo-module' } +//MONGOMODULE diff --git a/tutorial/azure-cosmosdb.bicep b/tutorial/azure-cosmosdb.bicep index 9507c3e3..344ee53f 100644 --- a/tutorial/azure-cosmosdb.bicep +++ b/tutorial/azure-cosmosdb.bicep @@ -1,9 +1,9 @@ import radius as radius param location string - param name string = 'todoapp-cosmos-${uniqueString(resourceGroup().id)}' +//COSMOS resource cosmosAccount 'Microsoft.DocumentDB/databaseAccounts@2021-04-15' = { name: toLower(name) location: location @@ -33,5 +33,6 @@ resource cosmosAccount 'Microsoft.DocumentDB/databaseAccounts@2021-04-15' = { } } +//COSMOS output cosmosDatabaseId string = cosmosAccount::cosmosDb.id diff --git a/tutorial/mongo-container.bicep b/tutorial/mongo-container.bicep index 91c0d4f5..7c94612b 100644 --- a/tutorial/mongo-container.bicep +++ b/tutorial/mongo-container.bicep @@ -1,3 +1,4 @@ +//MONGO import kubernetes as kubernetes { kubeConfig: '' namespace: namespace @@ -8,6 +9,7 @@ param name string = 'mongo' var port = 27017 +//SS resource statefulset 'apps/StatefulSet@v1' = { metadata: { name: name @@ -97,6 +99,33 @@ resource statefulset 'apps/StatefulSet@v1' = { ] } } +//SS +//SERVICE +resource service 'core/Service@v1' = { + metadata: { + name: name + labels: { + app: name + } + } + spec: { + clusterIP: 'None' + ports: [ + { + port: port + } + ] + selector: { + app: name + } + } +} +//SERVICE + +output host string = name +output port int = int(port) +output connectionString string = 'mongodb://${name}.${namespace}.svc.cluster.local:${port}/${name}?authSource=admin' +//MONGO resource sa 'core/ServiceAccount@v1' = { metadata: { @@ -157,29 +186,3 @@ resource secret 'core/Secret@v1' = { connectionString: 'mongodb://${name}.${namespace}.svc.cluster.local:${port}/${name}?authSource=admin' } } - -resource service 'core/Service@v1' = { - metadata: { - name: name - labels: { - app: name - } - } - spec: { - clusterIP: 'None' - ports: [ - { - port: port - } - ] - selector: { - app: name - } - } -} - -output name string = '${name}.${namespace}.svc.cluster.local' -output dbName string = name -output port int = port - -output connectionString string = 'mongodb://${name}.${namespace}.svc.cluster.local:${port}/${name}?authSource=admin'