|
| 1 | +# Resource: mongodbatlas_encryption_at_rest_private_endpoint |
| 2 | + |
| 3 | +`mongodbatlas_encryption_at_rest_private_endpoint` provides a resource for managing a private endpoint used for encryption at rest with customer-managed keys. This ensures all traffic between Atlas and customer key management systems take place over private network interfaces. |
| 4 | + |
| 5 | +~> **IMPORTANT** The Encryption at Rest using Azure Key Vault over Private Endpoints feature is available by request. To request this functionality for you Atlas deployments, contact your Account Manager. |
| 6 | +Additionally, you'll need to set the environment variable `MONGODB_ATLAS_ENABLE_PREVIEW=true` to use this resource. To learn more about existing limitations, see the [Manage Customer Keys with Azure Key Vault Over Private Endpoints](https://www.mongodb.com/docs/atlas/security/azure-kms-over-private-endpoint/#manage-customer-keys-with-azure-key-vault-over-private-endpoints). |
| 7 | + |
| 8 | +-> **NOTE:** Only Azure Key Vault with Azure Private Link is supported at this time. |
| 9 | + |
| 10 | +## Example Usages |
| 11 | + |
| 12 | +### Configuring Atlas Encryption at Rest using Azure Key Vault with Azure Private Link |
| 13 | + |
| 14 | +```terraform |
| 15 | +resource "mongodbatlas_encryption_at_rest" "ear" { |
| 16 | + project_id = var.atlas_project_id |
| 17 | +
|
| 18 | + azure_key_vault_config { |
| 19 | + require_private_networking = true |
| 20 | +
|
| 21 | + enabled = true |
| 22 | + azure_environment = "AZURE" |
| 23 | +
|
| 24 | + tenant_id = var.azure_tenant_id |
| 25 | + subscription_id = var.azure_subscription_id |
| 26 | + client_id = var.azure_client_id |
| 27 | + secret = var.azure_client_secret |
| 28 | +
|
| 29 | + resource_group_name = var.azure_resource_group_name |
| 30 | + key_vault_name = var.azure_key_vault_name |
| 31 | + key_identifier = var.azure_key_identifier |
| 32 | + } |
| 33 | +} |
| 34 | +
|
| 35 | +# Creates private endpoint |
| 36 | +resource "mongodbatlas_encryption_at_rest_private_endpoint" "endpoint" { |
| 37 | + project_id = mongodbatlas_encryption_at_rest.ear.project_id |
| 38 | + cloud_provider = "AZURE" |
| 39 | + region_name = var.azure_region_name |
| 40 | +} |
| 41 | +
|
| 42 | +locals { |
| 43 | + key_vault_resource_id = "/subscriptions/${var.azure_subscription_id}/resourceGroups/${var.azure_resource_group_name}/providers/Microsoft.KeyVault/vaults/${var.azure_key_vault_name}" |
| 44 | +} |
| 45 | +
|
| 46 | +# Approves private endpoint connection from Azure Key Vault |
| 47 | +resource "azapi_update_resource" "approval" { |
| 48 | + type = "Microsoft.KeyVault/Vaults/PrivateEndpointConnections@2023-07-01" |
| 49 | + name = mongodbatlas_encryption_at_rest_private_endpoint.endpoint.private_endpoint_connection_name |
| 50 | + parent_id = local.key_vault_resource_id |
| 51 | +
|
| 52 | + body = jsonencode({ |
| 53 | + properties = { |
| 54 | + privateLinkServiceConnectionState = { |
| 55 | + description = "Approved via Terraform" |
| 56 | + status = "Approved" |
| 57 | + } |
| 58 | + } |
| 59 | + }) |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +<!-- schema generated by tfplugindocs --> |
| 64 | +## Schema |
| 65 | + |
| 66 | +### Required |
| 67 | + |
| 68 | +- `cloud_provider` (String) Label that identifies the cloud provider for the Encryption At Rest private endpoint. |
| 69 | +- `project_id` (String) Unique 24-hexadecimal digit string that identifies your project. |
| 70 | +- `region_name` (String) Cloud provider region in which the Encryption At Rest private endpoint is located. |
| 71 | + |
| 72 | +### Read-Only |
| 73 | + |
| 74 | +- `error_message` (String) Error message for failures associated with the Encryption At Rest private endpoint. |
| 75 | +- `id` (String) Unique 24-hexadecimal digit string that identifies the Private Endpoint Service. |
| 76 | +- `private_endpoint_connection_name` (String) Connection name of the Azure Private Endpoint. |
| 77 | +- `status` (String) State of the Encryption At Rest private endpoint. |
| 78 | + |
| 79 | +# Import |
| 80 | +Encryption At Rest Private Endpoint resource can be imported using the project ID, cloud provider, and private endpoint ID. The format must be `{project_id}-{cloud_provider}-{private_endpoint_id}` e.g. |
| 81 | + |
| 82 | +``` |
| 83 | +$ terraform import mongodbatlas_encryption_at_rest_private_endpoint.test 650972848269185c55f40ca1-AZURE-650972848269185c55f40ca2 |
| 84 | +``` |
| 85 | + |
| 86 | +For more information see: |
| 87 | +- [MongoDB Atlas API - Private Endpoint for Encryption at Rest Using Customer Key Management](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Encryption-at-Rest-using-Customer-Key-Management/operation/getEncryptionAtRestPrivateEndpoint) Documentation. |
| 88 | +- [Manage Customer Keys with Azure Key Vault Over Private Endpoints](https://www.mongodb.com/docs/atlas/security/azure-kms-over-private-endpoint/). |
0 commit comments