Skip to content

Commit 322e163

Browse files
authored
feat(m365): add separate directory for adhoc scans (#21)
1 parent c7c98d0 commit 322e163

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

m365/image/run_container.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ $Env:AZCOPY_ACTIVE_DIRECTORY_ENDPOINT = if ($Env:IS_GOV -eq "true") {"https://lo
5858
Invoke-SCuBA -Version
5959

6060
Write-Output "Grabbing tenant config files"
61-
.\azcopy copy "$Env:TENANT_INPUT/*" 'input' --output-level essential
61+
New-Item -Path "input" -ItemType Directory | Out-Null
62+
.\azcopy copy "$Env:TENANT_INPUT/*" 'input' --include-pattern "*.yaml;*.yml;*.json" --output-level essential
6263
if ($LASTEXITCODE -gt 0) {
6364
throw "Error reading config files"
6465
}

m365/terraform/modules/container/main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ data "azurerm_client_config" "current" {}
33
locals {
44
is_us_gov = startswith(lower(var.resource_group.location), "usgov")
55
aad_endpoint = local.is_us_gov ? "https://login.microsoftonline.us" : "https://login.microsoftonline.com"
6+
container_types = toset(["scheduled", "adhoc"])
67
}
78

89
resource "azurerm_user_assigned_identity" "container_mi" {
@@ -33,7 +34,7 @@ resource "azurerm_key_vault_access_policy" "mi_kv_access" {
3334
# If "Private", a port must be opened on the container. This is dictated by Azure's APIs
3435
# The open port is still within the vnet, so nothing is exposed externally
3536
resource "azurerm_container_group" "aci" {
36-
for_each = toset(["scheduled", "adhoc"])
37+
for_each = local.container_types
3738
name = "${var.resource_prefix}-${each.key}-container"
3839
location = var.resource_group.location
3940
resource_group_name = var.resource_group.name
@@ -74,7 +75,7 @@ resource "azurerm_container_group" "aci" {
7475
"TENANT_ID" = data.azurerm_client_config.current.tenant_id
7576
"APP_ID" = var.application_client_id
7677
"REPORT_OUTPUT" = local.output_storage_container_url
77-
"TENANT_INPUT" = local.input_storage_container_url
78+
"TENANT_INPUT" = "${local.input_storage_container_url}/${each.key}"
7879
"IS_VNET" = var.subnet_ids != null
7980
"IS_GOV" = local.is_us_gov
8081
"VAULT_NAME" = var.cert_info.vault_name

m365/terraform/modules/container/storage.tf

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,30 @@ resource "azurerm_storage_container" "input" {
6060
container_access_type = "private"
6161
}
6262

63+
resource "azurerm_storage_blob" "keep_files" {
64+
for_each = local.container_types
65+
name = "${each.key}/.keep"
66+
storage_account_name = azurerm_storage_account.storage[0].name
67+
storage_container_name = azurerm_storage_container.input[0].name
68+
type = "Block"
69+
source_content = "File used for keeping directory structure in absence of config files"
70+
71+
lifecycle {
72+
ignore_changes = [
73+
cache_control
74+
]
75+
}
76+
}
77+
78+
6379
# Blobs containing configuration for each tenant
6480
resource "azurerm_storage_blob" "tenants" {
65-
for_each = fileset(var.tenants_dir_path, "*")
81+
for_each = { for typeFile in setproduct(local.container_types, fileset(var.tenants_dir_path, "*")): "${typeFile[0]}/${typeFile[1]}" => typeFile[1] }
6682
name = each.key
6783
storage_account_name = azurerm_storage_account.storage[0].name
6884
storage_container_name = azurerm_storage_container.input[0].name
6985
type = "Block"
70-
source = "${var.tenants_dir_path}/${each.key}"
86+
source = "${var.tenants_dir_path}/${each.value}"
7187

7288
lifecycle {
7389
ignore_changes = [

0 commit comments

Comments
 (0)