From 538cb2ae3e1b294fdbe6e55a73e6779fe0546df8 Mon Sep 17 00:00:00 2001 From: jolov Date: Fri, 23 Feb 2024 10:48:57 -0800 Subject: [PATCH 1/3] Update DeploymentScript to not use placeholders --- .../src/resources/DeploymentScript.cs | 15 +++++++++++---- .../rg_TEST_module/rg_TEST_module.bicep | 8 ++++---- .../rg_TEST_module/rg_TEST_module.bicep | 8 ++++---- .../Infrastructure/WebSiteUsingL1/main.bicep | 2 ++ .../rg_TEST_module/rg_TEST_module.bicep | 18 ++++++++++-------- .../Infrastructure/WebSiteUsingL2/main.bicep | 2 ++ .../rg_TEST_module/rg_TEST_module.bicep | 18 ++++++++++-------- .../tests/ProvisioningTests.cs | 14 ++++++++++++-- .../tests/TestCommonSqlDatabase.cs | 16 +++++++++++++--- 9 files changed, 68 insertions(+), 33 deletions(-) diff --git a/sdk/provisioning/Azure.Provisioning/src/resources/DeploymentScript.cs b/sdk/provisioning/Azure.Provisioning/src/resources/DeploymentScript.cs index da50a9fb12606..f9b96d6b2b2cf 100644 --- a/sdk/provisioning/Azure.Provisioning/src/resources/DeploymentScript.cs +++ b/sdk/provisioning/Azure.Provisioning/src/resources/DeploymentScript.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Linq; using Azure.Core; using Azure.Provisioning.ResourceManager; using Azure.ResourceManager.Resources.Models; @@ -46,11 +47,13 @@ public DeploymentScript(IConstruct scope, string resourceName, IEnumerableThe scope. /// The resource name. /// The database. + /// The database name. + /// The database server name. /// The app user password secret. /// The sql admin password secret. /// The resource version. /// The resource location. - public DeploymentScript(IConstruct scope, string resourceName, Resource database, Parameter appUserPasswordSecret, Parameter sqlAdminPasswordSecret, string version = _defaultVersion, AzureLocation? location = default) + public DeploymentScript(IConstruct scope, string resourceName, Resource database, Parameter databaseName, Parameter databaseServerName, Parameter appUserPasswordSecret, Parameter sqlAdminPasswordSecret, string version = _defaultVersion, AzureLocation? location = default) : base(scope, null, resourceName, ResourceTypeName, version, (name) => ArmResourcesModelFactory.AzureCliScript( name: name, resourceType: ResourceTypeName, @@ -61,11 +64,11 @@ public DeploymentScript(IConstruct scope, string resourceName, Resource database cleanupPreference: ScriptCleanupOptions.OnSuccess, environmentVariables: new List { - new ScriptEnvironmentVariable("APPUSERNAME") { Value = "appUser" }, - new ScriptEnvironmentVariable("APPUSERPASSWORD") { SecureValue = $"_p_.{appUserPasswordSecret.Name}" }, + new ScriptEnvironmentVariable("APPUSERPASSWORD"), + new ScriptEnvironmentVariable("SQLCMDPASSWORD"), new ScriptEnvironmentVariable("DBNAME") { Value = $"_p_.{database.Name}.name" }, new ScriptEnvironmentVariable("DBSERVER") { Value = $"_p_.{database.Parent!.Name}.properties.fullyQualifiedDomainName" }, - new ScriptEnvironmentVariable("SQLCMDPASSWORD") { SecureValue = $"_p_.{sqlAdminPasswordSecret.Name}" }, + new ScriptEnvironmentVariable("APPUSERNAME") { Value = "appUser" }, new ScriptEnvironmentVariable("SQLADMIN") { Value = "sqlAdmin" }, }, scriptContent: """ @@ -84,6 +87,10 @@ alter role db_owner add member ${APPUSERNAME} ./sqlcmd -S ${DBSERVER} -d ${DBNAME} -U ${SQLADMIN} -i ./initDb.sql """)) { + AssignParameter(data => data.EnvironmentVariables[0].SecureValue, appUserPasswordSecret); + AssignParameter(data => data.EnvironmentVariables[1].SecureValue, sqlAdminPasswordSecret); + AssignParameter(data => data.EnvironmentVariables[2].Value, databaseName); + AssignParameter(data => data.EnvironmentVariables[3].Value, databaseServerName); Scope.AddParameter(appUserPasswordSecret); Scope.AddParameter(sqlAdminPasswordSecret); } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST_module/rg_TEST_module.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST_module/rg_TEST_module.bicep index 82d658009d3bb..78b54985f9094 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST_module/rg_TEST_module.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST_module/rg_TEST_module.bicep @@ -1,6 +1,6 @@ -resource storageAccount_nyqKj4fVa 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoacct783bf4edd65646e' +resource storageAccount_qoZyLiiYO 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoacctfadf2ed2a58d43c' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_nyqKj4fVa 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_CjbeMfMgo 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_nyqKj4fVa +resource blobService_8zCl9jaMv 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_qoZyLiiYO name: 'default' properties: { } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST_module/rg_TEST_module.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST_module/rg_TEST_module.bicep index c935bdba2308d..8dbe8551097ea 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST_module/rg_TEST_module.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST_module/rg_TEST_module.bicep @@ -1,6 +1,6 @@ -resource storageAccount_PdjzkDDBx 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoacct1434f94e82d1418' +resource storageAccount_AWAf1i775 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoacct03a34cbffeba423' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_PdjzkDDBx 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_uNPuvG8H2 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_PdjzkDDBx +resource blobService_hbrFFOTsM 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_AWAf1i775 name: 'default' properties: { deleteRetentionPolicy: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep index fd23a848138b1..97e115f7e558f 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep @@ -29,3 +29,5 @@ module rg_TEST_module './resources/rg_TEST_module/rg_TEST_module.bicep' = { output SERVICE_API_IDENTITY_PRINCIPAL_ID string = rg_TEST_module.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID output vaultUri string = rg_TEST_module.outputs.vaultUri +output sqlServerName string = rg_TEST_module.outputs.sqlServerName +output sqlServerDatabaseName string = rg_TEST_module.outputs.sqlServerDatabaseName diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST_module/rg_TEST_module.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST_module/rg_TEST_module.bicep index 07b502fac695b..907520e47fee1 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST_module/rg_TEST_module.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST_module/rg_TEST_module.bicep @@ -176,24 +176,24 @@ SCRIPT_END ./sqlcmd -S ${DBSERVER} -d ${DBNAME} -U ${SQLADMIN} -i ./initDb.sql''' environmentVariables: [ { - name: 'APPUSERNAME' - value: 'appUser' + name: 'APPUSERPASSWORD' + secureValue: appUserPassword } { - name: 'APPUSERPASSWORD' - secureValue: '_p_.appUserPassword' + name: 'SQLCMDPASSWORD' + secureValue: sqlAdminPassword } { name: 'DBNAME' - value: '_p_.sqlDatabase_U7NzorRJT.name' + value: sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName } { name: 'DBSERVER' - value: '_p_.sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName' + value: sqlDatabase_U7NzorRJT.name } { - name: 'SQLCMDPASSWORD' - secureValue: '_p_.sqlAdminPassword' + name: 'APPUSERNAME' + value: 'appUser' } { name: 'SQLADMIN' @@ -240,3 +240,5 @@ resource applicationSettingsResource_vEe46o8Zn 'Microsoft.Web/sites/config@2021- output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_W5EweSXEq.identity.principalId output vaultUri string = keyVault_CRoMbemLF.properties.vaultUri +output sqlServerName string = sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName +output sqlServerDatabaseName string = sqlDatabase_U7NzorRJT.name diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep index fd23a848138b1..3439a97a8d279 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep @@ -28,4 +28,6 @@ module rg_TEST_module './resources/rg_TEST_module/rg_TEST_module.bicep' = { } output SERVICE_API_IDENTITY_PRINCIPAL_ID string = rg_TEST_module.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID +output sqlServerName string = rg_TEST_module.outputs.sqlServerName +output sqlServerDatabaseName string = rg_TEST_module.outputs.sqlServerDatabaseName output vaultUri string = rg_TEST_module.outputs.vaultUri diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST_module/rg_TEST_module.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST_module/rg_TEST_module.bicep index d76769bb7ecd6..d3f306911d50b 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST_module/rg_TEST_module.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST_module/rg_TEST_module.bicep @@ -176,24 +176,24 @@ SCRIPT_END ./sqlcmd -S ${DBSERVER} -d ${DBNAME} -U ${SQLADMIN} -i ./initDb.sql''' environmentVariables: [ { - name: 'APPUSERNAME' - value: 'appUser' + name: 'APPUSERPASSWORD' + secureValue: appUserPassword } { - name: 'APPUSERPASSWORD' - secureValue: '_p_.appUserPassword' + name: 'SQLCMDPASSWORD' + secureValue: sqlAdminPassword } { name: 'DBNAME' - value: '_p_.sqlDatabase_U7NzorRJT.name' + value: sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName } { name: 'DBSERVER' - value: '_p_.sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName' + value: sqlDatabase_U7NzorRJT.name } { - name: 'SQLCMDPASSWORD' - secureValue: '_p_.sqlAdminPassword' + name: 'APPUSERNAME' + value: 'appUser' } { name: 'SQLADMIN' @@ -239,4 +239,6 @@ resource applicationSettingsResource_vEe46o8Zn 'Microsoft.Web/sites/config@2021- } output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_W5EweSXEq.identity.principalId +output sqlServerName string = sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName +output sqlServerDatabaseName string = sqlDatabase_U7NzorRJT.name output vaultUri string = keyVault_CRoMbemLF.properties.vaultUri diff --git a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs index c55f7f06261fd..b0aa9cf0abb02 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs +++ b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs @@ -60,14 +60,24 @@ public async Task WebSiteUsingL1() SqlServer sqlServer = new SqlServer(infra, "sqlserver"); sqlServer.AssignParameter(sql => sql.AdministratorLoginPassword, sqlAdminPasswordParam); + Output sqlServerName = sqlServer.AddOutput(sql => sql.FullyQualifiedDomainName, "sqlServerName"); - SqlDatabase sqlDatabase = new SqlDatabase(infra); + SqlDatabase sqlDatabase = new SqlDatabase(infra, sqlServer); + + Output sqlServerDatabaseName = sqlDatabase.AddOutput(db => db.Name, "sqlServerDatabaseName"); KeyVaultSecret sqlAzureConnectionStringSecret = new KeyVaultSecret(infra, "connectionString", sqlDatabase.GetConnectionString(appUserPasswordParam)); SqlFirewallRule sqlFirewallRule = new SqlFirewallRule(infra, "firewallRule"); - DeploymentScript deploymentScript = new DeploymentScript(infra, "cliScript", sqlDatabase, appUserPasswordParam, sqlAdminPasswordParam); + DeploymentScript deploymentScript = new DeploymentScript( + infra, + "cliScript", + sqlDatabase, + new Parameter(sqlServerName), + new Parameter(sqlServerDatabaseName), + appUserPasswordParam, + sqlAdminPasswordParam); WebSite backEnd = new WebSite(infra, "backEnd", appServicePlan, WebSiteRuntime.Dotnetcore, "6.0"); diff --git a/sdk/provisioning/Azure.Provisioning/tests/TestCommonSqlDatabase.cs b/sdk/provisioning/Azure.Provisioning/tests/TestCommonSqlDatabase.cs index 5383089000545..5892bea38d82e 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/TestCommonSqlDatabase.cs +++ b/sdk/provisioning/Azure.Provisioning/tests/TestCommonSqlDatabase.cs @@ -35,13 +35,23 @@ public TestCommonSqlDatabase(IConstruct scope, KeyVault? keyVault = null) SqlServer sqlServer = new SqlServer(this, "sqlserver"); sqlServer.AssignParameter(sql => sql.AdministratorLoginPassword, sqlAdminPasswordParam); - SqlDatabase = new SqlDatabase(this); + Output sqlServerName = sqlServer.AddOutput(sql => sql.FullyQualifiedDomainName, "sqlServerName"); + + SqlDatabase = new SqlDatabase(this, sqlServer); + Output sqlServerDatabaseName = SqlDatabase.AddOutput(db => db.Name, "sqlServerDatabaseName"); KeyVaultSecret sqlAzureConnectionStringSecret = new KeyVaultSecret(this, "connectionString", SqlDatabase.GetConnectionString(appUserPasswordParam)); SqlFirewallRule sqlFirewallRule = new SqlFirewallRule(this, "firewallRule"); - - DeploymentScript deploymentScript = new DeploymentScript(this, "cliScript", SqlDatabase, appUserPasswordParam, sqlAdminPasswordParam); + Parameter databaseName = new Parameter("appUserPassword", "Application user password", isSecure: true); + DeploymentScript deploymentScript = new DeploymentScript( + this, + "cliScript", + SqlDatabase, + new Parameter(sqlServerName), + new Parameter(sqlServerDatabaseName), + appUserPasswordParam, + sqlAdminPasswordParam); } } } From 60e0dd08cfac96f104d9056bc3d817a00b7deaff Mon Sep 17 00:00:00 2001 From: jolov Date: Fri, 23 Feb 2024 11:10:25 -0800 Subject: [PATCH 2/3] remove unnecessary parm --- .../api/Azure.Provisioning.net6.0.cs | 2 +- .../api/Azure.Provisioning.netstandard2.0.cs | 2 +- .../Azure.Provisioning/src/ResourceOfT.cs | 2 +- .../src/resources/DeploymentScript.cs | 12 ++++------- .../rg_TEST_module/rg_TEST_module.bicep | 8 +++---- .../rg_TEST_module/rg_TEST_module.bicep | 8 +++---- .../Infrastructure/WebSiteUsingL1/main.bicep | 1 - .../rg_TEST_module/rg_TEST_module.bicep | 7 +++---- .../Infrastructure/WebSiteUsingL2/main.bicep | 1 - .../rg_TEST_module/rg_TEST_module.bicep | 7 +++---- .../Infrastructure/WebSiteUsingL3/main.bicep | 1 + .../rg_TEST_module/rg_TEST_module.bicep | 21 ++++++++++--------- .../tests/ProvisioningTests.cs | 3 --- .../tests/TestCommonSqlDatabase.cs | 2 -- 14 files changed, 33 insertions(+), 44 deletions(-) diff --git a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs index 584053aa2395b..00ba815212072 100644 --- a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs +++ b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs @@ -194,7 +194,7 @@ namespace Azure.Provisioning.Resources { public partial class DeploymentScript : Azure.Provisioning.Resource { - public DeploymentScript(Azure.Provisioning.IConstruct scope, string resourceName, Azure.Provisioning.Resource database, Azure.Provisioning.Parameter appUserPasswordSecret, Azure.Provisioning.Parameter sqlAdminPasswordSecret, string version = "2020-10-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } + public DeploymentScript(Azure.Provisioning.IConstruct scope, string resourceName, Azure.Provisioning.Resource database, Azure.Provisioning.Parameter databaseServerName, Azure.Provisioning.Parameter appUserPasswordSecret, Azure.Provisioning.Parameter sqlAdminPasswordSecret, string version = "2020-10-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } public DeploymentScript(Azure.Provisioning.IConstruct scope, string resourceName, System.Collections.Generic.IEnumerable scriptEnvironmentVariables, string scriptContent, string version = "2020-10-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; } } diff --git a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs index 584053aa2395b..00ba815212072 100644 --- a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs +++ b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs @@ -194,7 +194,7 @@ namespace Azure.Provisioning.Resources { public partial class DeploymentScript : Azure.Provisioning.Resource { - public DeploymentScript(Azure.Provisioning.IConstruct scope, string resourceName, Azure.Provisioning.Resource database, Azure.Provisioning.Parameter appUserPasswordSecret, Azure.Provisioning.Parameter sqlAdminPasswordSecret, string version = "2020-10-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } + public DeploymentScript(Azure.Provisioning.IConstruct scope, string resourceName, Azure.Provisioning.Resource database, Azure.Provisioning.Parameter databaseServerName, Azure.Provisioning.Parameter appUserPasswordSecret, Azure.Provisioning.Parameter sqlAdminPasswordSecret, string version = "2020-10-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } public DeploymentScript(Azure.Provisioning.IConstruct scope, string resourceName, System.Collections.Generic.IEnumerable scriptEnvironmentVariables, string scriptContent, string version = "2020-10-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; } } diff --git a/sdk/provisioning/Azure.Provisioning/src/ResourceOfT.cs b/sdk/provisioning/Azure.Provisioning/src/ResourceOfT.cs index 13d211ebeae77..63843e1f5a888 100644 --- a/sdk/provisioning/Azure.Provisioning/src/ResourceOfT.cs +++ b/sdk/provisioning/Azure.Provisioning/src/ResourceOfT.cs @@ -29,7 +29,7 @@ public abstract class Resource : Resource /// /// The scope. /// The parent. - /// The resouce name. + /// The resource name. /// The resourceType. /// The version. /// Lambda to create the ARM properties. diff --git a/sdk/provisioning/Azure.Provisioning/src/resources/DeploymentScript.cs b/sdk/provisioning/Azure.Provisioning/src/resources/DeploymentScript.cs index f9b96d6b2b2cf..3fb2d0ed165de 100644 --- a/sdk/provisioning/Azure.Provisioning/src/resources/DeploymentScript.cs +++ b/sdk/provisioning/Azure.Provisioning/src/resources/DeploymentScript.cs @@ -47,13 +47,12 @@ public DeploymentScript(IConstruct scope, string resourceName, IEnumerableThe scope. /// The resource name. /// The database. - /// The database name. /// The database server name. /// The app user password secret. /// The sql admin password secret. /// The resource version. /// The resource location. - public DeploymentScript(IConstruct scope, string resourceName, Resource database, Parameter databaseName, Parameter databaseServerName, Parameter appUserPasswordSecret, Parameter sqlAdminPasswordSecret, string version = _defaultVersion, AzureLocation? location = default) + public DeploymentScript(IConstruct scope, string resourceName, Resource database, Parameter databaseServerName, Parameter appUserPasswordSecret, Parameter sqlAdminPasswordSecret, string version = _defaultVersion, AzureLocation? location = default) : base(scope, null, resourceName, ResourceTypeName, version, (name) => ArmResourcesModelFactory.AzureCliScript( name: name, resourceType: ResourceTypeName, @@ -66,8 +65,8 @@ public DeploymentScript(IConstruct scope, string resourceName, Resource database { new ScriptEnvironmentVariable("APPUSERPASSWORD"), new ScriptEnvironmentVariable("SQLCMDPASSWORD"), - new ScriptEnvironmentVariable("DBNAME") { Value = $"_p_.{database.Name}.name" }, - new ScriptEnvironmentVariable("DBSERVER") { Value = $"_p_.{database.Parent!.Name}.properties.fullyQualifiedDomainName" }, + new ScriptEnvironmentVariable("DBSERVER"), + new ScriptEnvironmentVariable("DBNAME") { Value = database.Id.Name }, new ScriptEnvironmentVariable("APPUSERNAME") { Value = "appUser" }, new ScriptEnvironmentVariable("SQLADMIN") { Value = "sqlAdmin" }, }, @@ -89,10 +88,7 @@ alter role db_owner add member ${APPUSERNAME} { AssignParameter(data => data.EnvironmentVariables[0].SecureValue, appUserPasswordSecret); AssignParameter(data => data.EnvironmentVariables[1].SecureValue, sqlAdminPasswordSecret); - AssignParameter(data => data.EnvironmentVariables[2].Value, databaseName); - AssignParameter(data => data.EnvironmentVariables[3].Value, databaseServerName); - Scope.AddParameter(appUserPasswordSecret); - Scope.AddParameter(sqlAdminPasswordSecret); + AssignParameter(data => data.EnvironmentVariables[2].Value, databaseServerName); } /// diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST_module/rg_TEST_module.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST_module/rg_TEST_module.bicep index 78b54985f9094..b477f7da0d2d9 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST_module/rg_TEST_module.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/resources/rg_TEST_module/rg_TEST_module.bicep @@ -1,6 +1,6 @@ -resource storageAccount_qoZyLiiYO 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoacctfadf2ed2a58d43c' +resource storageAccount_9Dvxxgn8O 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoacct58eee912f50347d' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_qoZyLiiYO 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_8zCl9jaMv 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_qoZyLiiYO +resource blobService_zJM6Ics0G 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_9Dvxxgn8O name: 'default' properties: { } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST_module/rg_TEST_module.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST_module/rg_TEST_module.bicep index 8dbe8551097ea..f651acb0493f6 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST_module/rg_TEST_module.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/resources/rg_TEST_module/rg_TEST_module.bicep @@ -1,6 +1,6 @@ -resource storageAccount_AWAf1i775 'Microsoft.Storage/storageAccounts@2022-09-01' = { - name: 'photoacct03a34cbffeba423' +resource storageAccount_96H1GOZhY 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: 'photoacct3d08551686934f0' location: 'westus' sku: { name: 'Premium_LRS' @@ -10,8 +10,8 @@ resource storageAccount_AWAf1i775 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_hbrFFOTsM 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_AWAf1i775 +resource blobService_lUTdsAAld 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_96H1GOZhY name: 'default' properties: { deleteRetentionPolicy: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep index 97e115f7e558f..b1ada50460d66 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep @@ -30,4 +30,3 @@ module rg_TEST_module './resources/rg_TEST_module/rg_TEST_module.bicep' = { output SERVICE_API_IDENTITY_PRINCIPAL_ID string = rg_TEST_module.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID output vaultUri string = rg_TEST_module.outputs.vaultUri output sqlServerName string = rg_TEST_module.outputs.sqlServerName -output sqlServerDatabaseName string = rg_TEST_module.outputs.sqlServerDatabaseName diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST_module/rg_TEST_module.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST_module/rg_TEST_module.bicep index 907520e47fee1..8e8e096e12f2d 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST_module/rg_TEST_module.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/resources/rg_TEST_module/rg_TEST_module.bicep @@ -184,12 +184,12 @@ SCRIPT_END secureValue: sqlAdminPassword } { - name: 'DBNAME' + name: 'DBSERVER' value: sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName } { - name: 'DBSERVER' - value: sqlDatabase_U7NzorRJT.name + name: 'DBNAME' + value: 'db-TEST' } { name: 'APPUSERNAME' @@ -241,4 +241,3 @@ resource applicationSettingsResource_vEe46o8Zn 'Microsoft.Web/sites/config@2021- output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_W5EweSXEq.identity.principalId output vaultUri string = keyVault_CRoMbemLF.properties.vaultUri output sqlServerName string = sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName -output sqlServerDatabaseName string = sqlDatabase_U7NzorRJT.name diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep index 3439a97a8d279..46851b7fa8647 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep @@ -29,5 +29,4 @@ module rg_TEST_module './resources/rg_TEST_module/rg_TEST_module.bicep' = { output SERVICE_API_IDENTITY_PRINCIPAL_ID string = rg_TEST_module.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID output sqlServerName string = rg_TEST_module.outputs.sqlServerName -output sqlServerDatabaseName string = rg_TEST_module.outputs.sqlServerDatabaseName output vaultUri string = rg_TEST_module.outputs.vaultUri diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST_module/rg_TEST_module.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST_module/rg_TEST_module.bicep index d3f306911d50b..a51f6d87cad7e 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST_module/rg_TEST_module.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/rg_TEST_module/rg_TEST_module.bicep @@ -184,12 +184,12 @@ SCRIPT_END secureValue: sqlAdminPassword } { - name: 'DBNAME' + name: 'DBSERVER' value: sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName } { - name: 'DBSERVER' - value: sqlDatabase_U7NzorRJT.name + name: 'DBNAME' + value: 'db-TEST' } { name: 'APPUSERNAME' @@ -240,5 +240,4 @@ resource applicationSettingsResource_vEe46o8Zn 'Microsoft.Web/sites/config@2021- output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_W5EweSXEq.identity.principalId output sqlServerName string = sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName -output sqlServerDatabaseName string = sqlDatabase_U7NzorRJT.name output vaultUri string = keyVault_CRoMbemLF.properties.vaultUri diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep index 37563c6295b4f..bfadd18f8ff68 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/main.bicep @@ -29,3 +29,4 @@ module rg_TEST_module './resources/rg_TEST_module/rg_TEST_module.bicep' = { output vaultUri string = rg_TEST_module.outputs.vaultUri output SERVICE_API_IDENTITY_PRINCIPAL_ID string = rg_TEST_module.outputs.SERVICE_API_IDENTITY_PRINCIPAL_ID +output sqlServerName string = rg_TEST_module.outputs.sqlServerName diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST_module/rg_TEST_module.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST_module/rg_TEST_module.bicep index 0a06ea2fd14d5..8acaae87f7e19 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST_module/rg_TEST_module.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/rg_TEST_module/rg_TEST_module.bicep @@ -178,25 +178,25 @@ go SCRIPT_END ./sqlcmd -S ${DBSERVER} -d ${DBNAME} -U ${SQLADMIN} -i ./initDb.sql''' environmentVariables: [ - { - name: 'APPUSERNAME' - value: 'appUser' - } { name: 'APPUSERPASSWORD' - secureValue: '_p_.appUserPassword' + secureValue: appUserPassword } { - name: 'DBNAME' - value: '_p_.sqlDatabase_U7NzorRJT.name' + name: 'SQLCMDPASSWORD' + secureValue: sqlAdminPassword } { name: 'DBSERVER' - value: '_p_.sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName' + value: sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName } { - name: 'SQLCMDPASSWORD' - secureValue: '_p_.sqlAdminPassword' + name: 'DBNAME' + value: 'db-TEST' + } + { + name: 'APPUSERNAME' + value: 'appUser' } { name: 'SQLADMIN' @@ -243,3 +243,4 @@ resource applicationSettingsResource_vEe46o8Zn 'Microsoft.Web/sites/config@2021- output vaultUri string = keyVault_CRoMbemLF.properties.vaultUri output SERVICE_API_IDENTITY_PRINCIPAL_ID string = webSite_W5EweSXEq.identity.principalId +output sqlServerName string = sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName diff --git a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs index b0aa9cf0abb02..6a99b7afb9498 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs +++ b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs @@ -64,8 +64,6 @@ public async Task WebSiteUsingL1() SqlDatabase sqlDatabase = new SqlDatabase(infra, sqlServer); - Output sqlServerDatabaseName = sqlDatabase.AddOutput(db => db.Name, "sqlServerDatabaseName"); - KeyVaultSecret sqlAzureConnectionStringSecret = new KeyVaultSecret(infra, "connectionString", sqlDatabase.GetConnectionString(appUserPasswordParam)); SqlFirewallRule sqlFirewallRule = new SqlFirewallRule(infra, "firewallRule"); @@ -75,7 +73,6 @@ public async Task WebSiteUsingL1() "cliScript", sqlDatabase, new Parameter(sqlServerName), - new Parameter(sqlServerDatabaseName), appUserPasswordParam, sqlAdminPasswordParam); diff --git a/sdk/provisioning/Azure.Provisioning/tests/TestCommonSqlDatabase.cs b/sdk/provisioning/Azure.Provisioning/tests/TestCommonSqlDatabase.cs index 5892bea38d82e..41d0254181b29 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/TestCommonSqlDatabase.cs +++ b/sdk/provisioning/Azure.Provisioning/tests/TestCommonSqlDatabase.cs @@ -38,7 +38,6 @@ public TestCommonSqlDatabase(IConstruct scope, KeyVault? keyVault = null) Output sqlServerName = sqlServer.AddOutput(sql => sql.FullyQualifiedDomainName, "sqlServerName"); SqlDatabase = new SqlDatabase(this, sqlServer); - Output sqlServerDatabaseName = SqlDatabase.AddOutput(db => db.Name, "sqlServerDatabaseName"); KeyVaultSecret sqlAzureConnectionStringSecret = new KeyVaultSecret(this, "connectionString", SqlDatabase.GetConnectionString(appUserPasswordParam)); @@ -49,7 +48,6 @@ public TestCommonSqlDatabase(IConstruct scope, KeyVault? keyVault = null) "cliScript", SqlDatabase, new Parameter(sqlServerName), - new Parameter(sqlServerDatabaseName), appUserPasswordParam, sqlAdminPasswordParam); } From 1915bfb7dc6e56b5db6ac7c45d935b0d28c95911 Mon Sep 17 00:00:00 2001 From: jolov Date: Fri, 23 Feb 2024 11:11:52 -0800 Subject: [PATCH 3/3] remove using --- .../Azure.Provisioning/src/resources/DeploymentScript.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/provisioning/Azure.Provisioning/src/resources/DeploymentScript.cs b/sdk/provisioning/Azure.Provisioning/src/resources/DeploymentScript.cs index 3fb2d0ed165de..9ce354e772ddb 100644 --- a/sdk/provisioning/Azure.Provisioning/src/resources/DeploymentScript.cs +++ b/sdk/provisioning/Azure.Provisioning/src/resources/DeploymentScript.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Linq; using Azure.Core; using Azure.Provisioning.ResourceManager; using Azure.ResourceManager.Resources.Models;