Once again I find myself being given the usual Out...
# python
i
Once again I find myself being given the usual Output runaround by Pulumi. I have a azure storage account connection string, made like this
Copy code
blob_conn_string=pulumi.Output.all(env_storage.name, env_storage_key).apply(lambda args: f'DefaultEndpointsProtocol: https;AccountName: {args[0]};AccountKey: {args[1]} ;EndpointSuffix: core.windows.net')
The connection string is fine, it's properly formed, all is good. I know it's an Output type, etc. That connection string is supposed to be placed in a Github Actions secret. In order to create said secret the value of connection string needs to be encrypted
Copy code
# this uses the pynacl
def encrypt_github_action_secret(public_encryption_key: str, secret_value: str) -> str:
    public_key = public.PublicKey(public_encryption_key.encode("utf-8"), encoding.Base64Encoder())
    sealed_box = public.SealedBox(public_key)
    encrypted = sealed_box.encrypt(secret_value.encode("utf-8"))
    return b64encode(encrypted).decode("utf-8")

encrypt_github_action_secret(public_encryption_key=public_key, secret_value=blob_conn_string)
The problem is I can't use Output for this, I need a damn string and I am out of options on how to convert the damn Output to a string (or some other form that the encrypting function can use, at this point I am not really picky). According to the documentation (what little there is, and I have given up on the Pulumi Artificial Idiot) the answer to this horror show basically boils down to doing everything within the apply. Any and all pointers would be more than welcome.
d
How come you need it as a string?
If it's just to run the function, then you can call that in an apply too.
blob_conn_enc = blob_conn_string.apply(lambda bc: encrypt_github_action_secret(public_key, bc))
👆 1
i
Thank you for the prompt answer. I don't really need it as a string in this particular case, I just wanted to know if there is some sane way of getting that value as a string (like for instance I need it as a part of some variable).
d
The answer is generally "no", as values aren't always known to the python process. If it's for passing to resources or exports, then you should use the
.apply
method