Search code examples
azurepulumi

Pulumi: Manipulate connection string during deployment


I'm using Pulumi to deploy several Azure ressources, which works fine.

I'm deploying a TopicAuthorizationRule and I need to manipulate the connection string in order to have it working with an Azure Function Trigger.

const myPolicy = new azure.eventhub.TopicAuthorizationRule(...);

const myPolicyConnectionString = myPolicy.primaryConnectionString.get();

const goodConnectionString = myPolicyConnectionString .substr(0, myPolicyConnectionString .lastIndexOf(';EntityPath'));

And I have this error: Cannot call '.get' during update or preview

How can I do this string manipulation in order to set it in AppSettings?


Solution

  • Connection string value is unknown yet at the time of preview, so you can't use it directly. It's contained in a value of type Output<T> which is going to be resolved at update time.

    You can transform the values of Output<T> by using apply function:

    const goodConnectionString = 
        myPolicy.primaryConnectionString.apply(s => s.substr(0, s.lastIndexOf(';EntityPath'));
    

    which can then be used to assign AppSettings (without calling get explicitly).