-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds CMK for CosmosDB Account (#8919)
Co-authored-by: kt <[email protected]> Co-authored-by: jackofallops <[email protected]>
- Loading branch information
1 parent
53946ff
commit 9bc0a5a
Showing
9 changed files
with
296 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## Example: CosmosDB with CMK (Customer Managed Key) encryption | ||
|
||
This example provisions a CosmosDB Account in a single region that uses a generated key stored in a Key Vault for encryption. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
provider "azurerm" { | ||
features {} | ||
} | ||
|
||
resource "azurerm_resource_group" "example" { | ||
name = "${var.prefix}-resources" | ||
location = var.location | ||
} | ||
|
||
data "azuread_service_principal" "cosmosdb" { | ||
display_name = "Azure Cosmos DB" | ||
} | ||
|
||
data "azurerm_client_config" "current" {} | ||
|
||
resource "azurerm_key_vault" "example" { | ||
name = "${var.prefix}kv" | ||
location = azurerm_resource_group.example.location | ||
resource_group_name = azurerm_resource_group.example.name | ||
tenant_id = data.azurerm_client_config.current.tenant_id | ||
sku_name = "premium" | ||
|
||
purge_protection_enabled = true | ||
soft_delete_enabled = true | ||
|
||
access_policy { | ||
tenant_id = data.azurerm_client_config.current.tenant_id | ||
object_id = data.azurerm_client_config.current.object_id | ||
|
||
key_permissions = [ | ||
"list", | ||
"create", | ||
"delete", | ||
"get", | ||
"update", | ||
] | ||
|
||
} | ||
|
||
access_policy { | ||
tenant_id = data.azurerm_client_config.current.tenant_id | ||
object_id = data.azuread_service_principal.cosmosdb.id | ||
|
||
key_permissions = [ | ||
"get", | ||
"unwrapKey", | ||
"wrapKey", | ||
] | ||
} | ||
} | ||
|
||
resource "azurerm_key_vault_key" "example" { | ||
name = "${var.prefix}key" | ||
key_vault_id = azurerm_key_vault.example.id | ||
key_type = "RSA" | ||
key_size = 3072 | ||
|
||
key_opts = [ | ||
"decrypt", | ||
"encrypt", | ||
"wrapKey", | ||
"unwrapKey", | ||
] | ||
} | ||
|
||
resource "azurerm_cosmosdb_account" "example" { | ||
name = "${var.prefix}-cosmosdb" | ||
location = azurerm_resource_group.example.location | ||
resource_group_name = azurerm_resource_group.example.name | ||
offer_type = "Standard" | ||
kind = "MongoDB" | ||
key_vault_key_id = azurerm_key_vault_key.example.id | ||
|
||
consistency_policy { | ||
consistency_level = "Strong" | ||
} | ||
|
||
geo_location { | ||
prefix = "${var.prefix}-customid" | ||
location = azurerm_resource_group.example.location | ||
failover_priority = 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
output "cosmos-db-id" { | ||
value = "${azurerm_cosmosdb_account.example.id}" | ||
} | ||
|
||
output "cosmos-db-endpoint" { | ||
value = "${azurerm_cosmosdb_account.example.endpoint}" | ||
} | ||
|
||
output "cosmos-db-endpoints_read" { | ||
value = "${azurerm_cosmosdb_account.example.read_endpoints}" | ||
} | ||
|
||
output "cosmos-db-endpoints_write" { | ||
value = "${azurerm_cosmosdb_account.example.write_endpoints}" | ||
} | ||
|
||
output "cosmos-db-primary_key" { | ||
value = "${azurerm_cosmosdb_account.example.primary_key}" | ||
} | ||
|
||
output "cosmos-db-secondary_key" { | ||
value = "${azurerm_cosmosdb_account.example.secondary_key}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
variable "prefix" { | ||
description = "The prefix which should be used for all resources in this example" | ||
} | ||
|
||
variable "location" { | ||
description = "The Azure Region in which all resources in this example should be created." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters