Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deploymentscript #42166

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ namespace Azure.Provisioning.Resources
{
public partial class DeploymentScript : Azure.Provisioning.Resource<Azure.ResourceManager.Resources.Models.AzureCliScript>
{
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<string, Azure.ResourceManager.Resources.Models.AzureCliScript>)) { }
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<string, Azure.ResourceManager.Resources.Models.AzureCliScript>)) { }
public DeploymentScript(Azure.Provisioning.IConstruct scope, string resourceName, System.Collections.Generic.IEnumerable<Azure.ResourceManager.Resources.Models.ScriptEnvironmentVariable> 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<string, Azure.ResourceManager.Resources.Models.AzureCliScript>)) { }
protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ namespace Azure.Provisioning.Resources
{
public partial class DeploymentScript : Azure.Provisioning.Resource<Azure.ResourceManager.Resources.Models.AzureCliScript>
{
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<string, Azure.ResourceManager.Resources.Models.AzureCliScript>)) { }
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<string, Azure.ResourceManager.Resources.Models.AzureCliScript>)) { }
public DeploymentScript(Azure.Provisioning.IConstruct scope, string resourceName, System.Collections.Generic.IEnumerable<Azure.ResourceManager.Resources.Models.ScriptEnvironmentVariable> 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<string, Azure.ResourceManager.Resources.Models.AzureCliScript>)) { }
protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; }
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/provisioning/Azure.Provisioning/src/ResourceOfT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public abstract class Resource<T> : Resource
/// </summary>
/// <param name="scope">The scope.</param>
/// <param name="parent">The parent.</param>
/// <param name="resourceName">The resouce name.</param>
/// <param name="resourceName">The resource name.</param>
/// <param name="resourceType">The resourceType.</param>
/// <param name="version">The version.</param>
/// <param name="createProperties">Lambda to create the ARM properties.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ public DeploymentScript(IConstruct scope, string resourceName, IEnumerable<Scrip
/// <param name="scope">The scope.</param>
/// <param name="resourceName">The resource name.</param>
/// <param name="database">The database.</param>
/// <param name="databaseServerName">The database server name.</param>
/// <param name="appUserPasswordSecret">The app user password secret.</param>
/// <param name="sqlAdminPasswordSecret">The sql admin password secret.</param>
/// <param name="version">The resource version.</param>
/// <param name="location">The resource location.</param>
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 databaseServerName, Parameter appUserPasswordSecret, Parameter sqlAdminPasswordSecret, string version = _defaultVersion, AzureLocation? location = default)
: base(scope, null, resourceName, ResourceTypeName, version, (name) => ArmResourcesModelFactory.AzureCliScript(
name: name,
resourceType: ResourceTypeName,
Expand All @@ -61,11 +62,11 @@ public DeploymentScript(IConstruct scope, string resourceName, Resource database
cleanupPreference: ScriptCleanupOptions.OnSuccess,
environmentVariables: new List<ScriptEnvironmentVariable>
{
new ScriptEnvironmentVariable("APPUSERPASSWORD"),
new ScriptEnvironmentVariable("SQLCMDPASSWORD"),
new ScriptEnvironmentVariable("DBSERVER"),
new ScriptEnvironmentVariable("DBNAME") { Value = database.Id.Name },
JoshLove-msft marked this conversation as resolved.
Show resolved Hide resolved
new ScriptEnvironmentVariable("APPUSERNAME") { Value = "appUser" },
new ScriptEnvironmentVariable("APPUSERPASSWORD") { SecureValue = $"_p_.{appUserPasswordSecret.Name}" },
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("SQLADMIN") { Value = "sqlAdmin" },
},
scriptContent: """
Expand All @@ -84,8 +85,9 @@ alter role db_owner add member ${APPUSERNAME}
./sqlcmd -S ${DBSERVER} -d ${DBNAME} -U ${SQLADMIN} -i ./initDb.sql
"""))
{
Scope.AddParameter(appUserPasswordSecret);
Scope.AddParameter(sqlAdminPasswordSecret);
AssignParameter(data => data.EnvironmentVariables[0].SecureValue, appUserPasswordSecret);
AssignParameter(data => data.EnvironmentVariables[1].SecureValue, sqlAdminPasswordSecret);
AssignParameter(data => data.EnvironmentVariables[2].Value, databaseServerName);
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

resource storageAccount_nyqKj4fVa 'Microsoft.Storage/storageAccounts@2022-09-01' = {
name: 'photoacct783bf4edd65646e'
resource storageAccount_9Dvxxgn8O 'Microsoft.Storage/storageAccounts@2022-09-01' = {
name: 'photoacct58eee912f50347d'
location: 'westus'
sku: {
name: 'Premium_LRS'
Expand All @@ -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_zJM6Ics0G 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = {
parent: storageAccount_9Dvxxgn8O
name: 'default'
properties: {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

resource storageAccount_PdjzkDDBx 'Microsoft.Storage/storageAccounts@2022-09-01' = {
name: 'photoacct1434f94e82d1418'
resource storageAccount_96H1GOZhY 'Microsoft.Storage/storageAccounts@2022-09-01' = {
name: 'photoacct3d08551686934f0'
location: 'westus'
sku: {
name: 'Premium_LRS'
Expand All @@ -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_lUTdsAAld 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = {
parent: storageAccount_96H1GOZhY
name: 'default'
properties: {
deleteRetentionPolicy: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +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 vaultUri string = rg_TEST_module.outputs.vaultUri
output sqlServerName string = rg_TEST_module.outputs.sqlServerName
Original file line number Diff line number Diff line change
Expand Up @@ -175,25 +175,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'
Expand Down Expand Up @@ -240,3 +240,4 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,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 sqlServerName string = rg_TEST_module.outputs.sqlServerName
output vaultUri string = rg_TEST_module.outputs.vaultUri
Original file line number Diff line number Diff line change
Expand Up @@ -175,25 +175,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'
Expand Down Expand Up @@ -239,4 +239,5 @@ 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 vaultUri string = keyVault_CRoMbemLF.properties.vaultUri
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
11 changes: 9 additions & 2 deletions sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,21 @@ 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);

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),
appUserPasswordParam,
sqlAdminPasswordParam);

WebSite backEnd = new WebSite(infra, "backEnd", appServicePlan, WebSiteRuntime.Dotnetcore, "6.0");

Expand Down
14 changes: 11 additions & 3 deletions sdk/provisioning/Azure.Provisioning/tests/TestCommonSqlDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,21 @@ 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);

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),
appUserPasswordParam,
sqlAdminPasswordParam);
}
}
}