-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add simple storage examples (#41956)
* add simple storage examples * update api
- Loading branch information
Showing
9 changed files
with
263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
sdk/provisioning/Azure.Provisioning/src/storage/BlobService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Azure.ResourceManager.Storage; | ||
using Azure.ResourceManager.Storage.Models; | ||
|
||
namespace Azure.Provisioning.Storage | ||
{ | ||
/// <summary> | ||
/// Represents a blob service. | ||
/// </summary> | ||
public class BlobService : Resource<BlobServiceData> | ||
{ | ||
private const string ResourceTypeName = "Microsoft.Storage/storageAccounts/blobServices"; | ||
|
||
private static string GetName(IConstruct scope, string? name) | ||
{ | ||
return $"{name}-{scope.EnvironmentName}"; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="BlobService"/>. | ||
/// </summary> | ||
/// <param name="scope">The scope.</param> | ||
/// <param name="name">The name.</param> | ||
public BlobService(IConstruct scope, string name = "blob") | ||
: base(scope, null, GetName(scope, name), ResourceTypeName, "2022-09-01", ArmStorageModelFactory.BlobServiceData( | ||
name: GetName(scope, name), | ||
resourceType: ResourceTypeName)) | ||
{ | ||
} | ||
|
||
/// <inheritdoc/> | ||
protected override Resource? FindParentInScope(IConstruct scope) | ||
{ | ||
var result = base.FindParentInScope(scope); | ||
if (result is null) | ||
{ | ||
result = scope.GetSingleResource<StorageAccount>() ?? new StorageAccount(scope, StorageKind.BlockBlobStorage, StorageSkuName.PremiumLrs); | ||
} | ||
return result; | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
sdk/provisioning/Azure.Provisioning/src/storage/StorageAccount.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using Azure.Core; | ||
using Azure.Provisioning.ResourceManager; | ||
using Azure.ResourceManager.Storage; | ||
using Azure.ResourceManager.Storage.Models; | ||
|
||
namespace Azure.Provisioning.Storage | ||
{ | ||
/// <summary> | ||
/// Represents a storage account. | ||
/// </summary> | ||
public class StorageAccount : Resource<StorageAccountData> | ||
{ | ||
private const string ResourceTypeName = "Microsoft.Storage/storageAccounts"; | ||
|
||
private static string GetName(IConstruct scope, string name) | ||
{ | ||
var result = $"{name}-{Guid.NewGuid()}"; | ||
return result.Substring(0, Math.Min(result.Length, 24)); | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="StorageAccount"/>. | ||
/// </summary> | ||
/// <param name="scope">The scope.</param> | ||
/// <param name="kind">The kind.</param> | ||
/// <param name="sku">The sku.</param> | ||
/// <param name="parent">The parent.</param> | ||
/// <param name="name">The name.</param> | ||
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), | ||
resourceType: ResourceTypeName, | ||
location: Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS, | ||
sku: new StorageSku(sku), | ||
kind: StorageKind.StorageV2)) | ||
{ | ||
} | ||
|
||
/// <inheritdoc/> | ||
protected override Resource? FindParentInScope(IConstruct scope) | ||
{ | ||
var result = base.FindParentInScope(scope); | ||
if (result is null) | ||
{ | ||
result = scope.GetOrAddResourceGroup(); | ||
} | ||
return result; | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
sdk/provisioning/Azure.Provisioning/src/storage/StorageExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Azure.Provisioning.ResourceManager; | ||
using Azure.ResourceManager.Storage.Models; | ||
|
||
namespace Azure.Provisioning.Storage | ||
{ | ||
/// <summary> | ||
/// Extension methods for <see cref="IConstruct"/>. | ||
/// </summary> | ||
public static class StorageExtensions | ||
{ | ||
/// <summary> | ||
/// Adds a <see cref="StorageAccount"/> to the construct. | ||
/// </summary> | ||
/// <param name="scope">The scope.</param> | ||
/// <param name="kind">The kind.</param> | ||
/// <param name="sku">The sku.</param> | ||
/// <param name="parent">The parent.</param> | ||
/// <param name="name">The name.</param> | ||
/// <returns></returns> | ||
public static StorageAccount AddStorageAccount(this IConstruct scope, StorageKind kind, StorageSkuName sku, ResourceGroup? parent = null, string name = "sa") | ||
{ | ||
return new StorageAccount(scope, kind, sku, parent, name); | ||
} | ||
|
||
/// <summary> | ||
/// Adds a <see cref="BlobService"/> to the construct. | ||
/// </summary> | ||
/// <param name="scope">The scope.</param> | ||
/// <param name="name">The name.</param> | ||
/// <returns></returns> | ||
public static BlobService AddBlobService(this IConstruct scope, string name = "blob") | ||
{ | ||
return new BlobService(scope, name); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDefaults/main.bicep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
targetScope = subscription | ||
|
||
|
||
resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = { | ||
name: 'rg-TEST' | ||
location: 'westus' | ||
tags: { | ||
azd-env-name: 'TEST' | ||
} | ||
} | ||
|
||
resource storageAccount_k7HxHnTvM 'Microsoft.Storage/storageAccounts@2022-09-01' = { | ||
scope: resourceGroup_I6QNkoPsb | ||
name: 'photoAcct-bda380cf-8cdb-' | ||
location: 'westus' | ||
sku: { | ||
name: 'Premium_LRS' | ||
} | ||
kind: 'StorageV2' | ||
properties: { | ||
} | ||
} | ||
|
||
resource blobService_BvgLmmmbK 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { | ||
parent: storageAccount_k7HxHnTvM | ||
name: 'photos-TEST' | ||
properties: { | ||
cors: { | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
sdk/provisioning/Azure.Provisioning/tests/Infrastructure/StorageBlobDropDown/main.bicep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
targetScope = subscription | ||
|
||
|
||
resource resourceGroup_I6QNkoPsb 'Microsoft.Resources/resourceGroups@2023-07-01' = { | ||
name: 'rg-TEST' | ||
location: 'westus' | ||
tags: { | ||
azd-env-name: 'TEST' | ||
} | ||
} | ||
|
||
resource storageAccount_9gvCV8M9t 'Microsoft.Storage/storageAccounts@2022-09-01' = { | ||
scope: resourceGroup_I6QNkoPsb | ||
name: 'photoAcct-464eb449-f1cd-' | ||
location: 'westus' | ||
sku: { | ||
name: 'Premium_LRS' | ||
} | ||
kind: 'StorageV2' | ||
properties: { | ||
} | ||
} | ||
|
||
resource blobService_8xlkwSZNm 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { | ||
parent: storageAccount_9gvCV8M9t | ||
name: 'photos-TEST' | ||
properties: { | ||
cors: { | ||
} | ||
deleteRetentionPolicy: { | ||
enabled: true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters