Hi pulumi, what's the latest way to get the connec...
# azure
a
Hi pulumi, what's the latest way to get the connection string from a storage account being created? your sample code shows the connection string is returned as part of the storage account object, but the latest library seems to have changed this, right?
m
I wasn’t aware that this changed. Are you referring to Azure Native or Classic?
l
Here's C# / .NET code I use to construct a connection string from the primary storage account key (Keys[0]):
Copy code
public static Output<string> GetStorageAccountConnectionString(Output<string> rgName, Output<string> storageAccountName)
    {
        var key = Output.Tuple(rgName, storageAccountName).Apply(names =>
            Output.CreateSecret(GetStorageAccountPrimaryKey(names.Item1, names.Item2)));

        return Output.Tuple(storageAccountName, key).Apply(values => $"DefaultEndpointsProtocol=https;AccountName={values.Item1};AccountKey={values.Item2};EndpointSuffix=<http://core.windows.net|core.windows.net>");
    }

    public static Output<string> GetStorageAccountPrimaryKey(string rgName, string storageAccountName)
    {
        var accountKeys = ListStorageAccountKeys.Invoke(new ListStorageAccountKeysInvokeArgs
        {
            ResourceGroupName = rgName,
            AccountName = storageAccountName
        });

        return accountKeys.Apply(k => k.Keys[0].Value);
    }
a
Thx Donnie i'll look! Thomas, this is the link i was looking which seems to be out of sync with the sdk: https://www.pulumi.com/ai/answers/kn7utchWrkjHBTjXhzcS3G/azure-storage-account-setup-tutorial
// Export the connection string for the storage account export const connectionString = storageAccount.primaryConnectionString;
The connectionstring property is pretty handy
m
It's beaucse Pulumi AI seems to be mixing Azure Classic Provider and Azure Native provider. @melodic-tomato-39005 anything that could be done to avoid Pulumi AI mixing up native and classic providers ? By the way @abundant-lock-75924 you should not export directly the connection string or the key as output, you have to tag them as secret output before. It's what @little-library-54601 did on his sample.
a
right, thx for the note Alex!