Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMK support for Cosmos DB (core) #4154

Merged
merged 38 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9d185d4
added management key vault
Sep 9, 2024
3bab628
added cmk for vmss and storage accounts
Sep 11, 2024
dec4288
Merge branch 'main' of https://github.com/yuvalyaron/AzureTRE into 40…
yuvalyaron Nov 7, 2024
7388db5
Merge branch 'main' of https://github.com/yuvalyaron/AzureTRE into 40…
yuvalyaron Nov 11, 2024
036b90e
add default value for variables
yuvalyaron Nov 13, 2024
27212b4
add CMK for cosmos accounts
yuvalyaron Nov 14, 2024
50ec316
move tre-encryption key from mgmt to core
yuvalyaron Nov 17, 2024
df682d6
fix order of creation for encryption key
yuvalyaron Nov 17, 2024
9e66234
add cmk for the state store in mgmt
yuvalyaron Nov 17, 2024
fed7a16
add support for external KV
yuvalyaron Nov 18, 2024
7f24a23
revert CMK for cosmos - not working, need to redo this
yuvalyaron Nov 18, 2024
cd9271a
refine comments and files names
yuvalyaron Nov 19, 2024
f459a82
remove redundant space
yuvalyaron Nov 19, 2024
af53615
add space
yuvalyaron Nov 19, 2024
61d8e97
upper case in comment
yuvalyaron Nov 19, 2024
25322d7
revert cosmos tags
yuvalyaron Nov 19, 2024
e3e2d6c
Merge branch 'main' into 4002-cmk-support
yuvalyaron Nov 19, 2024
8ef0231
update changelog + core version
yuvalyaron Nov 19, 2024
70ddb6b
remove unused var
yuvalyaron Nov 19, 2024
ce953ea
remove redundant variable
yuvalyaron Nov 19, 2024
8a48a95
remove redundant variables
yuvalyaron Nov 19, 2024
b07871e
add check for enable_cmk_encryption for the key_store_id variable in tf
yuvalyaron Nov 19, 2024
0106748
bugfix: remove redundant data keyword
yuvalyaron Nov 19, 2024
18ce3fd
add enable_cmk_encryption check in module variables
yuvalyaron Nov 20, 2024
c05f752
remove redundant key_vault_id from ignore_changes for cmk
yuvalyaron Nov 21, 2024
c7f1413
remove redundant sign/verify
yuvalyaron Nov 24, 2024
26c3f79
add cmk support for cosmos db
yuvalyaron Nov 24, 2024
1666b30
update changelog + add comments
yuvalyaron Nov 24, 2024
42886ff
update core version
yuvalyaron Nov 24, 2024
dea119b
fix linting issue
yuvalyaron Nov 24, 2024
d771f6c
add null provider to providers block
yuvalyaron Nov 24, 2024
c661fdb
Merge branch 'main' of https://github.com/microsoft/AzureTRE into 414…
yuvalyaron Nov 26, 2024
e8617e4
remove duplicates that were created by merge
yuvalyaron Nov 26, 2024
56d59f5
update core version
yuvalyaron Nov 26, 2024
23d30bf
remove redundant terraform data
yuvalyaron Nov 26, 2024
4f93421
Merge branch 'main' into 4144-cmk-support-for-cosmosdb2
Nov 29, 2024
c6e63e8
Merge branch 'main' of https://github.com/microsoft/AzureTRE into 414…
yuvalyaron Dec 1, 2024
2544556
bump core version
yuvalyaron Dec 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ENHANCEMENTS:
* Update Terraform to use Azure AD authentication rather than storage account keys ([#4103](https://github.com/microsoft/AzureTRE/issues/4103))
* Update obsolete Terraform properties ([#4136](https://github.com/microsoft/AzureTRE/issues/4136))
* Update Guacamole version and dependencies ([#4140](https://github.com/microsoft/AzureTRE/issues/4140))
* Add partial (core resources only) support for customer managed keys ([#4141](https://github.com/microsoft/AzureTRE/issues/4142))
* Add partial (core resources only) support for customer managed keys ([#4141](https://github.com/microsoft/AzureTRE/issues/4142), [#4144](https://github.com/microsoft/AzureTRE/issues/4144))
* Update the Azure CLI version to 2.67.0 in dev container and vmss ([#4157](https://github.com/microsoft/AzureTRE/pull/4157))

BUG FIXES:
Expand Down
19 changes: 19 additions & 0 deletions core/terraform/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions core/terraform/api-identity.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ resource "azurerm_cosmosdb_sql_role_assignment" "tre_db_contributor" {
role_definition_id = data.azurerm_cosmosdb_sql_role_definition.cosmosdb_db_contributor.id
principal_id = azurerm_user_assigned_identity.id.principal_id
scope = azurerm_cosmosdb_account.tre_db_account.id

depends_on = [null_resource.tre_db_account_enable_cmk]
}
29 changes: 28 additions & 1 deletion core/terraform/cosmos_mongo.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,38 @@ resource "azurerm_cosmosdb_account" "mongo" {
failover_priority = 0
}

dynamic "identity" {
for_each = var.enable_cmk_encryption ? [1] : []
content {
type = "UserAssigned"
identity_ids = [azurerm_user_assigned_identity.encryption[0].id]
}
}

default_identity_type = var.enable_cmk_encryption ? "UserAssignedIdentity=${azurerm_user_assigned_identity.encryption[0].id}" : null

tags = local.tre_core_tags

lifecycle { ignore_changes = [tags] }
# since key_vault_key_id is created by the 'mongo_enable_cmk' null_resource, terraform forces re-creation of the resource
lifecycle { ignore_changes = [tags, key_vault_key_id] }
}

# Using the az CLI command since terraform forces a re-creation of the resource
# https://github.com/hashicorp/terraform-provider-azurerm/issues/24781
resource "null_resource" "mongo_enable_cmk" {
count = var.enable_cmk_encryption ? 1 : 0

provisioner "local-exec" {
command = "az cosmosdb update --name ${azurerm_cosmosdb_account.mongo.name} --resource-group ${azurerm_cosmosdb_account.mongo.resource_group_name} --key-uri ${azurerm_key_vault_key.tre_encryption[0].versionless_id}"
}

depends_on = [
azurerm_cosmosdb_account.mongo,
azurerm_role_assignment.kv_encryption_key_user[0]
]
}


resource "azurerm_cosmosdb_mongo_database" "mongo" {
name = "porter"
resource_group_name = azurerm_resource_group.core.name
Expand Down
4 changes: 4 additions & 0 deletions core/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ terraform {
source = "Azure/azapi"
version = "~> 1.15.0"
}
null = {
source = "hashicorp/null"
version = "~> 3.2"
}
}

backend "azurerm" {}
Expand Down
28 changes: 27 additions & 1 deletion core/terraform/statestore.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ resource "azurerm_cosmosdb_account" "tre_db_account" {
}
}

dynamic "identity" {
for_each = var.enable_cmk_encryption ? [1] : []
content {
type = "UserAssigned"
identity_ids = [azurerm_user_assigned_identity.encryption[0].id]
}
}

default_identity_type = var.enable_cmk_encryption ? "UserAssignedIdentity=${azurerm_user_assigned_identity.encryption[0].id}" : null

consistency_policy {
consistency_level = "BoundedStaleness"
max_interval_in_seconds = 10
Expand All @@ -27,7 +37,8 @@ resource "azurerm_cosmosdb_account" "tre_db_account" {
failover_priority = 0
}

lifecycle { ignore_changes = [tags] }
# since key_vault_key_id is created by the 'tre_db_account_enable_cmk' null_resource, terraform forces re-creation of the resource
lifecycle { ignore_changes = [tags, key_vault_key_id] }
}

moved {
Expand Down Expand Up @@ -95,3 +106,18 @@ resource "azurerm_private_endpoint" "sspe" {
subresource_names = ["Sql"]
}
}

# Using the az CLI command since terraform forces a re-creation of the resource
# https://github.com/hashicorp/terraform-provider-azurerm/issues/24781
resource "null_resource" "tre_db_account_enable_cmk" {
count = var.enable_cmk_encryption ? 1 : 0

provisioner "local-exec" {
command = "az cosmosdb update --name ${azurerm_cosmosdb_account.tre_db_account.name} --resource-group ${azurerm_cosmosdb_account.tre_db_account.resource_group_name} --key-uri ${azurerm_key_vault_key.tre_encryption[0].versionless_id}"
}

depends_on = [
azurerm_cosmosdb_account.tre_db_account,
azurerm_role_assignment.kv_encryption_key_user[0]
]
}
1 change: 0 additions & 1 deletion core/terraform/storage.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ resource "azurerm_storage_account" "stg" {
allow_nested_items_to_be_public = false
cross_tenant_replication_enabled = false


dynamic "identity" {
for_each = var.enable_cmk_encryption ? [1] : []
content {
Expand Down
2 changes: 1 addition & 1 deletion core/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.11.3"
__version__ = "0.11.4"
Loading