https://pulumi.com logo
#dotnet
Title
# dotnet
p

powerful-printer-57241

11/13/2020, 2:54 PM
Hi, we cannot get the secret config values working. In particular, we have the following config value, set like this:
Copy code
pulumi config set --secret databaseServerPassword "abcdef"
In a stack, we have
Copy code
var databaseServerPassword = config.RequireSecret("databaseServerPassword");
...
var database = new Database(...); // This works fine

return new AppService(
    resourcesPrefix,
    new AppServiceArgs
    {
        Name = resourcesPrefix,
        AppServicePlanId = appServicePlanId,
        ResourceGroupName = resourceGroupName,        
        ConnectionStrings =
        {
            new AppServiceConnectionStringArgs
            {
                Name = "Database",
                Type = "SQLAzure",
                Value = Output.Tuple(database.ServerName, database.Name, databaseServerPassword).Apply(t =>
                {
                    var (serverName, databaseName, databasePassword) = t;                    
                    return $"Data Source=tcp:{serverName}.<http://database.windows.net|database.windows.net>,1433;Initial Catalog={databaseName};User ID={databaseUsername}@{serverName};Password={databasePassword}";
                })
            }
        }
    }
);
The app service is created fine, but without the connection string. If we remove databaseServerPassword from Output.Tuple (and remove the corresponding variable from the connection string), it works fine. Is there a problem in the way we work with secrets/output?
n

nice-oyster-71086

11/27/2020, 7:00 PM
Any update on this? I'm having issues as well. In particular
config.RequireSecret("<secret>")
returns a type of
Output<string>
which I can't seem to get at.
1
p

powerful-printer-57241

11/28/2020, 11:38 AM
No update unfortunately, I still don't know what's wrong with this approach.
b

bored-activity-40468

11/28/2020, 5:07 PM
What secrets provider are you using?
w

witty-candle-66007

11/30/2020, 9:52 PM
If I understand correctly, the issue is that the
databaseServerPassword
can’t be used because it’s an
Output<string>
. This is as per https://www.pulumi.com/docs/intro/concepts/programming-model/#how-secrets-relate-to-outputs So
.Apply
needs to be used and the reference to the secret variable used within the apply. Here is some example code where the secret is used within the
.Apply
to create a resource group:
Copy code
class MyStack : Stack
{
    public MyStack()
    {
        var config = new Pulumi.Config();
        var rgName = config.GetSecret("rgName"); 

        // Create an Azure Resource Group
        var resourceGroupName = rgName.Apply(rgn => {
            var rg = new ResourceGroup(rgn, new ResourceGroupArgs
            {
                Name = rgn,
            });
            return rg.Name;
        });

        var storageAccount = new Account("storage", new AccountArgs
        {
            ResourceGroupName = resourceGroupName,
            AccountReplicationType = "LRS",
            AccountTier = "Standard"
        });

        this.ResourceGroupName = resourceGroupName;
        this.ConnectionString = storageAccount.PrimaryConnectionString;

    }
    [Output] 
    public Output<string> ResourceGroupName { get; set; }
    [Output]
    public Output<string> ConnectionString { get; set; }
}
p

powerful-printer-57241

12/01/2020, 8:01 AM
@witty-candle-66007 But we are using apply.
w

witty-candle-66007

12/01/2020, 1:47 PM
Yes. And I saw that but I thought it was because of how you were using the Apply. As it turns out your code is very close to this: https://github.com/pulumi/examples/blob/master/azure-cs-appservice/AppServiceStack.cs Do you have the same problem if you follow the pattern in the referenced example? Or if there are reasons for not following that pattern, can you share your code in full?