Skip to content

Commit a050977

Browse files
Merge pull request #61 from lacework/feat/upgrade-azure-providers
upgrade azure providers azuread ~> 3.4, azurerm ~> 4.37 --------- Co-authored-by: Pengyuan Zhao <[email protected]>
2 parents 75e5cb6 + 74f348d commit a050977

File tree

5 files changed

+46
-33
lines changed

5 files changed

+46
-33
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ All code contributions made by Lacework customers to this repo are considered
3535
|------|---------|
3636
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.9 |
3737
| <a name="requirement_azapi"></a> [azapi](#requirement\_azapi) | ~> 1.15.0 |
38-
| <a name="requirement_azuread"></a> [azuread](#requirement\_azuread) | ~> 2.53.1 |
39-
| <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) | ~> 3.116.0 |
38+
| <a name="requirement_azuread"></a> [azuread](#requirement\_azuread) | ~> 3.4 |
39+
| <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) | ~> 4.37 |
4040
| <a name="requirement_lacework"></a> [lacework](#requirement\_lacework) | ~> 2.0 |
4141

4242
## Providers
4343

4444
| Name | Version |
4545
|------|---------|
4646
| <a name="provider_azapi"></a> [azapi](#provider\_azapi) | ~> 1.15.0 |
47-
| <a name="provider_azuread"></a> [azuread](#provider\_azuread) | ~> 2.53.1 |
48-
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | ~> 3.116.0 |
47+
| <a name="provider_azuread"></a> [azuread](#provider\_azuread) | ~> 3.4 |
48+
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | ~> 4.37 |
4949
| <a name="provider_lacework"></a> [lacework](#provider\_lacework) | ~> 2.0 |
5050
| <a name="provider_random"></a> [random](#provider\_random) | n/a |
5151
| <a name="provider_terraform"></a> [terraform](#provider\_terraform) | n/a |
@@ -112,7 +112,7 @@ No modules.
112112
| <a name="input_execute_now"></a> [execute\_now](#input\_execute\_now) | execute newly created job(s) immediately after deployment | `bool` | `true` | no |
113113
| <a name="input_filter_query_text"></a> [filter\_query\_text](#input\_filter\_query\_text) | The LQL query to constrain the scanning to specific resources. If left blank, Lacework will scan all resources available to the account or organization. For more information, see [Limit Scanned Workloads](https://docs.lacework.net/onboarding/lacework-console-agentless-workload-scanning#aws---limit-scanned-workloads). | `string` | `""` | no |
114114
| <a name="input_global"></a> [global](#input\_global) | Whether we create global resources for this deployment. Defaults to `false` | `bool` | `false` | no |
115-
| <a name="input_global_module_reference"></a> [global\_module\_reference](#input\_global\_module\_reference) | A reference to the global lacework\_azure\_agentless\_scanning module for this account. | <pre>object({<br> scanning_resource_group_name = string<br> scanning_resource_group_id = string<br> key_vault_id = string<br> key_vault_uri = string<br> key_vault_secret_name = string<br> lacework_account = string<br> lacework_domain = string<br> lacework_integration_name = string<br> storage_account_name = string<br> storage_account_id = string<br> blob_container_name = string<br> prefix = string<br> suffix = string<br> monitored_subscription_role_definition_id = string<br> scanning_subscription_role_definition_id = string<br> sidekick_principal_id = string<br> sidekick_client_id = string<br> included_subscriptions = set(string)<br> excluded_subscriptions = set(string)<br> })</pre> | <pre>{<br> "blob_container_name": "",<br> "excluded_subscriptions": [],<br> "included_subscriptions": [],<br> "key_vault_id": "",<br> "key_vault_secret_name": "",<br> "key_vault_uri": "",<br> "lacework_account": "",<br> "lacework_domain": "",<br> "lacework_integration_name": "",<br> "monitored_subscription_role_definition_id": "",<br> "prefix": "",<br> "scanning_resource_group_id": "",<br> "scanning_resource_group_name": "",<br> "scanning_subscription_role_definition_id": "",<br> "sidekick_client_id": "",<br> "sidekick_principal_id": "",<br> "storage_account_id": "",<br> "storage_account_name": "",<br> "suffix": ""<br>}</pre> | no |
115+
| <a name="input_global_module_reference"></a> [global\_module\_reference](#input\_global\_module\_reference) | A reference to the global lacework\_azure\_agentless\_scanning module for this account. | <pre>object({<br> scanning_resource_group_name = string<br> scanning_resource_group_id = string<br> scanning_subscription_id = string<br> key_vault_id = string<br> key_vault_uri = string<br> key_vault_secret_name = string<br> lacework_account = string<br> lacework_domain = string<br> lacework_integration_name = string<br> storage_account_name = string<br> storage_account_id = string<br> blob_container_name = string<br> prefix = string<br> suffix = string<br> monitored_subscription_role_definition_id = string<br> scanning_subscription_role_definition_id = string<br> sidekick_principal_id = string<br> sidekick_client_id = string<br> included_subscriptions = set(string)<br> excluded_subscriptions = set(string)<br> })</pre> | <pre>{<br> "blob_container_name": "",<br> "excluded_subscriptions": [],<br> "included_subscriptions": [],<br> "key_vault_id": "",<br> "key_vault_secret_name": "",<br> "key_vault_uri": "",<br> "lacework_account": "",<br> "lacework_domain": "",<br> "lacework_integration_name": "",<br> "monitored_subscription_role_definition_id": "",<br> "prefix": "",<br> "scanning_resource_group_id": "",<br> "scanning_resource_group_name": "",<br> "scanning_subscription_id": "",<br> "scanning_subscription_role_definition_id": "",<br> "sidekick_client_id": "",<br> "sidekick_principal_id": "",<br> "storage_account_id": "",<br> "storage_account_name": "",<br> "suffix": ""<br>}</pre> | no |
116116
| <a name="input_image_url"></a> [image\_url](#input\_image\_url) | The container image url for Lacework Agentless Workload Scanning. | `string` | `"sidekickpublic.azurecr.io/sidekick:latest"` | no |
117117
| <a name="input_included_subscriptions"></a> [included\_subscriptions](#input\_included\_subscriptions) | List of subscriptions to be monitored. Must be specified with `integration_level = 'SUBSCRIPTION'`. Set only for global resource. | `set(string)` | `[]` | no |
118118
| <a name="input_integration_level"></a> [integration\_level](#input\_integration\_level) | If we are integrating into a subscription or tenant. Valid values are 'SUBSCRIPTION' or 'TENANT' | `string` | n/a | yes |
@@ -157,6 +157,7 @@ No modules.
157157
| <a name="output_prefix"></a> [prefix](#output\_prefix) | Prefix used to add uniqueness to resource names. |
158158
| <a name="output_scanning_resource_group_id"></a> [scanning\_resource\_group\_id](#output\_scanning\_resource\_group\_id) | Id of the resource group hosting the scanner |
159159
| <a name="output_scanning_resource_group_name"></a> [scanning\_resource\_group\_name](#output\_scanning\_resource\_group\_name) | Name of the resource group hosting the scanner |
160+
| <a name="output_scanning_subscription_id"></a> [scanning\_subscription\_id](#output\_scanning\_subscription\_id) | The subscription ID where scanning resources are deployed |
160161
| <a name="output_scanning_subscription_role_definition_id"></a> [scanning\_subscription\_role\_definition\_id](#output\_scanning\_subscription\_role\_definition\_id) | The id of the scanning subscription role definition |
161162
| <a name="output_sidekick_client_id"></a> [sidekick\_client\_id](#output\_sidekick\_client\_id) | Client id of the managed identity running scanner |
162163
| <a name="output_sidekick_principal_id"></a> [sidekick\_principal\_id](#output\_sidekick\_principal\_id) | The principal id of the user identity used by agentless scanner |

main.tf

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ provider "azurerm" {
99
prevent_deletion_if_contains_resources = false
1010
}
1111
}
12-
/* use the current resource manager subscription if it's not provided, otherwise
13-
extract the subscription id if it's in the fully qualified form ("/subscriptions/xxx"),
14-
otherwise just use the subscription id as it is.
12+
/* Use scanning_subscription_id from either direct input or global_module_reference
13+
Extract the subscription id if it's in the fully qualified form ("/subscriptions/xxx")
1514
*/
16-
subscription_id = var.scanning_subscription_id == "" ? null : try(
15+
subscription_id = var.scanning_subscription_id != "" ? try(
1716
regex("^/subscriptions/([A-Za-z0-9-_]+)$", var.scanning_subscription_id)[0],
1817
var.scanning_subscription_id
18+
) : (
19+
// Regional modules use the scanning_subscription_id from the global module reference
20+
length(var.global_module_reference.scanning_subscription_id) > 0 ? try(
21+
regex("^/subscriptions/([A-Za-z0-9-_]+)$", var.global_module_reference.scanning_subscription_id)[0],
22+
var.global_module_reference.scanning_subscription_id
23+
) : null
1924
)
2025
}
2126

@@ -66,12 +71,12 @@ locals {
6671
storage_account_id = var.global ? azurerm_storage_account.scanning[0].id : var.global_module_reference.storage_account_id
6772

6873
included_subscriptions_local = (var.global
69-
? var.included_subscriptions
70-
: var.global_module_reference.included_subscriptions
74+
? var.included_subscriptions
75+
: var.global_module_reference.included_subscriptions
7176
)
7277
excluded_subscriptions_local = (var.global
73-
? var.excluded_subscriptions
74-
: var.global_module_reference.excluded_subscriptions
78+
? var.excluded_subscriptions
79+
: var.global_module_reference.excluded_subscriptions
7580
)
7681

7782
/* Convert the excluded and included subscriptions to the format required by the Lacework AWLS integration
@@ -81,7 +86,7 @@ locals {
8186
*/
8287
included_subscriptions_list = [for sub in local.included_subscriptions_local : replace(sub, "//subscriptions//", "")]
8388
excluded_subscriptions_list = [for sub in local.excluded_subscriptions_local : replace(sub, "//subscriptions//", "-")]
84-
subscriptions_list = var.integration_level == "SUBSCRIPTION" ? local.included_subscriptions_list : local.excluded_subscriptions_list
89+
subscriptions_list = var.integration_level == "SUBSCRIPTION" ? local.included_subscriptions_list : local.excluded_subscriptions_list
8590

8691
/* Define the scope for the monitored role
8792
- For SUBSCRIPTION integration level, we set the scope to the set of included subscriptions specified by the user
@@ -90,8 +95,8 @@ locals {
9095
root_management_group_scope = ["/providers/Microsoft.Management/managementGroups/${local.tenant_id}"]
9196
monitored_role_scopes = tolist(
9297
var.integration_level == "SUBSCRIPTION"
93-
? local.included_subscriptions_local
94-
: local.root_management_group_scope
98+
? local.included_subscriptions_local
99+
: local.root_management_group_scope
95100
)
96101

97102
environment_variables = {
@@ -117,8 +122,8 @@ locals {
117122
AZURE_CONTAINER_REGION = local.container_region
118123
USE_PUBLIC_IPS = local.use_public_ips
119124
}
120-
environment_variables_as_list = concat([for key, val in local.environment_variables : { name = key, value = val }],
121-
[for obj in var.additional_environment_variables : { name = obj["name"], value = obj["value"] }])
125+
environment_variables_as_list = concat([for key, val in local.environment_variables : { name = key, value = val }],
126+
[for obj in var.additional_environment_variables : { name = obj["name"], value = obj["value"] }])
122127

123128
key_vault_id = var.global ? azurerm_key_vault.lw_orchestrate[0].id : (
124129
length(var.global_module_reference.key_vault_id) > 0 ? var.global_module_reference.key_vault_id : var.key_vault_id
@@ -138,8 +143,8 @@ locals {
138143

139144
custom_network = length(var.custom_network) > 0 ? var.custom_network : (var.regional ? azurerm_subnet.agentless_subnet[0].id : "")
140145

141-
region = lower(replace(var.region, " ", ""))
142-
integration_level = upper(var.integration_level)
146+
region = lower(replace(var.region, " ", ""))
147+
integration_level = upper(var.integration_level)
143148
lacework_integration_name_local = var.global ? var.lacework_integration_name : var.global_module_reference.lacework_integration_name
144149

145150
version_file = "${abspath(path.module)}/VERSION"
@@ -155,7 +160,7 @@ locals {
155160
australiasoutheast = "australiaeast"
156161
}
157162
container_region = lookup(local.unsupported_region_replacements, local.region, local.region)
158-
use_public_ips = var.use_nat_gateway ? "false" : "true"
163+
use_public_ips = var.use_nat_gateway ? "false" : "true"
159164
}
160165

161166
resource "random_id" "uniq" {
@@ -210,7 +215,7 @@ resource "lacework_integration_azure_agentless_scanning" "lacework_cloud_account
210215
scan_stopped_instances = var.scan_stopped_instances
211216
query_text = var.filter_query_text
212217
// The Lacework AWLS integration API expects subscription IDs without the "/subscriptions/" prefix
213-
subscriptions_list = local.subscriptions_list
218+
subscriptions_list = local.subscriptions_list
214219
}
215220

216221
/* **************** General ****************
@@ -238,7 +243,7 @@ resource "azuread_service_principal" "data_loader" {
238243
resource "azuread_service_principal_password" "data_loader" {
239244
count = var.global ? 1 : 0
240245

241-
service_principal_id = azuread_service_principal.data_loader[0].object_id
246+
service_principal_id = azuread_service_principal.data_loader[0].id
242247
end_date_relative = "87600h" // expires in 10 years
243248
}
244249

@@ -398,7 +403,7 @@ resource "azurerm_role_assignment" "storage_sidekick" {
398403
resource "azurerm_role_assignment" "storage_data_loader" {
399404
count = var.global ? 1 : 0
400405

401-
principal_id = azuread_service_principal.data_loader[0].object_id
406+
principal_id = azuread_service_principal.data_loader[0].id
402407
role_definition_name = "Storage Blob Data Reader"
403408
scope = local.storage_account_id
404409
}
@@ -489,12 +494,12 @@ resource "azurerm_subnet_network_security_group_association" "agentless_nsg_asso
489494
count = var.regional && length(var.custom_network) == 0 ? 1 : 0
490495

491496
subnet_id = azurerm_subnet.agentless_subnet[0].id
492-
network_security_group_id = length(var.custom_network_security_group) > 0 ? var.custom_network_security_group: azurerm_network_security_group.agentless_orchestrate[0].id
497+
network_security_group_id = length(var.custom_network_security_group) > 0 ? var.custom_network_security_group : azurerm_network_security_group.agentless_orchestrate[0].id
493498
}
494499

495500
resource "azurerm_public_ip" "agentless_public_ip" {
496501
depends_on = [azurerm_resource_group.scanning_rg]
497-
count = var.regional && var.use_nat_gateway ? 1 : 0
502+
count = var.regional && var.use_nat_gateway ? 1 : 0
498503

499504
name = replace("${local.prefix}-public-ip-${local.region}-${local.suffix}", " ", "-")
500505
location = local.region
@@ -507,11 +512,11 @@ resource "azurerm_public_ip" "agentless_public_ip" {
507512

508513
resource "azurerm_nat_gateway" "agentless_nat_gateway" {
509514
depends_on = [azurerm_resource_group.scanning_rg]
510-
count = var.regional && var.use_nat_gateway ? 1 : 0
515+
count = var.regional && var.use_nat_gateway ? 1 : 0
511516

512-
name = replace("${local.prefix}-nat-gateway-${local.region}-${local.suffix}", " ", "-")
513-
location = local.region
514-
resource_group_name = local.scanning_resource_group_name
517+
name = replace("${local.prefix}-nat-gateway-${local.region}-${local.suffix}", " ", "-")
518+
location = local.region
519+
resource_group_name = local.scanning_resource_group_name
515520

516521
tags = var.tags
517522
}
@@ -526,7 +531,7 @@ resource "azurerm_nat_gateway_public_ip_association" "agentless_ip_association"
526531
resource "azurerm_subnet_nat_gateway_association" "agentless_nat_gateway_association" {
527532
count = var.regional && var.use_nat_gateway ? 1 : 0
528533

529-
subnet_id = length(var.custom_network) > 0 ? var.custom_network : azurerm_subnet.agentless_subnet[0].id
534+
subnet_id = length(var.custom_network) > 0 ? var.custom_network : azurerm_subnet.agentless_subnet[0].id
530535
nat_gateway_id = azurerm_nat_gateway.agentless_nat_gateway[0].id
531536
}
532537

output.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,8 @@ output "excluded_subscriptions" {
103103
value = local.excluded_subscriptions_local
104104
description = "The excluded subscriptions list in global module reference"
105105
}
106+
107+
output "scanning_subscription_id" {
108+
value = data.azurerm_subscription.current.subscription_id
109+
description = "The subscription ID where scanning resources are deployed"
110+
}

variables.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ variable "global_module_reference" {
324324
type = object({
325325
scanning_resource_group_name = string
326326
scanning_resource_group_id = string
327+
scanning_subscription_id = string
327328
key_vault_id = string
328329
key_vault_uri = string
329330
key_vault_secret_name = string
@@ -345,6 +346,7 @@ variable "global_module_reference" {
345346
default = {
346347
scanning_resource_group_name = ""
347348
scanning_resource_group_id = ""
349+
scanning_subscription_id = ""
348350
key_vault_id = ""
349351
key_vault_uri = ""
350352
key_vault_secret_name = ""

versions.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ terraform {
33
required_providers {
44
azuread = {
55
source = "hashicorp/azuread"
6-
version = "~> 2.53.1"
6+
version = "~> 3.4"
77
}
88
azurerm = {
99
source = "hashicorp/azurerm"
10-
version = "~> 3.116.0"
10+
version = "~> 4.37"
1111
}
1212
// include azapi because Azure Container App Jobs isn't yet available as a provider
1313
azapi = {

0 commit comments

Comments
 (0)