'Pulumi Azure: get keyvault key version

I want to use customer managed key for the sql server. For that I need to load the key from the keyvault but I cannot get the version of the key, which is required according to the pulumi documentation:

:param pulumi.Input[str] key_name: The name of the server key to be operated on (updated or created). The key name is required to be in the format of 'vault_key_version'. For example, if the keyId is https://YourVaultName.vault.azure.net/keys/YourKeyName/YourKeyVersion, then the server key name should be formatted as: YourVaultName_YourKeyName_YourKeyVersion

Relevant code:

def create_tde_key(self, key: keyvault.Key, vault_name: str):
    key_name            = "{}_{}_{}".format(vault_name, key.name, key.version ) // here I need the version but there is only key.key_uri_with_version

    tde_key = sql.ServerKey('tde-key-' + self.location_flag,
        key_name            = key_name,
        resource_group_name = self.resource_group_name,
        server_name         = self.sql_server,
        server_key_type     = sql.ServerKeyType.AZURE_KEY_VAULT,
        uri                 = key.key_uri_with_version
    ) 

tried to disassemble key.key_uri_with_version this way: key_version = key.key_uri_with_version[key.key_uri_with_version.rfind('/') + 1:] but then I got TypeError: 'Output' object is not callable

I tried to use lambdas to get the string Output from key.key_uri_with_version but got the same TypeError as before.

I tried hardcoding the version and it is working so somehow I need to get the keyversion.

Any idea what should I do?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source