Skip to content

azurermPostgresqlServerKey

Manages a Customer Managed Key for a PostgreSQL Server.

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 dataAzurermClientConfigCurrent =
  new azurerm.dataAzurermClientConfig.DataAzurermClientConfig(
    this,
    "current",
    {}
  );
const azurermKeyVaultExample = new azurerm.keyVault.KeyVault(
  this,
  "example_2",
  {
    location: azurermResourceGroupExample.location,
    name: "examplekv",
    purge_protection_enabled: true,
    resource_group_name: azurermResourceGroupExample.name,
    sku_name: "premium",
    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 azurermKeyVaultAccessPolicyClient =
  new azurerm.keyVaultAccessPolicy.KeyVaultAccessPolicy(this, "client", {
    key_permissions: [
      "Get",
      "Create",
      "Delete",
      "List",
      "Restore",
      "Recover",
      "UnwrapKey",
      "WrapKey",
      "Purge",
      "Encrypt",
      "Decrypt",
      "Sign",
      "Verify",
      "GetRotationPolicy",
    ],
    key_vault_id: azurermKeyVaultExample.id,
    object_id: dataAzurermClientConfigCurrent.objectId,
    secret_permissions: ["Get"],
    tenant_id: dataAzurermClientConfigCurrent.tenantId,
  });
const azurermPostgresqlServerExample =
  new azurerm.postgresqlServer.PostgresqlServer(this, "example_4", {
    administrator_login: "psqladmin",
    administrator_login_password: "H@Sh1CoR3!",
    identity: [
      {
        type: "SystemAssigned",
      },
    ],
    location: azurermResourceGroupExample.location,
    name: "example-postgre-server",
    resource_group_name: azurermResourceGroupExample.name,
    sku_name: "GP_Gen5_2",
    ssl_enforcement_enabled: true,
    storage_mb: 51200,
    version: "11",
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermPostgresqlServerExample.overrideLogicalId("example");
const azurermKeyVaultAccessPolicyServer =
  new azurerm.keyVaultAccessPolicy.KeyVaultAccessPolicy(this, "server", {
    key_permissions: ["Get", "UnwrapKey", "WrapKey"],
    key_vault_id: azurermKeyVaultExample.id,
    object_id: `\${${azurermPostgresqlServerExample.identity}.0.principal_id}`,
    secret_permissions: ["Get"],
    tenant_id: dataAzurermClientConfigCurrent.tenantId,
  });
const azurermKeyVaultKeyExample = new azurerm.keyVaultKey.KeyVaultKey(
  this,
  "example_6",
  {
    depends_on: [
      `\${${azurermKeyVaultAccessPolicyClient.fqn}}`,
      `\${${azurermKeyVaultAccessPolicyServer.fqn}}`,
    ],
    key_opts: ["decrypt", "encrypt", "sign", "unwrapKey", "verify", "wrapKey"],
    key_size: 2048,
    key_type: "RSA",
    key_vault_id: azurermKeyVaultExample.id,
    name: "tfex-key",
  }
);
/*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 azurermPostgresqlServerKeyExample =
  new azurerm.postgresqlServerKey.PostgresqlServerKey(this, "example_7", {
    key_vault_key_id: azurermKeyVaultKeyExample.id,
    server_id: azurermPostgresqlServerExample.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.*/
azurermPostgresqlServerKeyExample.overrideLogicalId("example");

Argument Reference

The following arguments are supported:

  • serverId - (Required) The ID of the PostgreSQL Server. Changing this forces a new resource to be created.

  • keyVaultKeyId - (Required) The URL to a Key Vault Key.

Attributes Reference

The following attributes are exported in addition to the arguments listed above:

  • id - The ID of the PostgreSQL Server Key.

Timeouts

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

  • create - (Defaults to 60 minutes) Used when creating the PostgreSQL Server Key.
  • update - (Defaults to 60 minutes) Used when updating the PostgreSQL Server Key.
  • read - (Defaults to 5 minutes) Used when retrieving the PostgreSQL Server Key.
  • delete - (Defaults to 60 minutes) Used when deleting the PostgreSQL Server Key.

Import

A PostgreSQL Server Key can be imported using the resourceId of the PostgreSQL Server Key, e.g.

terraform import azurerm_postgresql_server_key.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.DBforPostgreSQL/servers/server1/keys/keyvaultname_key-name_keyversion