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

117 views Asked by At

Using Pulumi, how can a Function App reference a connection string from a SQL Server Database declaration?

I've tried building the following SQL connection string:

var sqlServer = server as Pulumi.Azure.Sql.SqlServer;

var connectionString = $"Server=tcp:{sqlServer.FullyQualifiedDomainName},1433;Initial Catalog={sqlDatabase.Name};Persist Security Info=False;User ID={sqlServer.AdministratorLogin};Password={sqlServer.AdministratorLoginPassword};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;";

Unfortunately, the Output<string> property values that are embedded within the connection string, never get resolved after observing the App Settings of an Azure function app.

In Pulumi, does a connection string property exist for an Azure SQL Server database?

1

There are 1 answers

0
Scott Nimrod On BEST ANSWER

The following code resolves a SQL connection string:

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;