powerful-printer-57241
11/13/2020, 2:54 PMpulumi config set --secret databaseServerPassword "abcdef"
In a stack, we have
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?nice-oyster-71086
11/27/2020, 7:00 PMconfig.RequireSecret("<secret>")
returns a type of Output<string>
which I can't seem to get at.powerful-printer-57241
11/28/2020, 11:38 AMbored-activity-40468
11/28/2020, 5:07 PMwitty-candle-66007
11/30/2020, 9:52 PMdatabaseServerPassword
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:
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; }
}
powerful-printer-57241
12/01/2020, 8:01 AMwitty-candle-66007
12/01/2020, 1:47 PM