Is there a recommended way to include a file as a ...
# azure
m
Is there a recommended way to include a file as a dependency to a Pulumi Command and trigger an update if that file changes? I have a Command that uploads a file to a filestore by calling
az storage file upload
but would like an update to be triggered if the file contents changes. I could possibly hack around this by changing the filename each time, but that’s not ideal and easily forgotten. Unfortunately this doesn’t look like it’s supported in the spec even though it was in az classic: https://pulumi-community.slack.com/archives/C84L4E3N1/p1648163487694929?thread_ts=1648066957.732819&cid=C84L4E3N1 I briefly looked into a Dynamic Provider but that’s not supported in dotnet. Any suggestions welcome 🙂
Have worked around this for now by: 1. Hashing the file 2. Passing that hash as an input to the Environment InputMap Seems to do enough to trigger Update correctly
Copy code
public static Command UploadFile(string commandName, Input<string> fileShareName,
        Input<string> storageAccountName, Input<string> storageKey,
        Input<string> sourceFile, Input<string> fileHash,
        Input<string> destinationFile)
    {
        const string uploadCommand =
            "az storage file upload -s $STORAGE_SHARE_NAME --source $SOURCE_FILE --account-key $STORAGE_ACCOUNT_KEY --account-name $STORAGE_ACCOUNT_NAME -p $DESTINATION_PATH";

        const string deleteCommand =
            "az storage file delete -s $STORAGE_SHARE_NAME --account-key $STORAGE_ACCOUNT_KEY --account-name $STORAGE_ACCOUNT_NAME -p $DESTINATION_PATH";

        return new Command(commandName, new CommandArgs
        {
            Create = uploadCommand,
            Update = uploadCommand,
            Delete = deleteCommand,

            Environment =
            {
                { "STORAGE_SHARE_NAME", fileShareName },
                { "STORAGE_ACCOUNT_NAME", storageAccountName },
                { "STORAGE_ACCOUNT_KEY", storageKey },
                { "SOURCE_FILE", sourceFile },
                { "HASH", fileHash },
                { "DESTINATION_PATH", destinationFile }
            }
        });
    }