https://pulumi.com logo
Title
m

mysterious-australia-14256

09/30/2021, 12:21 PM
Hi, I'm hoping for some guidance on how to correctly implement the following... I am deploying an Integration Runtime to an Azure Data Factory using Pulumi.AzureNative.DataFactory.IntegrationRuntime. Once the integration runtime has been deployed I then need to obtain the AuthKey from it. There is a function for this ( Pulumi.AzureNative.DataFactory.ListIntegrationRuntimeAuthKeys) but it requires the Integration Runtime Name to be specified as a string. The Integration Runtime deployment returns an object with a Name property of type Output<string> which the ListIntegrationRuntimeAuthKeys won't accept. I am guessing that I need to make use of something like Apply here to get the name back as a string but am unsure how to do it in such a way that I get the authKey correctly returned (also as a string not an Output<string>)? This doesn't work for example as authKey is only available within the Apply block and I need it available outside of that (so I can pass it in to another deployment that also wants it as a string)
integrationRuntime.Name.Apply(n =>
{
    var authKey = Pulumi.AzureNative.DataFactory.ListIntegrationRuntimeAuthKeys.InvokeAsync(new Pulumi.AzureNative.DataFactory.ListIntegrationRuntimeAuthKeysArgs
    {
        FactoryName = runtimeSettings.DataFactoryName,
        ResourceGroupName = runtimeSettings.DataFactoryResourceGroup,
        IntegrationRuntimeName = n
    }).Result.AuthKey1;
    return n;
});
t

tall-librarian-49374

09/30/2021, 12:26 PM
You can’t get a
string
from
Output<string>
because you’d loose the dependency tracking then. Why do you need your auth key to be a plain string? You can usually pass outputs as inputs to other resources.
m

mysterious-australia-14256

09/30/2021, 1:06 PM
I need to pass the auth string in as part of a powershell command in a VirtualMachineExtension deployment. The args for that have a ProtectedSettings property which takes a dictionary<string,.string>. I need to add an entry to that with key = "commandToExecute" and value = "the powershell command including the auth key"
t

tall-librarian-49374

09/30/2021, 1:26 PM
Then you need to build the dictionary inside another Apply
m

mysterious-australia-14256

09/30/2021, 1:43 PM
OK so I take it you mean that the VirtualMachineExtension deployemnt would have to also run within the Apply. This is how I have it at the moment but the pulumi docs warn against creating new resources inside of Applys so I was trying to refactor it. I take it that this is unavoidable in this scenario? Apply Docs
t

tall-librarian-49374

09/30/2021, 2:01 PM
No, the resource won’t be inside an Apply. Resource properties are always inputs which accept outputs.
Your last apply should produce
Output<X>
where X is what ProtectedSettings needs
👍 1
m

mysterious-australia-14256

09/30/2021, 2:02 PM
ah OK, I'll give that a go, thanks
OK that seems to be working 🙂 . The only code I have left inside the Apply is the code that creates the command string (which I add to the dictionary). The only reason this has to remain in the Apply is because I can't find another way to ensure that the Integration Runtime is created before I try to get the access key. I create the Integration Runtime with code like..
var myIR = new Pulumi.AzureNative.DataFactory.IntegrationRuntime(<some settings>);
I then need to get the authKey which requires code like
var authKey = Pulumi.AzureNative.DataFactory.ListIntegrationRuntimeAuthKeys.InvokeAsync(new Pulumi.AzureNative.DataFactory.ListIntegrationRuntimeAuthKeysArgs
{
    FactoryName = "dfname"
    ResourceGroupName = "rgname",
    IntegrationRuntimeName = myIR.Name
}).Result.AuthKey1;
The problem here is that IntegrationRuntimeName only accepts a string (not an Input<string>) so I am just wrapping all of that in an Apply for the myIR object just to ensure that myIR exists (as there isn't a dependsOn option for ListIntegrationRuntimeAuthKeys)
var commandToExecute = myIR.Name.Apply<string>(name =>
{
    var authKey = Pulumi.AzureNative.DataFactory.ListIntegrationRuntimeAuthKeys.InvokeAsync(new Pulumi.AzureNative.DataFactory.ListIntegrationRuntimeAuthKeysArgs
    {
        FactoryName = "dfname",
        ResourceGroupName = "rgname",
        IntegrationRuntimeName = name 
    }).Result.AuthKey1;

    var commandToExecute = $"powershell.exe -ExecutionPolicy Unrestricted -File gatewayInstall.ps1 {authKey}";

    return commandToExecute;
});
I am no longer creating anything inside of the Apply. Does that look like the best way to proceed given I can't apply an Input<string> to IntegrationRuntimeName?
t

tall-librarian-49374

09/30/2021, 2:50 PM
That looks correct until we land https://github.com/pulumi/pulumi/issues/7945 where functions will accepts outputs. The only change I suggest is an await
var commandToExecute = myIR.Name.Apply<string>(async name =>
{
    var authKey = (await Pulumi.AzureNative.DataFactory.ListIntegrationRuntimeAuthKeys.InvokeAsync(new Pulumi.AzureNative.DataFactory.ListIntegrationRuntimeAuthKeysArgs
    {
        FactoryName = "dfname",
        ResourceGroupName = "rgname",
        IntegrationRuntimeName = name 
    })).AuthKey1;

    var commandToExecute = $"powershell.exe -ExecutionPolicy Unrestricted -File gatewayInstall.ps1 {authKey}";

    return commandToExecute;
});
👍 1
m

mysterious-australia-14256

09/30/2021, 3:02 PM
thanks for your help