Importing resources?

Is it possible to import resources with cdktf ? I can do i.e.

terrafrom import azurerm_key_vault.keyvault /subscriptions/...

but it requires configuration in the root module (error of terraform import). It doesn’t look like KeyVault in main.ts will help

new KeyVault(this, 'keyvault', {...});

That’s not possible with cdktf directly, but could be done in combination with the Terraform CLI. That would make a good feature requests though: https://cdk.tf/feature

1 Like

Sounds good, thnx. I imported using terraform i.e. keyvault and now trying to add new key but getting an error “Inappropriate value for attribute “key_vault_id”: string required.”

 new KeyVaultKey(this, 'keyvaultkey', {
        name: 'cdktfkey',
        keyVaultId: remoteState.get('azurerm_key_vault.keyvault.id'),
       ...
    });

My state file is like below , not sure what I am doing wrong:

...
"resources": [
    {
      "mode": "managed",
      "type": "azurerm_key_vault",
      "name": "keyvault",
      "provider": "provider.azurerm",
      "instances": [
        {
          "schema_version": 1,
          "attributes": {
....
          "id": "/subscriptions/....
....
]
...