From fbef263b3b27167f706b45371f01e44e7937e940 Mon Sep 17 00:00:00 2001 From: m-nash <64171366+m-nash@users.noreply.github.com> Date: Thu, 15 Feb 2024 10:14:35 -0800 Subject: [PATCH] enable naming rule overrides per resource (#42012) * add name rule override ability in resource * remove lang override * update api --- .../api/Azure.Provisioning.net6.0.cs | 43 ++++++++------- .../api/Azure.Provisioning.netstandard2.0.cs | 43 ++++++++------- .../Azure.Provisioning/src/Resource.cs | 55 ++++++++++++++++--- .../Azure.Provisioning/src/ResourceOfT.cs | 8 +-- .../src/keyvault/KeyVault.cs | 11 +--- .../src/keyvault/KeyVaultAddAccessPolicy.cs | 2 +- .../src/keyvault/KeyVaultSecret.cs | 14 ++--- .../src/resourcemanager/ResourceGroup.cs | 8 +-- .../src/resourcemanager/Subscription.cs | 16 ++++-- .../src/resourcemanager/Tenant.cs | 12 ++-- .../src/resources/DeploymentScript.cs | 10 ++-- .../src/sqlmanagement/SqlDatabase.cs | 8 +-- .../src/sqlmanagement/SqlFirewallRule.cs | 8 +-- .../src/sqlmanagement/SqlServer.cs | 8 +-- .../src/storage/BlobService.cs | 9 +-- .../src/storage/StorageAccount.cs | 38 ++++++++++--- .../src/websites/AppServicePlan.cs | 6 +- .../websites/ApplicationSettingsResource.cs | 2 +- .../src/websites/WebSite.cs | 5 +- .../src/websites/WebSiteConfigLogs.cs | 9 +-- .../WebSitePublishingCredentialPolicy.cs | 6 +- .../StorageBlobDefaults/main.bicep | 8 +-- .../StorageBlobDropDown/main.bicep | 8 +-- .../Infrastructure/WebSiteUsingL1/main.bicep | 18 +++--- .../Infrastructure/WebSiteUsingL2/main.bicep | 2 +- .../TestBackEndWebSite.bicep | 2 +- .../TestCommonSqlDatabase.bicep | 12 ++-- .../TestFrontEndWebSite.bicep | 2 +- .../TestBackEndWebSite.bicep | 2 +- .../TestCommonSqlDatabase.bicep | 12 ++-- .../TestFrontEndWebSite.bicep | 2 +- .../TestWebSiteWithSqlBackEnd.bicep | 2 +- 32 files changed, 222 insertions(+), 169 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 e17598c7c2189..5094694d9e053 100644 --- a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs +++ b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs @@ -79,7 +79,7 @@ public readonly partial struct Parameter } public abstract partial class Resource : System.ClientModel.Primitives.IPersistableModel { - protected Resource(Azure.Provisioning.IConstruct scope, Azure.Provisioning.Resource? parent, string resourceName, Azure.Core.ResourceType resourceType, string version, object properties) { } + protected Resource(Azure.Provisioning.IConstruct scope, Azure.Provisioning.Resource? parent, string resourceName, Azure.Core.ResourceType resourceType, string version, System.Func createProperties) { } public Azure.Core.ResourceIdentifier Id { get { throw null; } } public string Name { get { throw null; } } public System.Collections.Generic.IList Parameters { get { throw null; } } @@ -87,13 +87,14 @@ protected Resource(Azure.Provisioning.IConstruct scope, Azure.Provisioning.Resou public Azure.Provisioning.IConstruct Scope { get { throw null; } } public string Version { get { throw null; } } protected virtual Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; } + protected virtual string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; } Azure.Provisioning.Resource System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } public abstract partial class Resource : Azure.Provisioning.Resource where T : notnull { - protected Resource(Azure.Provisioning.IConstruct scope, Azure.Provisioning.Resource? parent, string resourceName, Azure.Core.ResourceType resourceType, string version, T properties) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(object)) { } + protected Resource(Azure.Provisioning.IConstruct scope, Azure.Provisioning.Resource? parent, string resourceName, Azure.Core.ResourceType resourceType, string version, System.Func createProperties) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } public T Properties { get { throw null; } } public Azure.Provisioning.Output AddOutput(System.Linq.Expressions.Expression> propertySelector, string outputName, bool isLiteral = false, bool isSecure = false) { throw null; } public void AssignParameter(System.Linq.Expressions.Expression> propertySelector, Azure.Provisioning.Parameter parameter) { } @@ -103,7 +104,7 @@ namespace Azure.Provisioning.AppService { public partial class AppServicePlan : Azure.Provisioning.Resource { - public AppServicePlan(Azure.Provisioning.IConstruct scope, string resourceName, string version = "2021-02-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(Azure.ResourceManager.AppService.AppServicePlanData)) { } + public AppServicePlan(Azure.Provisioning.IConstruct scope, string resourceName, string version = "2021-02-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; } } public static partial class AppServicesExtensions @@ -112,7 +113,7 @@ public static partial class AppServicesExtensions } public partial class WebSite : Azure.Provisioning.Resource { - public WebSite(Azure.Provisioning.IConstruct scope, string resourceName, Azure.Provisioning.AppService.AppServicePlan appServicePlan, Azure.Provisioning.AppService.WebSiteRuntime runtime, string runtimeVersion, string version = "2021-02-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(Azure.ResourceManager.AppService.WebSiteData)) { } + public WebSite(Azure.Provisioning.IConstruct scope, string resourceName, Azure.Provisioning.AppService.AppServicePlan appServicePlan, Azure.Provisioning.AppService.WebSiteRuntime runtime, string runtimeVersion, string version = "2021-02-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 void AddApplicationSetting(string key, Azure.Provisioning.Parameter value) { } public void AddApplicationSetting(string key, string value) { } public void AddLogConfig(string resourceName) { } @@ -120,11 +121,12 @@ public void AddLogConfig(string resourceName) { } } public partial class WebSiteConfigLogs : Azure.Provisioning.Resource { - public WebSiteConfigLogs(Azure.Provisioning.IConstruct scope, string resourceName, Azure.Provisioning.AppService.WebSite? parent = null, string version = "2021-02-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(Azure.ResourceManager.AppService.SiteLogsConfigData)) { } + public WebSiteConfigLogs(Azure.Provisioning.IConstruct scope, string resourceName, Azure.Provisioning.AppService.WebSite? parent = null, string version = "2021-02-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 string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; } } public partial class WebSitePublishingCredentialPolicy : Azure.Provisioning.Resource { - public WebSitePublishingCredentialPolicy(Azure.Provisioning.IConstruct scope, string resourceName, string version = "2021-02-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(Azure.ResourceManager.AppService.CsmPublishingCredentialsPoliciesEntityData)) { } + public WebSitePublishingCredentialPolicy(Azure.Provisioning.IConstruct scope, string resourceName, string version = "2021-02-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 enum WebSiteRuntime { @@ -136,7 +138,7 @@ namespace Azure.Provisioning.KeyVaults { public partial class KeyVault : Azure.Provisioning.Resource { - public KeyVault(Azure.Provisioning.IConstruct scope, string? name = null, string version = "2023-02-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(Azure.ResourceManager.KeyVault.KeyVaultData)) { } + public KeyVault(Azure.Provisioning.IConstruct scope, string name = "kv", string version = "2023-02-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 void AddAccessPolicy(Azure.Provisioning.Output output) { } protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; } } @@ -147,8 +149,8 @@ public static partial class KeyVaultExtensions } public partial class KeyVaultSecret : Azure.Provisioning.Resource { - public KeyVaultSecret(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.Sql.ConnectionString connectionString, string version = "2023-02-01") : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(Azure.ResourceManager.KeyVault.KeyVaultSecretData)) { } - public KeyVaultSecret(Azure.Provisioning.IConstruct scope, string name, string version = "2023-02-01") : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(Azure.ResourceManager.KeyVault.KeyVaultSecretData)) { } + public KeyVaultSecret(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.Sql.ConnectionString connectionString, string version = "2023-02-01") : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } + public KeyVaultSecret(Azure.Provisioning.IConstruct scope, string name = "kvs", string version = "2023-02-01") : 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; } } } @@ -156,7 +158,7 @@ namespace Azure.Provisioning.ResourceManager { public partial class ResourceGroup : Azure.Provisioning.Resource { - public ResourceGroup(Azure.Provisioning.IConstruct scope, string? name = null, string version = "2023-07-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(Azure.ResourceManager.Resources.ResourceGroupData)) { } + public ResourceGroup(Azure.Provisioning.IConstruct scope, string name = "rg", string version = "2023-07-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; } } public static partial class ResourceManagerExtensions @@ -167,19 +169,21 @@ public static partial class ResourceManagerExtensions } public partial class Subscription : Azure.Provisioning.Resource { - public Subscription(Azure.Provisioning.IConstruct scope, System.Guid? guid = default(System.Guid?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(Azure.ResourceManager.Resources.SubscriptionData)) { } + public Subscription(Azure.Provisioning.IConstruct scope, System.Guid? guid = default(System.Guid?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } + protected override string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; } } public partial class Tenant : Azure.Provisioning.Resource { - public Tenant(Azure.Provisioning.IConstruct scope, System.Guid? tenantId = default(System.Guid?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(Azure.ResourceManager.Resources.TenantData)) { } + public Tenant(Azure.Provisioning.IConstruct scope, System.Guid? tenantId = default(System.Guid?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } + protected override string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; } } } 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(Azure.ResourceManager.Resources.Models.AzureCliScript)) { } - 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(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)) { } + 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; } } } @@ -192,18 +196,18 @@ public ConnectionString(Azure.Provisioning.Sql.SqlDatabase database, Azure.Provi } public partial class SqlDatabase : Azure.Provisioning.Resource { - public SqlDatabase(Azure.Provisioning.IConstruct scope, string? name = null, string version = "2022-08-01-preview", 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(Azure.ResourceManager.Sql.SqlDatabaseData)) { } + public SqlDatabase(Azure.Provisioning.IConstruct scope, string name = "db", string version = "2022-08-01-preview", 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; } public Azure.Provisioning.Sql.ConnectionString GetConnectionString(Azure.Provisioning.Parameter passwordSecret, string userName = "appUser") { throw null; } } public partial class SqlFirewallRule : Azure.Provisioning.Resource { - public SqlFirewallRule(Azure.Provisioning.IConstruct scope, string? name = null, string version = "2020-11-01-preview") : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(Azure.ResourceManager.Sql.SqlFirewallRuleData)) { } + public SqlFirewallRule(Azure.Provisioning.IConstruct scope, string name = "fw", string version = "2020-11-01-preview") : 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; } } public partial class SqlServer : Azure.Provisioning.Resource { - public SqlServer(Azure.Provisioning.IConstruct scope, string name, string? version = null, 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(Azure.ResourceManager.Sql.SqlServerData)) { } + public SqlServer(Azure.Provisioning.IConstruct scope, string name, string version = "2022-08-01-preview", 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; } } } @@ -211,13 +215,14 @@ namespace Azure.Provisioning.Storage { public partial class BlobService : Azure.Provisioning.Resource { - public BlobService(Azure.Provisioning.IConstruct scope, string name = "blob") : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(Azure.ResourceManager.Storage.BlobServiceData)) { } + public BlobService(Azure.Provisioning.IConstruct scope, string name = "blob") : 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; } } public partial class StorageAccount : Azure.Provisioning.Resource { - public StorageAccount(Azure.Provisioning.IConstruct scope, Azure.ResourceManager.Storage.Models.StorageKind kind, Azure.ResourceManager.Storage.Models.StorageSkuName sku, Azure.Provisioning.ResourceManager.ResourceGroup? parent = null, string name = "sa") : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(Azure.ResourceManager.Storage.StorageAccountData)) { } + public StorageAccount(Azure.Provisioning.IConstruct scope, Azure.ResourceManager.Storage.Models.StorageKind kind, Azure.ResourceManager.Storage.Models.StorageSkuName sku, Azure.Provisioning.ResourceManager.ResourceGroup? parent = null, string name = "sa") : 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; } + protected override string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; } } public static partial class StorageExtensions { 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 e17598c7c2189..5094694d9e053 100644 --- a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs +++ b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs @@ -79,7 +79,7 @@ public readonly partial struct Parameter } public abstract partial class Resource : System.ClientModel.Primitives.IPersistableModel { - protected Resource(Azure.Provisioning.IConstruct scope, Azure.Provisioning.Resource? parent, string resourceName, Azure.Core.ResourceType resourceType, string version, object properties) { } + protected Resource(Azure.Provisioning.IConstruct scope, Azure.Provisioning.Resource? parent, string resourceName, Azure.Core.ResourceType resourceType, string version, System.Func createProperties) { } public Azure.Core.ResourceIdentifier Id { get { throw null; } } public string Name { get { throw null; } } public System.Collections.Generic.IList Parameters { get { throw null; } } @@ -87,13 +87,14 @@ protected Resource(Azure.Provisioning.IConstruct scope, Azure.Provisioning.Resou public Azure.Provisioning.IConstruct Scope { get { throw null; } } public string Version { get { throw null; } } protected virtual Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; } + protected virtual string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; } Azure.Provisioning.Resource System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } public abstract partial class Resource : Azure.Provisioning.Resource where T : notnull { - protected Resource(Azure.Provisioning.IConstruct scope, Azure.Provisioning.Resource? parent, string resourceName, Azure.Core.ResourceType resourceType, string version, T properties) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(object)) { } + protected Resource(Azure.Provisioning.IConstruct scope, Azure.Provisioning.Resource? parent, string resourceName, Azure.Core.ResourceType resourceType, string version, System.Func createProperties) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } public T Properties { get { throw null; } } public Azure.Provisioning.Output AddOutput(System.Linq.Expressions.Expression> propertySelector, string outputName, bool isLiteral = false, bool isSecure = false) { throw null; } public void AssignParameter(System.Linq.Expressions.Expression> propertySelector, Azure.Provisioning.Parameter parameter) { } @@ -103,7 +104,7 @@ namespace Azure.Provisioning.AppService { public partial class AppServicePlan : Azure.Provisioning.Resource { - public AppServicePlan(Azure.Provisioning.IConstruct scope, string resourceName, string version = "2021-02-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(Azure.ResourceManager.AppService.AppServicePlanData)) { } + public AppServicePlan(Azure.Provisioning.IConstruct scope, string resourceName, string version = "2021-02-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; } } public static partial class AppServicesExtensions @@ -112,7 +113,7 @@ public static partial class AppServicesExtensions } public partial class WebSite : Azure.Provisioning.Resource { - public WebSite(Azure.Provisioning.IConstruct scope, string resourceName, Azure.Provisioning.AppService.AppServicePlan appServicePlan, Azure.Provisioning.AppService.WebSiteRuntime runtime, string runtimeVersion, string version = "2021-02-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(Azure.ResourceManager.AppService.WebSiteData)) { } + public WebSite(Azure.Provisioning.IConstruct scope, string resourceName, Azure.Provisioning.AppService.AppServicePlan appServicePlan, Azure.Provisioning.AppService.WebSiteRuntime runtime, string runtimeVersion, string version = "2021-02-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 void AddApplicationSetting(string key, Azure.Provisioning.Parameter value) { } public void AddApplicationSetting(string key, string value) { } public void AddLogConfig(string resourceName) { } @@ -120,11 +121,12 @@ public void AddLogConfig(string resourceName) { } } public partial class WebSiteConfigLogs : Azure.Provisioning.Resource { - public WebSiteConfigLogs(Azure.Provisioning.IConstruct scope, string resourceName, Azure.Provisioning.AppService.WebSite? parent = null, string version = "2021-02-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(Azure.ResourceManager.AppService.SiteLogsConfigData)) { } + public WebSiteConfigLogs(Azure.Provisioning.IConstruct scope, string resourceName, Azure.Provisioning.AppService.WebSite? parent = null, string version = "2021-02-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 string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; } } public partial class WebSitePublishingCredentialPolicy : Azure.Provisioning.Resource { - public WebSitePublishingCredentialPolicy(Azure.Provisioning.IConstruct scope, string resourceName, string version = "2021-02-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(Azure.ResourceManager.AppService.CsmPublishingCredentialsPoliciesEntityData)) { } + public WebSitePublishingCredentialPolicy(Azure.Provisioning.IConstruct scope, string resourceName, string version = "2021-02-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 enum WebSiteRuntime { @@ -136,7 +138,7 @@ namespace Azure.Provisioning.KeyVaults { public partial class KeyVault : Azure.Provisioning.Resource { - public KeyVault(Azure.Provisioning.IConstruct scope, string? name = null, string version = "2023-02-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(Azure.ResourceManager.KeyVault.KeyVaultData)) { } + public KeyVault(Azure.Provisioning.IConstruct scope, string name = "kv", string version = "2023-02-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 void AddAccessPolicy(Azure.Provisioning.Output output) { } protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; } } @@ -147,8 +149,8 @@ public static partial class KeyVaultExtensions } public partial class KeyVaultSecret : Azure.Provisioning.Resource { - public KeyVaultSecret(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.Sql.ConnectionString connectionString, string version = "2023-02-01") : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(Azure.ResourceManager.KeyVault.KeyVaultSecretData)) { } - public KeyVaultSecret(Azure.Provisioning.IConstruct scope, string name, string version = "2023-02-01") : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(Azure.ResourceManager.KeyVault.KeyVaultSecretData)) { } + public KeyVaultSecret(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.Sql.ConnectionString connectionString, string version = "2023-02-01") : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } + public KeyVaultSecret(Azure.Provisioning.IConstruct scope, string name = "kvs", string version = "2023-02-01") : 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; } } } @@ -156,7 +158,7 @@ namespace Azure.Provisioning.ResourceManager { public partial class ResourceGroup : Azure.Provisioning.Resource { - public ResourceGroup(Azure.Provisioning.IConstruct scope, string? name = null, string version = "2023-07-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(Azure.ResourceManager.Resources.ResourceGroupData)) { } + public ResourceGroup(Azure.Provisioning.IConstruct scope, string name = "rg", string version = "2023-07-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; } } public static partial class ResourceManagerExtensions @@ -167,19 +169,21 @@ public static partial class ResourceManagerExtensions } public partial class Subscription : Azure.Provisioning.Resource { - public Subscription(Azure.Provisioning.IConstruct scope, System.Guid? guid = default(System.Guid?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(Azure.ResourceManager.Resources.SubscriptionData)) { } + public Subscription(Azure.Provisioning.IConstruct scope, System.Guid? guid = default(System.Guid?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } + protected override string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; } } public partial class Tenant : Azure.Provisioning.Resource { - public Tenant(Azure.Provisioning.IConstruct scope, System.Guid? tenantId = default(System.Guid?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(Azure.ResourceManager.Resources.TenantData)) { } + public Tenant(Azure.Provisioning.IConstruct scope, System.Guid? tenantId = default(System.Guid?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func)) { } + protected override string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; } } } 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(Azure.ResourceManager.Resources.Models.AzureCliScript)) { } - 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(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)) { } + 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; } } } @@ -192,18 +196,18 @@ public ConnectionString(Azure.Provisioning.Sql.SqlDatabase database, Azure.Provi } public partial class SqlDatabase : Azure.Provisioning.Resource { - public SqlDatabase(Azure.Provisioning.IConstruct scope, string? name = null, string version = "2022-08-01-preview", 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(Azure.ResourceManager.Sql.SqlDatabaseData)) { } + public SqlDatabase(Azure.Provisioning.IConstruct scope, string name = "db", string version = "2022-08-01-preview", 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; } public Azure.Provisioning.Sql.ConnectionString GetConnectionString(Azure.Provisioning.Parameter passwordSecret, string userName = "appUser") { throw null; } } public partial class SqlFirewallRule : Azure.Provisioning.Resource { - public SqlFirewallRule(Azure.Provisioning.IConstruct scope, string? name = null, string version = "2020-11-01-preview") : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(Azure.ResourceManager.Sql.SqlFirewallRuleData)) { } + public SqlFirewallRule(Azure.Provisioning.IConstruct scope, string name = "fw", string version = "2020-11-01-preview") : 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; } } public partial class SqlServer : Azure.Provisioning.Resource { - public SqlServer(Azure.Provisioning.IConstruct scope, string name, string? version = null, 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(Azure.ResourceManager.Sql.SqlServerData)) { } + public SqlServer(Azure.Provisioning.IConstruct scope, string name, string version = "2022-08-01-preview", 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; } } } @@ -211,13 +215,14 @@ namespace Azure.Provisioning.Storage { public partial class BlobService : Azure.Provisioning.Resource { - public BlobService(Azure.Provisioning.IConstruct scope, string name = "blob") : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(Azure.ResourceManager.Storage.BlobServiceData)) { } + public BlobService(Azure.Provisioning.IConstruct scope, string name = "blob") : 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; } } public partial class StorageAccount : Azure.Provisioning.Resource { - public StorageAccount(Azure.Provisioning.IConstruct scope, Azure.ResourceManager.Storage.Models.StorageKind kind, Azure.ResourceManager.Storage.Models.StorageSkuName sku, Azure.Provisioning.ResourceManager.ResourceGroup? parent = null, string name = "sa") : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(Azure.ResourceManager.Storage.StorageAccountData)) { } + public StorageAccount(Azure.Provisioning.IConstruct scope, Azure.ResourceManager.Storage.Models.StorageKind kind, Azure.ResourceManager.Storage.Models.StorageSkuName sku, Azure.Provisioning.ResourceManager.ResourceGroup? parent = null, string name = "sa") : 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; } + protected override string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; } } public static partial class StorageExtensions { diff --git a/sdk/provisioning/Azure.Provisioning/src/Resource.cs b/sdk/provisioning/Azure.Provisioning/src/Resource.cs index 46752e606e107..2116dffad2e09 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Resource.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Resource.cs @@ -34,7 +34,7 @@ internal void AddDependency(Resource resource) /// Gets the parent . /// public Resource? Parent { get; } - private object Properties { get; } + private protected object ResourceData { get; } /// /// Gets the version of the resource. /// @@ -67,25 +67,64 @@ internal void AddDependency(Resource resource) /// The resource name. /// The resource type. /// The resource version. - /// The resource properties + /// Lambda to create the ARM properties. /// If is null. - protected Resource(IConstruct scope, Resource? parent, string resourceName, ResourceType resourceType, string version, object properties) + protected Resource(IConstruct scope, Resource? parent, string resourceName, ResourceType resourceType, string version, Func createProperties) { if (scope is null) throw new ArgumentNullException(nameof(scope)); + var azureName = GetAzureName(scope, resourceName); Scope = scope; Parameters = new List(); Parent = parent ?? FindParentInScope(scope); Scope.AddResource(this); - Properties = properties; + ResourceData = createProperties(azureName); Version = version; ParameterOverrides = new Dictionary>(); Dependencies = new List(); ResourceType = resourceType; - Id = Parent is null ? ResourceIdentifier.Root : Parent is ResourceGroup ? Parent.Id.AppendProviderResource(ResourceType.Namespace, ResourceType.GetLastType(), resourceName) : Parent.Id.AppendChildResource(ResourceType.GetLastType(), resourceName); + Id = Parent is null + ? ResourceIdentifier.Root + : Parent is ResourceGroup + ? Parent.Id.AppendProviderResource(ResourceType.Namespace, ResourceType.GetLastType(), azureName) + : Parent.Id.AppendChildResource(ResourceType.GetLastType(), azureName); Name = GetHash(); } + /// + /// Validate and sanitize the resource name. + /// + /// The scope. + /// The resource name. + /// Sanitized resource name. + /// If the resource name violates rules that cannot be sanitized. + protected virtual string GetAzureName(IConstruct scope, string resourceName) + { + var span = resourceName.AsSpan(); + if (!char.IsLetter(span[0])) + { + throw new ArgumentException("Resource name must start with a letter", nameof(resourceName)); + } + if (!char.IsLetterOrDigit(span[span.Length - 1])) + { + throw new ArgumentException("Resource name must end with a letter or digit", nameof(resourceName)); + } + StringBuilder stringBuilder = new StringBuilder(); + for (int i = 0; i < span.Length; i++) + { + char c = span[i]; + if (!char.IsLetterOrDigit(c) && c != '-') + { + continue; + } + stringBuilder.Append(c); + } + + stringBuilder.Append('-'); + stringBuilder.Append(scope.EnvironmentName); + return stringBuilder.ToString(0, Math.Min(stringBuilder.Length, 24)); + } + /// /// Finds the parent resource in the scope. /// @@ -127,10 +166,10 @@ private protected void AssignParameter(object instance, string propertyName, Par /// If the is not found on the resources properties. private protected Output AddOutput(string name, object instance, string propertyName, bool isLiteral = false, bool isSecure = false) { - string? reference = GetReference(instance.GetType(), Properties.GetType(), propertyName, Name.ToCamelCase()); + string? reference = GetReference(instance.GetType(), ResourceData.GetType(), propertyName, Name.ToCamelCase()); if (reference is null) - throw new ArgumentException(nameof(propertyName), $"{propertyName} was not found in the property tree for {Properties.GetType().Name}"); + throw new ArgumentException(nameof(propertyName), $"{propertyName} was not found in the property tree for {ResourceData.GetType().Name}"); var result = new Output(name, reference, Scope, isLiteral, isSecure); Scope.AddOutput(result); return result; @@ -197,7 +236,7 @@ private BinaryData SerializeModule(ModelReaderWriterOptions options) { bicepOptions.ParameterOverrides.Add(parameter.Key, parameter.Value); } - var data = ModelReaderWriter.Write(Properties, bicepOptions).ToMemory(); + var data = ModelReaderWriter.Write(ResourceData, bicepOptions).ToMemory(); #if NET6_0_OR_GREATER WriteLines(0, BinaryData.FromBytes(data[2..]), stream, this); diff --git a/sdk/provisioning/Azure.Provisioning/src/ResourceOfT.cs b/sdk/provisioning/Azure.Provisioning/src/ResourceOfT.cs index 33b12c1e177e7..cedfb4a7766df 100644 --- a/sdk/provisioning/Azure.Provisioning/src/ResourceOfT.cs +++ b/sdk/provisioning/Azure.Provisioning/src/ResourceOfT.cs @@ -31,11 +31,11 @@ public abstract class Resource : Resource /// The resouce name. /// The resourceType. /// The version. - /// The properites. - protected Resource(IConstruct scope, Resource? parent, string resourceName, ResourceType resourceType, string version, T properties) - : base(scope, parent, resourceName, resourceType, version, properties) + /// Lambda to create the ARM properties. + protected Resource(IConstruct scope, Resource? parent, string resourceName, ResourceType resourceType, string version, Func createProperties) + : base(scope, parent, resourceName, resourceType, version, (name) => createProperties(name)) { - Properties = properties; + Properties = (T)ResourceData; } /// diff --git a/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVault.cs b/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVault.cs index c18a95f4008b0..a9886757edfbc 100644 --- a/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVault.cs +++ b/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVault.cs @@ -24,9 +24,9 @@ public class KeyVault : Resource /// The name. /// The version. /// The location. - public KeyVault(IConstruct scope, string? name = null, string version = "2023-02-01", AzureLocation? location = default) - : base(scope, null, GetName(scope, name), ResourceTypeName, version, ArmKeyVaultModelFactory.KeyVaultData( - name: GetName(scope, name), + public KeyVault(IConstruct scope, string name = "kv", string version = "2023-02-01", AzureLocation? location = default) + : base(scope, null, name, ResourceTypeName, version, (name) => ArmKeyVaultModelFactory.KeyVaultData( + name: name, resourceType: ResourceTypeName, location: location ?? Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS, properties: ArmKeyVaultModelFactory.KeyVaultProperties( @@ -46,11 +46,6 @@ public KeyVault(IConstruct scope, string? name = null, string version = "2023-02 { } - private static string GetName(IConstruct scope, string? name) - { - return name is null ? $"kv-{scope.EnvironmentName}" : $"{name}-{scope.EnvironmentName}"; - } - /// /// Adds an access policy to the . /// diff --git a/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVaultAddAccessPolicy.cs b/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVaultAddAccessPolicy.cs index 31999e92eed64..7f9783eae90ed 100644 --- a/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVaultAddAccessPolicy.cs +++ b/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVaultAddAccessPolicy.cs @@ -13,7 +13,7 @@ internal class KeyVaultAddAccessPolicy : Resource ArmKeyVaultModelFactory.KeyVaultAccessPolicyParameters( name: "add", resourceType: ResourceTypeName, accessPolicies: new List diff --git a/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVaultSecret.cs b/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVaultSecret.cs index 5424eed7d8854..cf065dcc9d776 100644 --- a/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVaultSecret.cs +++ b/sdk/provisioning/Azure.Provisioning/src/keyvault/KeyVaultSecret.cs @@ -21,9 +21,9 @@ public class KeyVaultSecret : Resource /// The scope. /// The name. /// The version. - public KeyVaultSecret(IConstruct scope, string name, string version = "2023-02-01") - : base(scope, null, GetName(scope, name), ResourceTypeName, version, ArmKeyVaultModelFactory.KeyVaultSecretData( - name: GetName(scope, name), + public KeyVaultSecret(IConstruct scope, string name = "kvs", string version = "2023-02-01") + : base(scope, null, name, ResourceTypeName, version, (name) => ArmKeyVaultModelFactory.KeyVaultSecretData( + name: name, resourceType: ResourceTypeName, properties: ArmKeyVaultModelFactory.SecretProperties( value: Guid.Empty.ToString()) @@ -39,8 +39,8 @@ public KeyVaultSecret(IConstruct scope, string name, string version = "2023-02-0 /// The connection string. /// The version. public KeyVaultSecret(IConstruct scope, string name, ConnectionString connectionString, string version = "2023-02-01") - : base(scope, null, GetName(scope, name), ResourceTypeName, version, ArmKeyVaultModelFactory.KeyVaultSecretData( - name: GetName(scope, name), + : base(scope, null, name, ResourceTypeName, version, (name) => ArmKeyVaultModelFactory.KeyVaultSecretData( + name: name, resourceType: ResourceTypeName, properties: ArmKeyVaultModelFactory.SecretProperties( value: connectionString.Value) @@ -48,15 +48,13 @@ public KeyVaultSecret(IConstruct scope, string name, ConnectionString connection { } - private static string GetName(IConstruct scope, string? name) => name is null ? $"kvs-{scope.EnvironmentName}" : name; - /// protected override Resource? FindParentInScope(IConstruct scope) { var result = base.FindParentInScope(scope); if (result is null) { - result = scope.GetSingleResource() ?? new KeyVault(scope, "kv"); + result = scope.GetSingleResource() ?? new KeyVault(scope); } return result; } diff --git a/sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceGroup.cs b/sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceGroup.cs index 61b36e0f0130b..e14f4477a1e2b 100644 --- a/sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceGroup.cs +++ b/sdk/provisioning/Azure.Provisioning/src/resourcemanager/ResourceGroup.cs @@ -23,17 +23,15 @@ public class ResourceGroup : Resource /// The name of the resourceGroup. /// The version of the resourceGroup. /// The location of the resourceGroup. - public ResourceGroup(IConstruct scope, string? name = default, string version = "2023-07-01", AzureLocation? location = default) - : base(scope, null, GetName(scope, name), ResourceType, version, ResourceManagerModelFactory.ResourceGroupData( - name: GetName(scope, name), + public ResourceGroup(IConstruct scope, string name = "rg", string version = "2023-07-01", AzureLocation? location = default) + : base(scope, null, name, ResourceType, version, (name) => ResourceManagerModelFactory.ResourceGroupData( + name: name, resourceType: ResourceType, tags: new Dictionary { { "azd-env-name", scope.EnvironmentName } }, location: location ?? Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS)) { } - private static string GetName(IConstruct scope, string? name) => name is null ? $"rg-{scope.EnvironmentName}" : $"{name}-{scope.EnvironmentName}"; - /// protected override Resource? FindParentInScope(IConstruct scope) { diff --git a/sdk/provisioning/Azure.Provisioning/src/resourcemanager/Subscription.cs b/sdk/provisioning/Azure.Provisioning/src/resourcemanager/Subscription.cs index 70175f19b4af3..0049e8b5585fb 100644 --- a/sdk/provisioning/Azure.Provisioning/src/resourcemanager/Subscription.cs +++ b/sdk/provisioning/Azure.Provisioning/src/resourcemanager/Subscription.cs @@ -17,8 +17,6 @@ public class Subscription : Resource { internal static readonly ResourceType ResourceType = "Microsoft.Resources/subscriptions"; - private static string GetName(Guid? guid) => guid.HasValue ? guid.Value.ToString() : Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID") ?? throw new InvalidOperationException("No environment variable named 'AZURE_SUBSCRIPTION_ID' found"); - /// /// Initializes a new instance of the . /// @@ -28,14 +26,20 @@ public Subscription(IConstruct scope, Guid? guid = default) : base( scope, scope.Root, - GetName(guid), + guid?.ToString()!, ResourceType, "2022-12-01", - ResourceManagerModelFactory.SubscriptionData( - id: SubscriptionResource.CreateResourceIdentifier(GetName(guid)), - subscriptionId: GetName(guid), + (name) => ResourceManagerModelFactory.SubscriptionData( + id: SubscriptionResource.CreateResourceIdentifier(name), + subscriptionId: name, tenantId: scope.Root.Properties.TenantId)) { } + + /// + protected override string GetAzureName(IConstruct scope, string resourceName) + { + return resourceName is not null ? resourceName : Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID") ?? throw new InvalidOperationException("No environment variable named 'AZURE_SUBSCRIPTION_ID' found"); + } } } diff --git a/sdk/provisioning/Azure.Provisioning/src/resourcemanager/Tenant.cs b/sdk/provisioning/Azure.Provisioning/src/resourcemanager/Tenant.cs index 9ee5996b7c637..35658a0754908 100644 --- a/sdk/provisioning/Azure.Provisioning/src/resourcemanager/Tenant.cs +++ b/sdk/provisioning/Azure.Provisioning/src/resourcemanager/Tenant.cs @@ -16,17 +16,21 @@ public class Tenant : Resource { private const string ResourceTypeName = "Microsoft.Resources/tenants"; - private static string GetName() => Environment.GetEnvironmentVariable("AZURE_TENANT_ID") ?? throw new InvalidOperationException("No environment variable named 'AZURE_TENANT_ID' found"); - /// /// Initializes a new instance of the . /// /// The scope the tenant belongs to. /// The tenant id. public Tenant(IConstruct scope, Guid? tenantId = null) - : base(scope, null, tenantId.HasValue ? tenantId.Value.ToString() : GetName(), ResourceTypeName, "2022-12-01", ResourceManagerModelFactory.TenantData( - tenantId: tenantId.HasValue ? tenantId.Value : Guid.Parse(GetName()))) + : base(scope, null, tenantId?.ToString()!, ResourceTypeName, "2022-12-01", (name) => ResourceManagerModelFactory.TenantData( + tenantId: tenantId.HasValue ? tenantId.Value : Guid.Parse(name))) + { + } + + /// + protected override string GetAzureName(IConstruct scope, string resourceName) { + return resourceName is not null ? resourceName : Environment.GetEnvironmentVariable("AZURE_TENANT_ID") ?? throw new InvalidOperationException("No environment variable named 'AZURE_TENANT_ID' found"); } } } diff --git a/sdk/provisioning/Azure.Provisioning/src/resources/DeploymentScript.cs b/sdk/provisioning/Azure.Provisioning/src/resources/DeploymentScript.cs index 5fa087a2dbcc6..da50a9fb12606 100644 --- a/sdk/provisioning/Azure.Provisioning/src/resources/DeploymentScript.cs +++ b/sdk/provisioning/Azure.Provisioning/src/resources/DeploymentScript.cs @@ -27,8 +27,8 @@ public class DeploymentScript : Resource /// The resource version. /// The resource location. public DeploymentScript(IConstruct scope, string resourceName, IEnumerable scriptEnvironmentVariables, string scriptContent, string version = _defaultVersion, AzureLocation? location = default) - : base(scope, null, GetName(scope, resourceName), ResourceTypeName, version, ArmResourcesModelFactory.AzureCliScript( - name: GetName(scope, resourceName), + : base(scope, null, resourceName, ResourceTypeName, version, (name) => ArmResourcesModelFactory.AzureCliScript( + name: name, resourceType: ResourceTypeName, location: location ?? Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS, azCliVersion: "2.37.0", @@ -51,8 +51,8 @@ public DeploymentScript(IConstruct scope, string resourceName, IEnumerableThe resource version. /// The resource location. public DeploymentScript(IConstruct scope, string resourceName, Resource database, Parameter appUserPasswordSecret, Parameter sqlAdminPasswordSecret, string version = _defaultVersion, AzureLocation? location = default) - : base(scope, null, GetName(scope, resourceName), ResourceTypeName, version, ArmResourcesModelFactory.AzureCliScript( - name: GetName(scope, resourceName), + : base(scope, null, resourceName, ResourceTypeName, version, (name) => ArmResourcesModelFactory.AzureCliScript( + name: name, resourceType: ResourceTypeName, location: location ?? Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS, azCliVersion: "2.37.0", @@ -88,8 +88,6 @@ alter role db_owner add member ${APPUSERNAME} Scope.AddParameter(sqlAdminPasswordSecret); } - private static string GetName(IConstruct scope, string? name) => name is null ? $"deploymentScript-{scope.EnvironmentName}" : $"{name}-{scope.EnvironmentName}"; - /// protected override Resource? FindParentInScope(IConstruct scope) { diff --git a/sdk/provisioning/Azure.Provisioning/src/sqlmanagement/SqlDatabase.cs b/sdk/provisioning/Azure.Provisioning/src/sqlmanagement/SqlDatabase.cs index 46f6a5f4d51af..44610b4b7f011 100644 --- a/sdk/provisioning/Azure.Provisioning/src/sqlmanagement/SqlDatabase.cs +++ b/sdk/provisioning/Azure.Provisioning/src/sqlmanagement/SqlDatabase.cs @@ -22,9 +22,9 @@ public class SqlDatabase : Resource /// The name. /// The version. /// The location. - public SqlDatabase(IConstruct scope, string? name = default, string version = "2022-08-01-preview", AzureLocation? location = default) - : base(scope, null, GetName(scope, name), ResourceTypeName, version, ArmSqlModelFactory.SqlDatabaseData( - name: GetName(scope, name), + public SqlDatabase(IConstruct scope, string name = "db", string version = "2022-08-01-preview", AzureLocation? location = default) + : base(scope, null, name, ResourceTypeName, version, (name) => ArmSqlModelFactory.SqlDatabaseData( + name: name, resourceType: ResourceTypeName, location: location ?? Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS)) { @@ -39,8 +39,6 @@ public SqlDatabase(IConstruct scope, string? name = default, string version = "2 public ConnectionString GetConnectionString(Parameter passwordSecret, string userName = "appUser") => new ConnectionString(this, passwordSecret, userName); - private static string GetName(IConstruct scope, string? name) => name is null ? $"db-{scope.EnvironmentName}" : name; - /// protected override Resource? FindParentInScope(IConstruct scope) { diff --git a/sdk/provisioning/Azure.Provisioning/src/sqlmanagement/SqlFirewallRule.cs b/sdk/provisioning/Azure.Provisioning/src/sqlmanagement/SqlFirewallRule.cs index fed4b8b6b4a1c..7486b55cf2f79 100644 --- a/sdk/provisioning/Azure.Provisioning/src/sqlmanagement/SqlFirewallRule.cs +++ b/sdk/provisioning/Azure.Provisioning/src/sqlmanagement/SqlFirewallRule.cs @@ -19,9 +19,9 @@ public class SqlFirewallRule : Resource /// The scope. /// The name. /// The version. - public SqlFirewallRule(IConstruct scope, string? name = default, string version = "2020-11-01-preview") - : base(scope, null, GetName(scope, name), ResourceTypeName, version, ArmSqlModelFactory.SqlFirewallRuleData( - name: GetName(scope, name), + public SqlFirewallRule(IConstruct scope, string name = "fw", string version = "2020-11-01-preview") + : base(scope, null, name, ResourceTypeName, version, (name) => ArmSqlModelFactory.SqlFirewallRuleData( + name: name, resourceType: ResourceTypeName, startIPAddress: "0.0.0.1", endIPAddress: "255.255.255.254" @@ -29,8 +29,6 @@ public SqlFirewallRule(IConstruct scope, string? name = default, string version { } - private static string GetName(IConstruct scope, string? name) => name is null ? $"fw-{scope.EnvironmentName}" : $"{name}-{scope.EnvironmentName}"; - /// protected override Resource? FindParentInScope(IConstruct scope) { diff --git a/sdk/provisioning/Azure.Provisioning/src/sqlmanagement/SqlServer.cs b/sdk/provisioning/Azure.Provisioning/src/sqlmanagement/SqlServer.cs index d81db47b618fa..1e3117793dedc 100644 --- a/sdk/provisioning/Azure.Provisioning/src/sqlmanagement/SqlServer.cs +++ b/sdk/provisioning/Azure.Provisioning/src/sqlmanagement/SqlServer.cs @@ -23,9 +23,9 @@ public class SqlServer : Resource /// The name. /// The version. /// The location. - public SqlServer(IConstruct scope, string name, string? version = default, AzureLocation? location = default) - : base(scope, null, GetName(scope, name), ResourceTypeName, version ?? "2022-08-01-preview", ArmSqlModelFactory.SqlServerData( - name: GetName(scope, name), + public SqlServer(IConstruct scope, string name, string version = "2022-08-01-preview", AzureLocation? location = default) + : base(scope, null, name, ResourceTypeName, version, (name) => ArmSqlModelFactory.SqlServerData( + name: name, location: location ?? Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS, resourceType: ResourceTypeName, version: "12.0", @@ -36,8 +36,6 @@ public SqlServer(IConstruct scope, string name, string? version = default, Azure { } - private static string GetName(IConstruct scope, string? name) => name is null ? $"sql-{scope.EnvironmentName}" : $"{name}-{scope.EnvironmentName}"; - /// protected override Resource? FindParentInScope(IConstruct scope) { diff --git a/sdk/provisioning/Azure.Provisioning/src/storage/BlobService.cs b/sdk/provisioning/Azure.Provisioning/src/storage/BlobService.cs index 366e9149f066b..1a80472a628ad 100644 --- a/sdk/provisioning/Azure.Provisioning/src/storage/BlobService.cs +++ b/sdk/provisioning/Azure.Provisioning/src/storage/BlobService.cs @@ -13,19 +13,14 @@ public class BlobService : Resource { private const string ResourceTypeName = "Microsoft.Storage/storageAccounts/blobServices"; - private static string GetName(IConstruct scope, string? name) - { - return $"{name}-{scope.EnvironmentName}"; - } - /// /// Initializes a new instance of the . /// /// The scope. /// The name. public BlobService(IConstruct scope, string name = "blob") - : base(scope, null, GetName(scope, name), ResourceTypeName, "2022-09-01", ArmStorageModelFactory.BlobServiceData( - name: GetName(scope, name), + : base(scope, null, name, ResourceTypeName, "2022-09-01", (name) => ArmStorageModelFactory.BlobServiceData( + name: name, resourceType: ResourceTypeName)) { } diff --git a/sdk/provisioning/Azure.Provisioning/src/storage/StorageAccount.cs b/sdk/provisioning/Azure.Provisioning/src/storage/StorageAccount.cs index 446d27aef2ee0..1251924817d21 100644 --- a/sdk/provisioning/Azure.Provisioning/src/storage/StorageAccount.cs +++ b/sdk/provisioning/Azure.Provisioning/src/storage/StorageAccount.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.Text; using Azure.Core; using Azure.Provisioning.ResourceManager; using Azure.ResourceManager.Storage; @@ -16,12 +17,6 @@ public class StorageAccount : Resource { private const string ResourceTypeName = "Microsoft.Storage/storageAccounts"; - private static string GetName(IConstruct scope, string name) - { - var result = $"{name}-{Guid.NewGuid().ToString().Replace("-", "")}"; - return result.Substring(0, Math.Min(result.Length, 24)); - } - /// /// Initializes a new instance of the . /// @@ -31,8 +26,8 @@ private static string GetName(IConstruct scope, string name) /// The parent. /// The name. public StorageAccount(IConstruct scope, StorageKind kind, StorageSkuName sku, ResourceGroup? parent = null, string name = "sa") - : base(scope, parent, GetName(scope, name), ResourceTypeName, "2022-09-01", ArmStorageModelFactory.StorageAccountData( - name: GetName(scope, name), + : base(scope, parent, name, ResourceTypeName, "2022-09-01", (name) => ArmStorageModelFactory.StorageAccountData( + name: name, resourceType: ResourceTypeName, location: Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS, sku: new StorageSku(sku), @@ -50,5 +45,32 @@ public StorageAccount(IConstruct scope, StorageKind kind, StorageSkuName sku, Re } return result; } + + /// + protected override string GetAzureName(IConstruct scope, string resourceName) + { + var span = resourceName.AsSpan(); + StringBuilder stringBuilder = new StringBuilder(); + for (int i = 0; i < span.Length; i++) + { + char c = span[i]; + if (!char.IsLetterOrDigit(c)) + { + continue; + } + if (char.IsDigit(c) && !char.IsLower(c)) + { + stringBuilder.Append(char.ToLower(c)); + } + else + { + stringBuilder.Append(c); + } + } + stringBuilder.Append('-'); + stringBuilder.Append(Guid.NewGuid().ToString("N")); + + return stringBuilder.ToString(0, Math.Min(stringBuilder.Length, 24)); + } } } diff --git a/sdk/provisioning/Azure.Provisioning/src/websites/AppServicePlan.cs b/sdk/provisioning/Azure.Provisioning/src/websites/AppServicePlan.cs index 33d538d5083ce..44d66e3476050 100644 --- a/sdk/provisioning/Azure.Provisioning/src/websites/AppServicePlan.cs +++ b/sdk/provisioning/Azure.Provisioning/src/websites/AppServicePlan.cs @@ -16,8 +16,6 @@ public class AppServicePlan : Resource { private const string ResourceTypeName = "Microsoft.Web/serverfarms"; - private static string GetName(IConstruct scope, string? name) => name is null ? $"appServicePlan-{scope.EnvironmentName}" : $"{name}-{scope.EnvironmentName}"; - /// /// Initializes a new instance of the . /// @@ -26,8 +24,8 @@ public class AppServicePlan : Resource /// The version. /// The location. public AppServicePlan(IConstruct scope, string resourceName, string version = "2021-02-01", AzureLocation? location = default) - : base(scope, null, GetName(scope, resourceName), ResourceTypeName, version, ArmAppServiceModelFactory.AppServicePlanData( - name: GetName(scope, resourceName), + : base(scope, null, resourceName, ResourceTypeName, version, (name) => ArmAppServiceModelFactory.AppServicePlanData( + name: name, location: location ?? Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS, sku: new AppServiceSkuDescription() { Name = "B1" }, isReserved: true)) diff --git a/sdk/provisioning/Azure.Provisioning/src/websites/ApplicationSettingsResource.cs b/sdk/provisioning/Azure.Provisioning/src/websites/ApplicationSettingsResource.cs index 9cc38e42a8323..0419763b7abb4 100644 --- a/sdk/provisioning/Azure.Provisioning/src/websites/ApplicationSettingsResource.cs +++ b/sdk/provisioning/Azure.Provisioning/src/websites/ApplicationSettingsResource.cs @@ -11,7 +11,7 @@ internal class ApplicationSettingsResource : Resource appSettings, WebSite? parent = null, string version = "2021-02-01") - : base(scope, parent, "appsettings", ResourceTypeName, version, ArmAppServiceModelFactory.AppServiceConfigurationDictionary( + : base(scope, parent, "appsettings", ResourceTypeName, version, (name) => ArmAppServiceModelFactory.AppServiceConfigurationDictionary( name: "appsettings", properties: appSettings)) { diff --git a/sdk/provisioning/Azure.Provisioning/src/websites/WebSite.cs b/sdk/provisioning/Azure.Provisioning/src/websites/WebSite.cs index 971d1275813da..de258213a8cab 100644 --- a/sdk/provisioning/Azure.Provisioning/src/websites/WebSite.cs +++ b/sdk/provisioning/Azure.Provisioning/src/websites/WebSite.cs @@ -32,7 +32,6 @@ public enum WebSiteRuntime public class WebSite : Resource { private const string ResourceTypeName = "Microsoft.Web/sites"; - private static string GetName(IConstruct scope, string? name) => name is null ? $"webSite-{scope.EnvironmentName}" : $"{name}-{scope.EnvironmentName}"; private ApplicationSettingsResource AppSettings { get; } @@ -47,8 +46,8 @@ public class WebSite : Resource /// The version. /// The location. public WebSite(IConstruct scope, string resourceName, AppServicePlan appServicePlan, WebSiteRuntime runtime, string runtimeVersion, string version = "2021-02-01", AzureLocation? location = default) - : base(scope, null, GetName(scope, resourceName), ResourceTypeName, version, ArmAppServiceModelFactory.WebSiteData( - name: GetName(scope, resourceName), + : base(scope, null, resourceName, ResourceTypeName, version, (name) => ArmAppServiceModelFactory.WebSiteData( + name: name, location: location ?? Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS, resourceType: ResourceTypeName, kind: "app,linux", diff --git a/sdk/provisioning/Azure.Provisioning/src/websites/WebSiteConfigLogs.cs b/sdk/provisioning/Azure.Provisioning/src/websites/WebSiteConfigLogs.cs index 05c819a59fdf8..61823e52d6610 100644 --- a/sdk/provisioning/Azure.Provisioning/src/websites/WebSiteConfigLogs.cs +++ b/sdk/provisioning/Azure.Provisioning/src/websites/WebSiteConfigLogs.cs @@ -14,8 +14,6 @@ public class WebSiteConfigLogs : Resource { private const string ResourceTypeName = "Microsoft.Web/sites/config"; - private static string GetName(IConstruct scope, string? name) => name is null ? $"logs-{scope.EnvironmentName}" : $"{name}-{scope.EnvironmentName}"; - /// /// Initializes a new instance of the . /// @@ -25,8 +23,8 @@ public class WebSiteConfigLogs : Resource /// The version. /// The location. public WebSiteConfigLogs(IConstruct scope, string resourceName, WebSite? parent = null, string version = "2021-02-01", AzureLocation? location = default) - : base(scope, parent, resourceName, ResourceTypeName, version, ArmAppServiceModelFactory.SiteLogsConfigData( - name: resourceName, + : base(scope, parent, resourceName, ResourceTypeName, version, (name) => ArmAppServiceModelFactory.SiteLogsConfigData( + name: name, applicationLogs: new ApplicationLogsConfig() { FileSystemLevel = WebAppLogLevel.Verbose @@ -44,5 +42,8 @@ public WebSiteConfigLogs(IConstruct scope, string resourceName, WebSite? parent })) { } + + /// + protected override string GetAzureName(IConstruct scope, string resourceName) => resourceName; } } diff --git a/sdk/provisioning/Azure.Provisioning/src/websites/WebSitePublishingCredentialPolicy.cs b/sdk/provisioning/Azure.Provisioning/src/websites/WebSitePublishingCredentialPolicy.cs index 467b9995e8e10..385a4f9551560 100644 --- a/sdk/provisioning/Azure.Provisioning/src/websites/WebSitePublishingCredentialPolicy.cs +++ b/sdk/provisioning/Azure.Provisioning/src/websites/WebSitePublishingCredentialPolicy.cs @@ -14,8 +14,6 @@ public class WebSitePublishingCredentialPolicy : Resource name is null ? $"publishingCredentialPolicy-{scope.EnvironmentName}" : $"{name}-{scope.EnvironmentName}"; - /// /// Initializes a new instance of the class. /// @@ -24,8 +22,8 @@ public class WebSitePublishingCredentialPolicy : ResourceThe version. /// The location. public WebSitePublishingCredentialPolicy(IConstruct scope, string resourceName, string version = "2021-02-01", AzureLocation? location = default) - : base(scope, null, GetName(scope, resourceName), ResourceTypeName, version, ArmAppServiceModelFactory.CsmPublishingCredentialsPoliciesEntityData( - name: GetName(scope, resourceName), + : base(scope, null, resourceName, ResourceTypeName, version, (name) => ArmAppServiceModelFactory.CsmPublishingCredentialsPoliciesEntityData( + name: name, allow: false)) { } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/main.bicep index 0264df3811fbd..fe8ed79f4ee14 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/main.bicep @@ -9,9 +9,9 @@ resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' } } -resource storageAccount_blTmfjwbK 'Microsoft.Storage/storageAccounts@2022-09-01' = { +resource storageAccount_TDwXOzG67 'Microsoft.Storage/storageAccounts@2022-09-01' = { scope: resourceGroup_I6QNkoPsb - name: 'photoAcct-4e4db487e2b643' + name: 'photoAcct-7f1b0ebf61714c' location: 'westus' sku: { name: 'Premium_LRS' @@ -21,8 +21,8 @@ resource storageAccount_blTmfjwbK 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_BsPXWXWhN 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_blTmfjwbK +resource blobService_JcufSwMPd 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_TDwXOzG67 name: 'photos-TEST' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/main.bicep index c03c30a706955..50896072b7ea7 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/main.bicep @@ -9,9 +9,9 @@ resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' } } -resource storageAccount_hEAJzZrZs 'Microsoft.Storage/storageAccounts@2022-09-01' = { +resource storageAccount_LayX88MCA 'Microsoft.Storage/storageAccounts@2022-09-01' = { scope: resourceGroup_I6QNkoPsb - name: 'photoAcct-1b8d4004b0984b' + name: 'photoAcct-94212d55456a47' location: 'westus' sku: { name: 'Premium_LRS' @@ -21,8 +21,8 @@ resource storageAccount_hEAJzZrZs 'Microsoft.Storage/storageAccounts@2022-09-01' } } -resource blobService_0wStUCho1 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { - parent: storageAccount_hEAJzZrZs +resource blobService_mmxB2GeFN 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_LayX88MCA name: 'photos-TEST' properties: { cors: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep index d43f5d9ffa9b1..962c6bbcbb0ff 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL1/main.bicep @@ -58,7 +58,7 @@ resource webSite_W5EweSXEq 'Microsoft.Web/sites@2021-02-01' = { } } -resource applicationSettingsResource_NslbdUwEt 'Microsoft.Web/sites/config@2021-02-01' = { +resource applicationSettingsResource_9BG7vUQd2 'Microsoft.Web/sites/config@2021-02-01' = { parent: webSite_W5EweSXEq name: 'appsettings' } @@ -76,7 +76,7 @@ resource keyVault_CRoMbemLF 'Microsoft.KeyVault/vaults@2023-02-01' = { } } -resource keyVaultAddAccessPolicy_OttgS6uaT 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { +resource keyVaultAddAccessPolicy_NWCGclP20 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { parent: keyVault_CRoMbemLF name: 'add' properties: { @@ -95,17 +95,17 @@ resource keyVaultAddAccessPolicy_OttgS6uaT 'Microsoft.KeyVault/vaults/accessPoli } } -resource keyVaultSecret_nMDmVNMVq 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { +resource keyVaultSecret_NmXfhaHvM 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { parent: keyVault_CRoMbemLF - name: 'sqlAdminPassword' + name: 'sqlAdminPassword-TEST' properties: { value: sqlAdminPassword } } -resource keyVaultSecret_PrlUnEuAz 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { +resource keyVaultSecret_QRsiyFBMe 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { parent: keyVault_CRoMbemLF - name: 'appUserPassword' + name: 'appUserPassword-TEST' properties: { value: appUserPassword } @@ -132,9 +132,9 @@ resource sqlDatabase_U7NzorRJT 'Microsoft.Sql/servers/databases@2022-08-01-previ } } -resource keyVaultSecret_NP8ELZpgb 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { +resource keyVaultSecret_7eiFxkj0r 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { parent: keyVault_CRoMbemLF - name: 'connectionString' + name: 'connectionString-TEST' properties: { value: 'Server=${sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName}; Database=${sqlDatabase_U7NzorRJT.name}; User=appUser; Password=${appUserPassword}' } @@ -228,7 +228,7 @@ resource webSite_4pzZqR2OO 'Microsoft.Web/sites@2021-02-01' = { } } -resource applicationSettingsResource_Pfdqa0OdT 'Microsoft.Web/sites/config@2021-02-01' = { +resource applicationSettingsResource_vEe46o8Zn 'Microsoft.Web/sites/config@2021-02-01' = { parent: webSite_4pzZqR2OO name: 'appsettings' properties: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep index 748389309f98d..6edc46bfa65f9 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/main.bicep @@ -43,7 +43,7 @@ resource keyVault_CRoMbemLF 'Microsoft.KeyVault/vaults@2023-02-01' = { } } -resource keyVaultAddAccessPolicy_OttgS6uaT 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { +resource keyVaultAddAccessPolicy_NWCGclP20 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { parent: keyVault_CRoMbemLF name: 'add' properties: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/TestBackEndWebSite/TestBackEndWebSite.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/TestBackEndWebSite/TestBackEndWebSite.bicep index 6922472a5c1f4..f92d15b10452b 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/TestBackEndWebSite/TestBackEndWebSite.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/TestBackEndWebSite/TestBackEndWebSite.bicep @@ -30,7 +30,7 @@ resource webSite_4pzZqR2OO 'Microsoft.Web/sites@2021-02-01' = { } } -resource applicationSettingsResource_Pfdqa0OdT 'Microsoft.Web/sites/config@2021-02-01' = { +resource applicationSettingsResource_vEe46o8Zn 'Microsoft.Web/sites/config@2021-02-01' = { parent: webSite_4pzZqR2OO name: 'appsettings' properties: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/TestCommonSqlDatabase/TestCommonSqlDatabase.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/TestCommonSqlDatabase/TestCommonSqlDatabase.bicep index ff3a54c940cf5..b6e644f6cc615 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/TestCommonSqlDatabase/TestCommonSqlDatabase.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/TestCommonSqlDatabase/TestCommonSqlDatabase.bicep @@ -11,17 +11,17 @@ resource keyVault_CRoMbemLF 'Microsoft.KeyVault/vaults@2023-02-01' existing = { name: 'keyVault_CRoMbemLF' } -resource keyVaultSecret_nMDmVNMVq 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { +resource keyVaultSecret_NmXfhaHvM 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { parent: keyVault_CRoMbemLF - name: 'sqlAdminPassword' + name: 'sqlAdminPassword-TEST' properties: { value: sqlAdminPassword } } -resource keyVaultSecret_PrlUnEuAz 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { +resource keyVaultSecret_QRsiyFBMe 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { parent: keyVault_CRoMbemLF - name: 'appUserPassword' + name: 'appUserPassword-TEST' properties: { value: appUserPassword } @@ -47,9 +47,9 @@ resource sqlDatabase_U7NzorRJT 'Microsoft.Sql/servers/databases@2022-08-01-previ } } -resource keyVaultSecret_NP8ELZpgb 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { +resource keyVaultSecret_7eiFxkj0r 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { parent: keyVault_CRoMbemLF - name: 'connectionString' + name: 'connectionString-TEST' properties: { value: 'Server=${sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName}; Database=${sqlDatabase_U7NzorRJT.name}; User=appUser; Password=${appUserPassword}' } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/TestFrontEndWebSite/TestFrontEndWebSite.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/TestFrontEndWebSite/TestFrontEndWebSite.bicep index 70b2a2a6da499..dc133defcbbe7 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/TestFrontEndWebSite/TestFrontEndWebSite.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL2/resources/TestFrontEndWebSite/TestFrontEndWebSite.bicep @@ -34,7 +34,7 @@ resource webSite_W5EweSXEq 'Microsoft.Web/sites@2021-02-01' = { } } -resource applicationSettingsResource_NslbdUwEt 'Microsoft.Web/sites/config@2021-02-01' = { +resource applicationSettingsResource_9BG7vUQd2 'Microsoft.Web/sites/config@2021-02-01' = { parent: webSite_W5EweSXEq name: 'appsettings' } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestBackEndWebSite/TestBackEndWebSite.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestBackEndWebSite/TestBackEndWebSite.bicep index 6922472a5c1f4..f92d15b10452b 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestBackEndWebSite/TestBackEndWebSite.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestBackEndWebSite/TestBackEndWebSite.bicep @@ -30,7 +30,7 @@ resource webSite_4pzZqR2OO 'Microsoft.Web/sites@2021-02-01' = { } } -resource applicationSettingsResource_Pfdqa0OdT 'Microsoft.Web/sites/config@2021-02-01' = { +resource applicationSettingsResource_vEe46o8Zn 'Microsoft.Web/sites/config@2021-02-01' = { parent: webSite_4pzZqR2OO name: 'appsettings' properties: { diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestCommonSqlDatabase/TestCommonSqlDatabase.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestCommonSqlDatabase/TestCommonSqlDatabase.bicep index ff3a54c940cf5..b6e644f6cc615 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestCommonSqlDatabase/TestCommonSqlDatabase.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestCommonSqlDatabase/TestCommonSqlDatabase.bicep @@ -11,17 +11,17 @@ resource keyVault_CRoMbemLF 'Microsoft.KeyVault/vaults@2023-02-01' existing = { name: 'keyVault_CRoMbemLF' } -resource keyVaultSecret_nMDmVNMVq 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { +resource keyVaultSecret_NmXfhaHvM 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { parent: keyVault_CRoMbemLF - name: 'sqlAdminPassword' + name: 'sqlAdminPassword-TEST' properties: { value: sqlAdminPassword } } -resource keyVaultSecret_PrlUnEuAz 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { +resource keyVaultSecret_QRsiyFBMe 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { parent: keyVault_CRoMbemLF - name: 'appUserPassword' + name: 'appUserPassword-TEST' properties: { value: appUserPassword } @@ -47,9 +47,9 @@ resource sqlDatabase_U7NzorRJT 'Microsoft.Sql/servers/databases@2022-08-01-previ } } -resource keyVaultSecret_NP8ELZpgb 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { +resource keyVaultSecret_7eiFxkj0r 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = { parent: keyVault_CRoMbemLF - name: 'connectionString' + name: 'connectionString-TEST' properties: { value: 'Server=${sqlServer_zjdvvB2wl.properties.fullyQualifiedDomainName}; Database=${sqlDatabase_U7NzorRJT.name}; User=appUser; Password=${appUserPassword}' } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestFrontEndWebSite/TestFrontEndWebSite.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestFrontEndWebSite/TestFrontEndWebSite.bicep index 70b2a2a6da499..dc133defcbbe7 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestFrontEndWebSite/TestFrontEndWebSite.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestFrontEndWebSite/TestFrontEndWebSite.bicep @@ -34,7 +34,7 @@ resource webSite_W5EweSXEq 'Microsoft.Web/sites@2021-02-01' = { } } -resource applicationSettingsResource_NslbdUwEt 'Microsoft.Web/sites/config@2021-02-01' = { +resource applicationSettingsResource_9BG7vUQd2 'Microsoft.Web/sites/config@2021-02-01' = { parent: webSite_W5EweSXEq name: 'appsettings' } diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestWebSiteWithSqlBackEnd/TestWebSiteWithSqlBackEnd.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestWebSiteWithSqlBackEnd/TestWebSiteWithSqlBackEnd.bicep index 26593965a6196..18109bc3e3039 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestWebSiteWithSqlBackEnd/TestWebSiteWithSqlBackEnd.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/WebSiteUsingL3/resources/TestWebSiteWithSqlBackEnd/TestWebSiteWithSqlBackEnd.bicep @@ -33,7 +33,7 @@ resource keyVault_CRoMbemLF 'Microsoft.KeyVault/vaults@2023-02-01' = { } } -resource keyVaultAddAccessPolicy_OttgS6uaT 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { +resource keyVaultAddAccessPolicy_NWCGclP20 'Microsoft.KeyVault/vaults/accessPolicies@2023-02-01' = { parent: keyVault_CRoMbemLF name: 'add' properties: {