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

Adds CMK for CosmosDB Account #8919

Merged
merged 9 commits into from Nov 11, 2020

Conversation

petems
Copy link
Contributor

@petems petems commented Oct 16, 2020

Copy link
Member

@jackofallops jackofallops left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @petems - Thanks for this PR, looks off to a good start.

My understanding is that the key_vault_key_id property can be changed / updated, so I think we'd need to remove the ForceNew and include it in the update. As it stands, I believe it will remove the key from the account was otherwise updated? Could you add a test that covers the new property also?

Thanks!

@katbyte
Copy link
Collaborator

katbyte commented Oct 19, 2020

Adding to @jackofallops's comment, could we also add a test that updates the key_vault_key_id

@petems
Copy link
Contributor Author

petems commented Oct 20, 2020

My understanding is that the key_vault_key_id property can be changed / updated, so I think we'd need to remove the ForceNew and include it in the update. As it stands, I believe it will remove the key from the account was otherwise updated? Could you add a test that covers the new property also?

Currently the key_vault_key_uri cannot be changed in the API, its only possible on new resources, which is why I set it to ForceNew:

Code="BadRequest" Message="Updating KeyVaultKeyUri is not supported\r\nActivityId: 5f367e7d-92ee-42a7-966b-fb12e53ab69a, Microsoft.Azure.Documents.Common/2.11.0"

See Azure/azure-rest-api-specs#10323

But I will add a test for it overall

@@ -993,3 +1016,60 @@ func checkAccAzureRMCosmosDBAccount_basic(data acceptance.TestData, consistency
resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_readonly_key"),
)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@katbyte @jackofallops I've created a test using a key vault example from a different test, can I get some 👀 on it? And run it as an acc-test if it looks correct?

@petems
Copy link
Contributor Author

petems commented Oct 20, 2020

Just did a manual test, and this config works for me now:

provider "azurerm" {
  features {}
}
resource "azurerm_resource_group" "test" {
  name     = "acctestRG-cosmos-123456"
  location = "West US 2"
}

data "azurerm_client_config" "current" {}

data "azuread_service_principal" "cosmosdb" {
  display_name = "Azure Cosmos DB"
}

resource "azurerm_key_vault" "test" {
  name                = "acctestkeyvault123456789"
  location            = azurerm_resource_group.test.location
  resource_group_name = azurerm_resource_group.test.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",
    ]

    secret_permissions = [
      "get",
      "delete",
      "set",
    ]
  }

  access_policy {
    tenant_id = data.azurerm_client_config.current.tenant_id
    object_id = data.azuread_service_principal.cosmosdb.id

    key_permissions = [
      "list",
      "create",
      "delete",
      "get",
      "update",
      "unwrapKey",
      "wrapKey",
    ]

    secret_permissions = [
      "get",
      "delete",
      "set",
    ]
  }
}

resource "azurerm_key_vault_key" "test" {
  name         = "examplekey123456"
  key_vault_id = azurerm_key_vault.test.id
  key_type     = "RSA"
  key_size     = 2048

  key_opts = [
    "decrypt",
    "encrypt",
    "sign",
    "unwrapKey",
    "verify",
    "wrapKey",
  ]
}

resource "azurerm_cosmosdb_account" "test" {
  name                = "acctest-ca-123456"
  location            = azurerm_resource_group.test.location
  resource_group_name = azurerm_resource_group.test.name
  offer_type          = "Standard"
  kind                = "MongoDB"
  key_vault_key_uri   = "${azurerm_key_vault.test.vault_uri}keys/${azurerm_key_vault_key.test.name}/"
  consistency_policy {
    consistency_level = "Strong"
  }
  geo_location {
    location          = azurerm_resource_group.test.location
    failover_priority = 0
  }
}

Will fix the test to use this

@ghost ghost added size/L and removed size/M labels Oct 20, 2020
Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @petems - aside from a couple comments this LGTM

website/docs/d/cosmosdb_account.html.markdown Outdated Show resolved Hide resolved
website/docs/r/cosmosdb_account.html.markdown Outdated Show resolved Hide resolved
@petems
Copy link
Contributor Author

petems commented Nov 4, 2020

@katbyte All good to merge? I dont have button rights 😄

Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@jackofallops
Copy link
Member

Tests passing (1 fail transient, unrelated)
image

@jackofallops jackofallops merged commit 9bc0a5a into hashicorp:master Nov 11, 2020
jackofallops added a commit that referenced this pull request Nov 11, 2020
@petems petems deleted the add_cmk_to_cosmosdb branch November 11, 2020 10:59
@ghost
Copy link

ghost commented Nov 12, 2020

This has been released in version 2.36.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.36.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Dec 11, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@hashicorp hashicorp locked as resolved and limited conversation to collaborators Dec 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for CosmosDB encryption with CMK
4 participants