Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ No modules.
| [random_id.uniq](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id) | resource |
| [terraform_data.job_execution_now](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/resources/data) | resource |
| [azurerm_client_config.current](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/client_config) | data source |
| [azurerm_key_vault.existing](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/key_vault) | data source |
| [azurerm_resource_group.scanning_rg](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/resource_group) | data source |
| [azurerm_subscription.current](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/subscription) | data source |
| [azurerm_subscriptions.available](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/subscriptions) | data source |
Expand Down
23 changes: 17 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,15 @@ locals {
environment_variables_as_list = concat([for key, val in local.environment_variables : { name = key, value = val }],
[for obj in var.additional_environment_variables : { name = obj["name"], value = obj["value"] }])

key_vault_id = var.global ? azurerm_key_vault.lw_orchestrate[0].id : (
key_vault_id = var.global ? (
length(var.key_vault_id) > 0 ? var.key_vault_id : azurerm_key_vault.lw_orchestrate[0].id
) : (
length(var.global_module_reference.key_vault_id) > 0 ? var.global_module_reference.key_vault_id : var.key_vault_id
)
key_vault_secret_name = var.global ? "${local.prefix}-secret-${local.suffix}" : var.global_module_reference.key_vault_secret_name
key_vault_uri = var.global ? azurerm_key_vault.lw_orchestrate[0].vault_uri : var.global_module_reference.key_vault_uri
key_vault_uri = var.global ? (
length(var.key_vault_id) > 0 ? data.azurerm_key_vault.existing[0].vault_uri : azurerm_key_vault.lw_orchestrate[0].vault_uri
) : var.global_module_reference.key_vault_uri

/* role_definition_id created as part of azurerm_role_definition creation contains an extra '|' character in the end, which needs to be removed (using split) */
monitored_subscription_role_definition_id = var.global ? split("|", azurerm_role_definition.agentless_monitored_subscription[0].id)[0] : var.global_module_reference.monitored_subscription_role_definition_id
Expand Down Expand Up @@ -258,8 +262,15 @@ resource "azurerm_user_assigned_identity" "sidekick" {
/* **************** Key Vault ****************
Define the key vault which holds integration details
*/

data "azurerm_key_vault" "existing" {
count = var.global && length(var.key_vault_id) > 0 ? 1 : 0
name = split("/", var.key_vault_id)[length(split("/", var.key_vault_id))-1]
resource_group_name = split("/", var.key_vault_id)[4]
}

resource "azurerm_key_vault" "lw_orchestrate" {
count = var.global ? 1 : 0
count = var.global && length(var.key_vault_id) == 0 ? 1 : 0
depends_on = [azurerm_resource_group.scanning_rg]

name = "${local.prefix}-agentless-${local.suffix}"
Expand All @@ -282,7 +293,7 @@ id (as an env variable) to be created, while the key vault needs the container
app managed identity to create access policies.
*/
resource "azurerm_key_vault_access_policy" "access_for_sidekick" {
count = var.global ? 1 : 0
count = var.global && length(var.key_vault_id) == 0 ? 1 : 0

key_vault_id = local.key_vault_id
tenant_id = local.tenant_id
Expand All @@ -297,7 +308,7 @@ resource "azurerm_key_vault_access_policy" "access_for_sidekick" {
}

resource "azurerm_key_vault_access_policy" "access_for_user" {
count = var.global ? 1 : 0
count = var.global && length(var.key_vault_id) == 0 ? 1 : 0

key_vault_id = local.key_vault_id
tenant_id = local.tenant_id
Expand Down Expand Up @@ -338,7 +349,7 @@ resource "azurerm_key_vault_secret" "lw_orchestrate" {
count = var.global ? 1 : 0
depends_on = [
lacework_integration_azure_agentless_scanning.lacework_cloud_account,
azurerm_key_vault_access_policy.access_for_user
Copy link
Contributor

Choose a reason for hiding this comment

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

don't we still need this in the case that we're not using an existing key vault?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

shoot, good call. Let me update and test.

azurerm_role_assignment.key_vault_user
]

/* stores credentials used to authenticate to LW API server */
Expand Down