Pulumi: How can a Function App reference a connection string from a SQL Server Database declaration?

Using Pulumi, I recently learned how to obtain a connection string from SQL Server database declaration. I needed this connection string so that I could register its value in an App Setting.

I learned that Pulumi provides the ConnStringInfoArgs type to accommodate this need.

Here’s some example code below:

using System;
using Pulumi;
using Pulumi.AzureNative.Resources;
using Classic = Pulumi.Azure;
using Pulumi.AzureNative.Web.Inputs;
using Pulumi.AzureNative.Web;
...
var connectionStringArgs = new ConnStringInfoArgs(){

    Name = "MySqlDbConnection-dev",
    Type = ConnectionStringType.SQLAzure,
    ConnectionString = Output.Tuple(sqlServer.Name, sqlDatabase.Name, sqlServer.AdministratorLogin, sqlServer.AdministratorLoginPassword).Apply(t => {

        (string server, string database, string username, string pwd) = t;

        return
         $"Server= tcp:{server}.database.windows.net;initial catalog={database};userID={username};password={pwd};Min Pool Size=0;Max Pool Size=30;Persist Security Info=true;";
    }),
};

var connectionString = connectionStringArgs.ConnectionString;

Appendix

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: