我正在尝试从"classic"Azure到Azure Native的Pulumi。我的需求之一是检索Connectionstring和AccessKey到我新创建的StorageAccount。
经典Azure我收到这些字段的
var connectionString=ClassicStorageAccount.PrimaryConnectionString;
var accessKey=ClassicStorageAccount.PrimaryAccessKey;
其中ClassicStorageAccount
的类型为Pulumi.Azure.Storage.Account
使用Azure Native创建存储帐户后:
var account=new Pulumi.AzureNative.Storage.StorageAccount("myMagicAccount", new StorageAccountArgs{...});
我正在努力检索AccessKey。
我能够使用
检索connectionstringvar connectionstring=account.StorageAccount.PrimaryEndpoints.Apply(q=>q.Web);
但PrimaryEndpoints
或PrivateEndpointConnections
的属性似乎都没有包含我所需的AccessKey。
Azure Native上的StorageAccount文档没有帮助我使用这种方法
你可以使用listStorageAccountKeys方法。
using System.Threading.Tasks;
using Pulumi;
using Pulumi.AzureNative.Resources;
using Pulumi.AzureNative.Storage;
using Pulumi.AzureNative.Storage.Inputs;
class MyStack : Stack
{
public MyStack()
{
// Create an Azure Resource Group
var resourceGroup = new ResourceGroup("resourceGroup");
// Create an Azure resource (Storage Account)
var storageAccount = new StorageAccount("sa", new StorageAccountArgs
{
ResourceGroupName = resourceGroup.Name,
Sku = new SkuArgs
{
Name = SkuName.Standard_LRS
},
Kind = Kind.StorageV2
});
// Export the primary key of the Storage Account
this.PrimaryStorageKey = Output.Tuple(resourceGroup.Name, storageAccount.Name).Apply(names =>
Output.CreateSecret(GetStorageAccountPrimaryKey(names.Item1, names.Item2)));
}
[Output]
public Output<string> PrimaryStorageKey { get; set; }
private static async Task<string> GetStorageAccountPrimaryKey(string resourceGroupName, string accountName)
{
var accountKeys = await ListStorageAccountKeys.InvokeAsync(new ListStorageAccountKeysArgs
{
ResourceGroupName = resourceGroupName,
AccountName = accountName
});
return accountKeys.Keys[0].Value;
}
}
上面的代码来自Pulumi运行pulumi new azure-csharp
时使用的模板,可以在模板存储库