Skip to content

azurermSynapseWorkspaceKey

Manages Synapse Workspace keys

-> Note: Keys that are actively protecting a workspace cannot be deleted. When the keys resource is deleted, if the key is inactive it will be deleted, if it is active it will not be deleted.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
const azurermResourceGroupExample = new azurerm.resourceGroup.ResourceGroup(
  this,
  "example",
  {
    location: "West Europe",
    name: "example-resources",
  }
);
const azurermStorageAccountExample = new azurerm.storageAccount.StorageAccount(
  this,
  "example_1",
  {
    account_kind: "StorageV2",
    account_replication_type: "LRS",
    account_tier: "Standard",
    is_hns_enabled: "true",
    location: azurermResourceGroupExample.location,
    name: "examplestorageacc",
    resource_group_name: azurermResourceGroupExample.name,
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermStorageAccountExample.overrideLogicalId("example");
const azurermStorageDataLakeGen2FilesystemExample =
  new azurerm.storageDataLakeGen2Filesystem.StorageDataLakeGen2Filesystem(
    this,
    "example_2",
    {
      name: "example",
      storage_account_id: azurermStorageAccountExample.id,
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermStorageDataLakeGen2FilesystemExample.overrideLogicalId("example");
const dataAzurermClientConfigCurrent =
  new azurerm.dataAzurermClientConfig.DataAzurermClientConfig(
    this,
    "current",
    {}
  );
const azurermKeyVaultExample = new azurerm.keyVault.KeyVault(
  this,
  "example_4",
  {
    location: azurermResourceGroupExample.location,
    name: "example",
    purge_protection_enabled: true,
    resource_group_name: azurermResourceGroupExample.name,
    sku_name: "standard",
    tenant_id: dataAzurermClientConfigCurrent.tenantId,
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermKeyVaultExample.overrideLogicalId("example");
const azurermKeyVaultAccessPolicyDeployer =
  new azurerm.keyVaultAccessPolicy.KeyVaultAccessPolicy(this, "deployer", {
    key_permissions: ["Create", "Get", "Delete", "Purge", "GetRotationPolicy"],
    key_vault_id: azurermKeyVaultExample.id,
    object_id: dataAzurermClientConfigCurrent.objectId,
    tenant_id: dataAzurermClientConfigCurrent.tenantId,
  });
const azurermKeyVaultKeyExample = new azurerm.keyVaultKey.KeyVaultKey(
  this,
  "example_6",
  {
    depends_on: [`\${${azurermKeyVaultAccessPolicyDeployer.fqn}}`],
    key_opts: ["unwrapKey", "wrapKey"],
    key_size: 2048,
    key_type: "RSA",
    key_vault_id: azurermKeyVaultExample.id,
    name: "workspaceEncryptionKey",
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermKeyVaultKeyExample.overrideLogicalId("example");
const azurermSynapseWorkspaceExample =
  new azurerm.synapseWorkspace.SynapseWorkspace(this, "example_7", {
    customer_managed_key: [
      {
        key_name: "enckey",
        key_versionless_id: azurermKeyVaultKeyExample.versionlessId,
      },
    ],
    identity: [
      {
        type: "SystemAssigned",
      },
    ],
    location: azurermResourceGroupExample.location,
    name: "example",
    resource_group_name: azurermResourceGroupExample.name,
    sql_administrator_login: "sqladminuser",
    sql_administrator_login_password: "H@Sh1CoR3!",
    storage_data_lake_gen2_filesystem_id:
      azurermStorageDataLakeGen2FilesystemExample.id,
    tags: {
      Env: "production",
    },
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermSynapseWorkspaceExample.overrideLogicalId("example");
const azurermKeyVaultAccessPolicyWorkspacePolicy =
  new azurerm.keyVaultAccessPolicy.KeyVaultAccessPolicy(
    this,
    "workspace_policy",
    {
      key_permissions: ["Get", "WrapKey", "UnwrapKey"],
      key_vault_id: azurermKeyVaultExample.id,
      object_id: `\${${azurermSynapseWorkspaceExample.identity.fqn}[0].principal_id}`,
      tenant_id: `\${${azurermSynapseWorkspaceExample.identity.fqn}[0].tenant_id}`,
    }
  );
const azurermSynapseWorkspaceKeyExample =
  new azurerm.synapseWorkspaceKey.SynapseWorkspaceKey(this, "example_9", {
    active: true,
    customer_managed_key_name: "enckey",
    customer_managed_key_versionless_id:
      azurermKeyVaultKeyExample.versionlessId,
    depends_on: [`\${${azurermKeyVaultAccessPolicyWorkspacePolicy.fqn}}`],
    synapse_workspace_id: azurermSynapseWorkspaceExample.id,
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermSynapseWorkspaceKeyExample.overrideLogicalId("example");

Arguments Reference

The following arguments are supported:

  • customerManagedKeyName - (Required) Specifies the name of the workspace key. Should match the name of the key in the synapse workspace.

  • customerManagedKeyVersionlessId - (Optional) The Azure Key Vault Key Versionless ID to be used as the Customer Managed Key (CMK) for double encryption

  • synapseWorkspaceId - (Required) The ID of the Synapse Workspace where the encryption key should be configured.

  • active - (Required) Specifies if the workspace should be encrypted with this key.

-> Note: Only one key can actively encrypt a workspace. When performing a key rotation, setting a new key as the active key will disable existing keys.

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

  • create - (Defaults to 30 minutes) Used when creating the Synapse Workspace.
  • read - (Defaults to 5 minutes) Used when retrieving the Synapse Workspace.
  • update - (Defaults to 30 minutes) Used when updating the Synapse Workspace.
  • delete - (Defaults to 30 minutes) Used when deleting the Synapse Workspace.

Import

Synapse Workspace Keys can be imported using the resourceId, e.g.

terraform import azurerm_synapse_workspace_key.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Synapse/workspaces/workspace1/keys/key1