This message was deleted.
# azure
s
This message was deleted.
t
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
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
Then you need to build the dictionary inside another Apply
m
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
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
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
Copy code
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)
Copy code
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
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
Copy code
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
thanks for your help