azurermMysqlServerKey
Manages a Customer Managed Key for a MySQL 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 azurermMysqlServerExample = new azurerm.mysqlServer.MysqlServer(
this,
"example_4",
{
administrator_login: "acctestun",
administrator_login_password: "H@Sh1CoR3!",
identity: [
{
type: "SystemAssigned",
},
],
location: azurermResourceGroupExample.location,
name: "example-mysql-server",
resource_group_name: azurermResourceGroupExample.name,
sku_name: "GP_Gen5_2",
ssl_enforcement_enabled: true,
ssl_minimal_tls_version_enforced: "TLS1_1",
storage_mb: 51200,
version: "5.7",
}
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermMysqlServerExample.overrideLogicalId("example");
const azurermKeyVaultAccessPolicyServer =
new azurerm.keyVaultAccessPolicy.KeyVaultAccessPolicy(this, "server", {
key_permissions: ["Get", "UnwrapKey", "WrapKey"],
key_vault_id: azurermKeyVaultExample.id,
object_id: `\${${azurermMysqlServerExample.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 azurermMysqlServerKeyExample = new azurerm.mysqlServerKey.MysqlServerKey(
this,
"example_7",
{
key_vault_key_id: azurermKeyVaultKeyExample.id,
server_id: azurermMysqlServerExample.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.*/
azurermMysqlServerKeyExample.overrideLogicalId("example");
Argument Reference
The following arguments are supported:
-
serverId
- (Required) The ID of the MySQL 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 MySQL Server Key.
Timeouts
The timeouts
block allows you to specify timeouts for certain actions:
create
- (Defaults to 60 minutes) Used when creating the MySQL Server Key.update
- (Defaults to 60 minutes) Used when updating the MySQL Server Key.read
- (Defaults to 5 minutes) Used when retrieving the MySQL Server Key.delete
- (Defaults to 60 minutes) Used when deleting the MySQL Server Key.
Import
A MySQL Server Key can be imported using the resourceId
of the MySQL Server Key, e.g.