From f0b0b5572fdf7455cf842c24268fb4a1523dcb9a Mon Sep 17 00:00:00 2001 From: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Date: Wed, 28 Feb 2024 17:17:36 -0800 Subject: [PATCH] Use bicep function for storage account name (#42271) * Use bicep function for storage account name * lambda * revert param rename --- .../src/storage/StorageAccount.cs | 4 ++++ .../main.bicep | 20 +++++++++++++++++++ .../tests/ProvisioningTests.cs | 19 ++++++++++++++---- 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaultsInPromptMode/main.bicep diff --git a/sdk/provisioning/Azure.Provisioning/src/storage/StorageAccount.cs b/sdk/provisioning/Azure.Provisioning/src/storage/StorageAccount.cs index 6a761b031fc0b..4c89e4b8240ab 100644 --- a/sdk/provisioning/Azure.Provisioning/src/storage/StorageAccount.cs +++ b/sdk/provisioning/Azure.Provisioning/src/storage/StorageAccount.cs @@ -33,6 +33,10 @@ public StorageAccount(IConstruct scope, StorageKind kind, StorageSkuName sku, Re sku: new StorageSku(sku), kind: StorageKind.StorageV2)) { + if (scope.Configuration?.UsePromptMode == true) + { + AssignProperty(data => data.Name, $"toLower(take(concat('{name}', uniqueString(resourceGroup().id)), 24))"); + } } /// diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaultsInPromptMode/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaultsInPromptMode/main.bicep new file mode 100644 index 0000000000000..5c8b1c572ae90 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaultsInPromptMode/main.bicep @@ -0,0 +1,20 @@ +targetScope = 'resourceGroup' + + +resource storageAccount_Ls2Cd9uGu 'Microsoft.Storage/storageAccounts@2022-09-01' = { + name: toLower(take(concat('photoAcct', uniqueString(resourceGroup().id)), 24)) + location: resourceGroup().location + sku: { + name: 'Premium_LRS' + } + kind: 'StorageV2' + properties: { + } +} + +resource blobService_OdYIZd2T2 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { + parent: storageAccount_Ls2Cd9uGu + name: 'default' + properties: { + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs index 8bab3611ee8a2..342e268c54dae 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs +++ b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs @@ -193,7 +193,7 @@ await ValidateBicepAsync(BinaryData.FromObjectAsJson( { sqlAdminPassword = new { value = "password" }, appUserPassword = new { value = "password" } - }), anonymousResourceGroup: true); + }), promptMode: true); } [Test] @@ -207,6 +207,17 @@ public async Task StorageBlobDefaults() await ValidateBicepAsync(); } + [Test] + public async Task StorageBlobDefaultsInPromptMode() + { + var infra = new TestInfrastructure(configuration: new Configuration { UsePromptMode = true }); + infra.AddStorageAccount(name: "photoAcct", sku: StorageSkuName.PremiumLrs, kind: StorageKind.BlockBlobStorage); + infra.AddBlobService(); + infra.Build(GetOutputPath()); + + await ValidateBicepAsync(promptMode: true); + } + [Test] public async Task StorageBlobDropDown() { @@ -280,7 +291,7 @@ public async Task OutputsSpanningModules() await ValidateBicepAsync(); } - public async Task ValidateBicepAsync(BinaryData? parameters = null, bool anonymousResourceGroup = false) + public async Task ValidateBicepAsync(BinaryData? parameters = null, bool promptMode = false) { if (TestEnvironment.GlobalIsRunningInCI) { @@ -317,7 +328,7 @@ public async Task ValidateBicepAsync(BinaryData? parameters = null, bool anonymo } ResourceIdentifier scope; - if (anonymousResourceGroup) + if (promptMode) { var rgs = subscription.GetResourceGroups(); var data = new ResourceGroupData("westus"); @@ -337,7 +348,7 @@ public async Task ValidateBicepAsync(BinaryData? parameters = null, bool anonymo Template = new BinaryData(File.ReadAllText(Path.Combine(testPath, "main.json"))), Parameters = parameters }); - if (!anonymousResourceGroup) + if (!promptMode) { content.Location = "westus"; }