Skip to content

Commit f8c85e1

Browse files
committed
refactor: update azd (wip)
1 parent f278534 commit f8c85e1

27 files changed

+1953
-495
lines changed

.devcontainer/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg; \
1717
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-$(lsb_release -cs)-prod $(lsb_release -cs) main" > /etc/apt/sources.list.d/dotnetdev.list';\
1818
sudo apt-get update && sudo apt-get -y install azure-functions-core-tools-4
1919

20+
# Install Azure Dev CLI
21+
RUN curl -fsSL https://aka.ms/install-azd.sh | bash
22+
2023
# apt-get update && export DEBIAN_FRONTEND=noninteractive \
2124
# && apt-get -y install --no-install-recommends <your-package-list-here>
2225

.devcontainer/devcontainer.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727
"ms-dotnettools.csharp",
2828
"ms-mssql.mssql",
2929
"ms-azuretools.vscode-azurefunctions",
30-
"Prisma.prisma"
30+
"Prisma.prisma",
31+
32+
// for Azure Developer CLI
33+
"ms-azuretools.azure-dev",
34+
"ms-azuretools.vscode-bicep",
35+
"ms-azuretools.vscode-docker"
3136
],
3237

3338
// Use 'forwardPorts' to make a list of ports inside the container available locally.
@@ -56,7 +61,14 @@
5661
"postCreateCommand": "bash .devcontainer/mssql/postCreateCommand.sh 'P@ssw0rd' './bin/Debug/' './.devcontainer/mssql/'",
5762
"features": {
5863
"github-cli": "latest",
59-
"azure-cli": "latest"
64+
"azure-cli": "latest",
65+
66+
// for Azure Developer CLI
67+
"docker-from-docker": "20.10",
68+
"node": {
69+
"version": "16",
70+
"nodeGypDependencies": false
71+
}
6072
}
6173

6274
}
Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
# yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json
22

33
name: azure-sql-prisma-vue
4-
5-
infra:
6-
provider: bicep
7-
path: main
8-
94
services:
10-
web:
11-
project: ./client
12-
dist: dist
13-
language: js
14-
host: staticwebapp
5+
web:
6+
project: ../../client
7+
dist: dist
8+
language: js
9+
host: staticwebapp

.repo/bicep/infra/abbreviations.json

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
{
2+
"analysisServicesServers": "as",
3+
"apiManagementService": "apim-",
4+
"appConfigurationConfigurationStores": "appcs-",
5+
"appManagedEnvironments": "cae-",
6+
"appContainerApps": "ca-",
7+
"authorizationPolicyDefinitions": "policy-",
8+
"automationAutomationAccounts": "aa-",
9+
"blueprintBlueprints": "bp-",
10+
"blueprintBlueprintsArtifacts": "bpa-",
11+
"cacheRedis": "redis-",
12+
"cdnProfiles": "cdnp-",
13+
"cdnProfilesEndpoints": "cdne-",
14+
"cognitiveServicesAccounts": "cog-",
15+
"cognitiveServicesFormRecognizer": "cog-fr-",
16+
"cognitiveServicesTextAnalytics": "cog-ta-",
17+
"computeAvailabilitySets": "avail-",
18+
"computeCloudServices": "cld-",
19+
"computeDiskEncryptionSets": "des",
20+
"computeDisks": "disk",
21+
"computeDisksOs": "osdisk",
22+
"computeGalleries": "gal",
23+
"computeSnapshots": "snap-",
24+
"computeVirtualMachines": "vm",
25+
"computeVirtualMachineScaleSets": "vmss-",
26+
"containerInstanceContainerGroups": "ci",
27+
"containerRegistryRegistries": "cr",
28+
"containerServiceManagedClusters": "aks-",
29+
"databricksWorkspaces": "dbw-",
30+
"dataFactoryFactories": "adf-",
31+
"dataLakeAnalyticsAccounts": "dla",
32+
"dataLakeStoreAccounts": "dls",
33+
"dataMigrationServices": "dms-",
34+
"dBforMySQLServers": "mysql-",
35+
"dBforPostgreSQLServers": "psql-",
36+
"devicesIotHubs": "iot-",
37+
"devicesProvisioningServices": "provs-",
38+
"devicesProvisioningServicesCertificates": "pcert-",
39+
"documentDBDatabaseAccounts": "cosmos-",
40+
"eventGridDomains": "evgd-",
41+
"eventGridDomainsTopics": "evgt-",
42+
"eventGridEventSubscriptions": "evgs-",
43+
"eventHubNamespaces": "evhns-",
44+
"eventHubNamespacesEventHubs": "evh-",
45+
"hdInsightClustersHadoop": "hadoop-",
46+
"hdInsightClustersHbase": "hbase-",
47+
"hdInsightClustersKafka": "kafka-",
48+
"hdInsightClustersMl": "mls-",
49+
"hdInsightClustersSpark": "spark-",
50+
"hdInsightClustersStorm": "storm-",
51+
"hybridComputeMachines": "arcs-",
52+
"insightsActionGroups": "ag-",
53+
"insightsComponents": "appi-",
54+
"keyVaultVaults": "kv-",
55+
"kubernetesConnectedClusters": "arck",
56+
"kustoClusters": "dec",
57+
"kustoClustersDatabases": "dedb",
58+
"logicIntegrationAccounts": "ia-",
59+
"logicWorkflows": "logic-",
60+
"machineLearningServicesWorkspaces": "mlw-",
61+
"managedIdentityUserAssignedIdentities": "id-",
62+
"managementManagementGroups": "mg-",
63+
"migrateAssessmentProjects": "migr-",
64+
"networkApplicationGateways": "agw-",
65+
"networkApplicationSecurityGroups": "asg-",
66+
"networkAzureFirewalls": "afw-",
67+
"networkBastionHosts": "bas-",
68+
"networkConnections": "con-",
69+
"networkDnsZones": "dnsz-",
70+
"networkExpressRouteCircuits": "erc-",
71+
"networkFirewallPolicies": "afwp-",
72+
"networkFirewallPoliciesWebApplication": "waf",
73+
"networkFirewallPoliciesRuleGroups": "wafrg",
74+
"networkFrontDoors": "fd-",
75+
"networkFrontdoorWebApplicationFirewallPolicies": "fdfp-",
76+
"networkLoadBalancersExternal": "lbe-",
77+
"networkLoadBalancersInternal": "lbi-",
78+
"networkLoadBalancersInboundNatRules": "rule-",
79+
"networkLocalNetworkGateways": "lgw-",
80+
"networkNatGateways": "ng-",
81+
"networkNetworkInterfaces": "nic-",
82+
"networkNetworkSecurityGroups": "nsg-",
83+
"networkNetworkSecurityGroupsSecurityRules": "nsgsr-",
84+
"networkNetworkWatchers": "nw-",
85+
"networkPrivateDnsZones": "pdnsz-",
86+
"networkPrivateLinkServices": "pl-",
87+
"networkPublicIPAddresses": "pip-",
88+
"networkPublicIPPrefixes": "ippre-",
89+
"networkRouteFilters": "rf-",
90+
"networkRouteTables": "rt-",
91+
"networkRouteTablesRoutes": "udr-",
92+
"networkTrafficManagerProfiles": "traf-",
93+
"networkVirtualNetworkGateways": "vgw-",
94+
"networkVirtualNetworks": "vnet-",
95+
"networkVirtualNetworksSubnets": "snet-",
96+
"networkVirtualNetworksVirtualNetworkPeerings": "peer-",
97+
"networkVirtualWans": "vwan-",
98+
"networkVpnGateways": "vpng-",
99+
"networkVpnGatewaysVpnConnections": "vcn-",
100+
"networkVpnGatewaysVpnSites": "vst-",
101+
"notificationHubsNamespaces": "ntfns-",
102+
"notificationHubsNamespacesNotificationHubs": "ntf-",
103+
"operationalInsightsWorkspaces": "log-",
104+
"portalDashboards": "dash-",
105+
"powerBIDedicatedCapacities": "pbi-",
106+
"purviewAccounts": "pview-",
107+
"recoveryServicesVaults": "rsv-",
108+
"resourcesResourceGroups": "rg-",
109+
"searchSearchServices": "srch-",
110+
"serviceBusNamespaces": "sb-",
111+
"serviceBusNamespacesQueues": "sbq-",
112+
"serviceBusNamespacesTopics": "sbt-",
113+
"serviceEndPointPolicies": "se-",
114+
"serviceFabricClusters": "sf-",
115+
"signalRServiceSignalR": "sigr",
116+
"sqlManagedInstances": "sqlmi-",
117+
"sqlServers": "sql-",
118+
"sqlServersDataWarehouse": "sqldw-",
119+
"sqlServersDatabases": "sqldb-",
120+
"sqlServersDatabasesStretch": "sqlstrdb-",
121+
"storageStorageAccounts": "st",
122+
"storageStorageAccountsVm": "stvm",
123+
"storSimpleManagers": "ssimp",
124+
"streamAnalyticsCluster": "asa-",
125+
"synapseWorkspaces": "syn",
126+
"synapseWorkspacesAnalyticsWorkspaces": "synw",
127+
"synapseWorkspacesSqlPoolsDedicated": "syndp",
128+
"synapseWorkspacesSqlPoolsSpark": "synsp",
129+
"timeSeriesInsightsEnvironments": "tsi-",
130+
"webServerFarms": "plan-",
131+
"webSitesAppService": "app-",
132+
"webSitesAppServiceEnvironment": "ase-",
133+
"webSitesFunctions": "func-",
134+
"webStaticSites": "stapp-"
135+
}

.repo/bicep/infra/app/sqlserver.bicep

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
param environmentName string
2+
param location string = resourceGroup().location
3+
4+
param databaseName string = 'ToDo'
5+
param keyVaultName string
6+
7+
@secure()
8+
param sqlAdminPassword string
9+
@secure()
10+
param appUserPassword string
11+
12+
module sqlServer '../core/database/sqlserver/sqlserver.bicep' = {
13+
name: 'sqlserver'
14+
params: {
15+
environmentName: environmentName
16+
location: location
17+
dbName: databaseName
18+
keyVaultName: keyVaultName
19+
sqlAdminPassword: sqlAdminPassword
20+
appUserPassword: appUserPassword
21+
}
22+
}
23+
24+
module sqlServerShadow '../core/database/sqlserver/sqlserver.bicep' = {
25+
name: 'sqlserverShadow'
26+
params: {
27+
environmentName: environmentName
28+
location: location
29+
dbName: '${databaseName}-shadow'
30+
keyVaultName: keyVaultName
31+
sqlAdminPassword: sqlAdminPassword
32+
appUserPassword: appUserPassword
33+
}
34+
}
35+
36+
output sqlConnectionStringKey string = sqlServer.outputs.sqlConnectionStringKey
37+
output sqlDatabaseName string = databaseName
38+
output sqlDatabaseEndpoint string = sqlServer.outputs.sqlDatabaseEndpoint
39+
40+
output sqlConnectionStringKeyShadow string = sqlServerShadow.outputs.sqlConnectionStringKey
41+
output sqlDatabaseNameShadow string = databaseName
42+
output sqlDatabaseEndpointShadow string = sqlServerShadow.outputs.sqlDatabaseEndpoint
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
param environmentName string
2+
param location string = resourceGroup().location
3+
4+
param serviceName string = 'web'
5+
param applicationInsightsName string = ''
6+
param appSettings object = {}
7+
param keyVaultName string
8+
9+
module web '../core/host/staticwebapp.bicep' = {
10+
name: '${serviceName}-staticwebapp-module'
11+
params: {
12+
environmentName: environmentName
13+
location: location
14+
serviceName: serviceName
15+
applicationInsightsName: applicationInsightsName
16+
appSettings: appSettings
17+
keyVaultName: keyVaultName
18+
scmDoBuildDuringDeployment: true
19+
}
20+
}
21+
22+
output WEB_NAME string = web.outputs.name
23+
output WEB_URI string = web.outputs.uri
24+
output WEB_IDENTITY_PRINCIPAL_ID string = web.outputs.principalId
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
param environmentName string
2+
param location string = resourceGroup().location
3+
4+
param appUser string = 'appUser'
5+
param dbName string
6+
param keyVaultName string
7+
param sqlAdmin string = 'sqlAdmin'
8+
param sqlConnectionStringKey string = 'AZURE-SQL-CONNECTION-STRING'
9+
10+
@secure()
11+
param sqlAdminPassword string
12+
@secure()
13+
param appUserPassword string
14+
15+
var abbrs = loadJsonContent('../../../abbreviations.json')
16+
var resourceToken = toLower(uniqueString(subscription().id, environmentName, location))
17+
var tags = { 'azd-env-name': environmentName }
18+
19+
resource sqlServer 'Microsoft.Sql/servers@2022-02-01-preview' = {
20+
name: '${abbrs.sqlServers}${resourceToken}'
21+
location: location
22+
tags: tags
23+
properties: {
24+
version: '12.0'
25+
minimalTlsVersion: '1.2'
26+
publicNetworkAccess: 'Enabled'
27+
administratorLogin: sqlAdmin
28+
administratorLoginPassword: sqlAdminPassword
29+
}
30+
31+
resource database 'databases' = {
32+
name: dbName
33+
location: location
34+
}
35+
36+
resource firewall 'firewallRules' = {
37+
name: 'Azure Services'
38+
properties: {
39+
// Allow all clients
40+
// Note: range [0.0.0.0-0.0.0.0] means "allow all Azure-hosted clients only".
41+
// This is not sufficient, because we also want to allow direct access from developer machine, for debugging purposes.
42+
startIpAddress: '0.0.0.1'
43+
endIpAddress: '255.255.255.254'
44+
}
45+
}
46+
}
47+
48+
resource sqlDeploymentScript 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
49+
name: 'script-${resourceToken}'
50+
location: location
51+
kind: 'AzureCLI'
52+
properties: {
53+
azCliVersion: '2.37.0'
54+
retentionInterval: 'PT1H' // Retain the script resource for 1 hour after it ends running
55+
timeout: 'PT5M' // Five minutes
56+
cleanupPreference: 'OnSuccess'
57+
environmentVariables: [
58+
{
59+
name: 'APPUSERNAME'
60+
value: appUser
61+
}
62+
{
63+
name: 'APPUSERPASSWORD'
64+
secureValue: appUserPassword
65+
}
66+
{
67+
name: 'DBNAME'
68+
value: dbName
69+
}
70+
{
71+
name: 'DBSERVER'
72+
value: sqlServer.properties.fullyQualifiedDomainName
73+
}
74+
{
75+
name: 'SQLCMDPASSWORD'
76+
secureValue: sqlAdminPassword
77+
}
78+
{
79+
name: 'SQLADMIN'
80+
value: sqlAdmin
81+
}
82+
]
83+
84+
scriptContent: '''
85+
wget https://github.com/microsoft/go-sqlcmd/releases/download/v0.8.1/sqlcmd-v0.8.1-linux-x64.tar.bz2
86+
tar x -f sqlcmd-v0.8.1-linux-x64.tar.bz2 -C .
87+
88+
cat <<SCRIPT_END > ./initDb.sql
89+
drop user ${APPUSERNAME}
90+
go
91+
create user ${APPUSERNAME} with password = '${APPUSERPASSWORD}'
92+
go
93+
alter role db_owner add member ${APPUSERNAME}
94+
go
95+
SCRIPT_END
96+
97+
./sqlcmd -S ${DBSERVER} -d ${DBNAME} -U ${SQLADMIN} -i ./initDb.sql
98+
'''
99+
}
100+
}
101+
102+
resource sqlAdminPasswordSecret 'Microsoft.KeyVault/vaults/secrets@2022-07-01' = {
103+
parent: keyVault
104+
name: 'sqlAdminPassword'
105+
properties: {
106+
value: sqlAdminPassword
107+
}
108+
}
109+
110+
resource appUserPasswordSecret 'Microsoft.KeyVault/vaults/secrets@2022-07-01' = {
111+
parent: keyVault
112+
name: 'appUserPassword'
113+
properties: {
114+
value: appUserPassword
115+
}
116+
}
117+
118+
resource sqlAzureConnectionStringSercret 'Microsoft.KeyVault/vaults/secrets@2022-07-01' = {
119+
parent: keyVault
120+
name: sqlConnectionStringKey
121+
properties: {
122+
value: '${azureSqlConnectionString}; Password=${appUserPassword}'
123+
}
124+
}
125+
126+
resource keyVault 'Microsoft.KeyVault/vaults@2022-07-01' existing = {
127+
name: keyVaultName
128+
}
129+
130+
var azureSqlConnectionString = 'Server=${sqlServer.properties.fullyQualifiedDomainName}; Database=${sqlServer::database.name}; User=${appUser}'
131+
output sqlConnectionStringKey string = sqlConnectionStringKey
132+
output sqlDatabaseEndpoint string = sqlServer.properties.fullyQualifiedDomainName

0 commit comments

Comments
 (0)