Skip to content

Commit c7c98d0

Browse files
authored
feat(m365): add parameter to output all ScubaGear files (#20)
1 parent 0b925ef commit c7c98d0

File tree

10 files changed

+62
-32
lines changed

10 files changed

+62
-32
lines changed

m365/README.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Optional::
9393
`tags` (map(string)) [default={}]::: Tags to apply to all resources created. Application is done via policies
9494
`serial_number` (string) [default=01]::: Increment by 1 when re-provisioning with the same resource group name
9595
`image_path` (string) [default=./cisa_logo.png]::: Path to image used for app logo. Displayed in Azure console on installed tenants
96+
`output_all_files` (bool) [default=False]::: If true, will output all files generated by ScubaGear instead of just the ScubaResults.json
9697
Advanced::
9798
`create_app` (bool) [default=True]::: If true, the app will be created. If false, the app will be imported
9899
`prefix_override` (string) [default=None]::: Prefix for resource names. If null, one will be generated from app_name

m365/image/run_container.ps1

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,18 @@ Foreach ($tenantConfig in $(Get-ChildItem 'input\')) {
9191

9292
Write-Output " Starting Upload"
9393
$DatePath = Get-Date -Format "yyyy/MM/dd"
94-
$OutPath = "$($Env:REPORT_OUTPUT)/$($DatePath)/$($ResultsFile.Name)"
94+
if ("true" -eq $Env:OUTPUT_ALL_FILES) {
95+
$InPath = "$($ResultsFile.DirectoryName)\*"
96+
$OutPath = "$($Env:REPORT_OUTPUT)/$($DatePath)/$($org)-$([int]$(Get-Date).TimeOfDay.TotalSeconds)"
97+
}
98+
else {
99+
$InPath = $ResultsFile.FullName
100+
$OutPath = "$($Env:REPORT_OUTPUT)/$($DatePath)/$($ResultsFile.Name)"
101+
}
95102
if ($null -ne $Env:REPORT_SAS) {
96103
$OutPath += "?$($Env:REPORT_SAS)"
97104
}
98-
.\azcopy copy $ResultsFile.FullName $OutPath --output-level essential
105+
.\azcopy copy $InPath $OutPath --output-level essential --recursive
99106
if ($LASTEXITCODE -gt 0) {
100107
throw "Error transferring files"
101108
}
@@ -108,7 +115,7 @@ Foreach ($tenantConfig in $(Get-ChildItem 'input\')) {
108115
Write-Output $_
109116
}
110117

111-
if ($Env:DEBUG_LOG -eq "true") {
118+
if ("true" -eq $Env:DEBUG_LOG) {
112119
Get-Process | Sort-Object -Property WS -Descending | Select-Object -First 10
113120
(Get-Ciminstance Win32_OperatingSystem).FreePhysicalMemory
114121
}

m365/terraform/env/example/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module "scuba_connect" {
1414
container_registry = var.container_registry
1515
input_storage_container_url = var.input_storage_container_url
1616
output_storage_container_url = var.output_storage_container_url
17+
output_all_files = var.output_all_files
1718
tags = var.tags
1819
secondary_app_info = var.secondary_app_info
1920
}

m365/terraform/env/example/provider.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ terraform {
1717
provider "azurerm" {
1818
features {}
1919
subscription_id = "<YOUR_SUBSCRIPTION_UUID>"
20-
environment = "public"
20+
environment = "public"
2121
}
2222

2323
provider "azuread" {

m365/terraform/env/example/variables.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ variable "image_path" {
7979
description = "Path to image used for app logo. Displayed in Azure console on installed tenants"
8080
}
8181

82+
variable "output_all_files" {
83+
default = false
84+
type = bool
85+
description = "If true, will output all files generated by ScubaGear instead of just the ScubaResults.json"
86+
}
87+
8288
### ADVANCED ###
8389

8490
variable "create_app" {
@@ -143,12 +149,12 @@ variable "secondary_app_info" {
143149
Set `environment_to_use` to the environment the manual app is in, either "commericial" or "gcchigh"
144150
EOF
145151
type = object({
146-
app_id = string
152+
app_id = string
147153
environment_to_use = string
148154
})
149155
default = null
150156
validation {
151-
condition = var.secondary_app_info == null ? true : contains(["commercial", "gcchigh"], var.secondary_app_info.environment_to_use)
157+
condition = var.secondary_app_info == null ? true : contains(["commercial", "gcchigh"], var.secondary_app_info.environment_to_use)
152158
error_message = "Valid values for create_mode are (Default, PointInTimeRestore, Replica)"
153159
}
154160
}

m365/terraform/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ module "container" {
6868
schedule_interval = var.schedule_interval
6969
output_storage_container_url = var.output_storage_container_url
7070
output_storage_container_sas = var.output_storage_container_sas
71+
output_all_files = var.output_all_files
7172
input_storage_container_url = var.input_storage_container_url
7273
contact_emails = var.contact_emails
7374
log_analytics_workspace = azurerm_log_analytics_workspace.monitor_law

m365/terraform/modules/container/main.tf

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
data "azurerm_client_config" "current" {}
22

33
locals {
4-
is_us_gov = startswith(lower(var.resource_group.location), "usgov")
4+
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"
66
}
77

@@ -69,23 +69,24 @@ resource "azurerm_container_group" "aci" {
6969
cpu = "1"
7070
memory = var.container_memory_gb
7171
environment_variables = {
72-
"DEBUG_LOG" = "false"
73-
"RUN_TYPE" = each.key
74-
"TENANT_ID" = data.azurerm_client_config.current.tenant_id
75-
"APP_ID" = var.application_client_id
76-
"REPORT_OUTPUT" = local.output_storage_container_url
77-
"TENANT_INPUT" = local.input_storage_container_url
78-
"IS_VNET" = var.subnet_ids != null
79-
"IS_GOV" = local.is_us_gov
80-
"VAULT_NAME" = var.cert_info.vault_name
81-
"CERT_NAME" = var.cert_info.cert_name
82-
"MI_PRINCIPAL_ID" = azurerm_user_assigned_identity.container_mi.principal_id
83-
84-
"SECONDARY_APP_ID" = var.secondary_app_info == null ? null : var.secondary_app_info.app_id
72+
"DEBUG_LOG" = "false"
73+
"RUN_TYPE" = each.key
74+
"TENANT_ID" = data.azurerm_client_config.current.tenant_id
75+
"APP_ID" = var.application_client_id
76+
"REPORT_OUTPUT" = local.output_storage_container_url
77+
"TENANT_INPUT" = local.input_storage_container_url
78+
"IS_VNET" = var.subnet_ids != null
79+
"IS_GOV" = local.is_us_gov
80+
"VAULT_NAME" = var.cert_info.vault_name
81+
"CERT_NAME" = var.cert_info.cert_name
82+
"MI_PRINCIPAL_ID" = azurerm_user_assigned_identity.container_mi.principal_id
83+
"OUTPUT_ALL_FILES" = var.output_all_files
84+
85+
"SECONDARY_APP_ID" = var.secondary_app_info == null ? null : var.secondary_app_info.app_id
8586
"SECONDARY_APP_TLD" = var.secondary_app_info == null ? null : (var.secondary_app_info.environment_to_use == "commercial" ? "com" : "us")
8687
}
8788
secure_environment_variables = {
88-
"REPORT_SAS" = var.output_storage_container_sas
89+
"REPORT_SAS" = var.output_storage_container_sas
8990
}
9091
dynamic "ports" {
9192
for_each = var.subnet_ids == null ? [] : [1]

m365/terraform/modules/container/variables.tf

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ variable "output_storage_container_sas" {
4040
description = "If not null, shared access signature token (query string) to use when writing results to the output storage container. Set this when the container is in an external tenant (the owner of that container will provide the value)."
4141
sensitive = true
4242
}
43+
44+
variable "output_all_files" {
45+
default = false
46+
type = bool
47+
description = "If true, will output all files generated by ScubaGear instead of just the ScubaResults.json"
48+
}
49+
4350
variable "tenants_dir_path" {
4451
default = "./tenants"
4552
type = string
@@ -87,7 +94,7 @@ variable "container_registry" {
8794
username = string
8895
password = string
8996
})
90-
default = null
97+
default = null
9198
description = "Credentials for logging into registry with container image"
9299
}
93100

@@ -122,12 +129,12 @@ variable "secondary_app_info" {
122129
Set `environment_to_use` to the environment the manual app is in, either "commericial" or "gcchigh"
123130
EOF
124131
type = object({
125-
app_id = string
132+
app_id = string
126133
environment_to_use = string
127134
})
128135
default = null
129136
validation {
130-
condition = var.secondary_app_info == null ? true : contains(["commercial", "gcchigh"], var.secondary_app_info.environment_to_use)
137+
condition = var.secondary_app_info == null ? true : contains(["commercial", "gcchigh"], var.secondary_app_info.environment_to_use)
131138
error_message = "Valid values for create_mode are (Default, PointInTimeRestore, Replica)"
132139
}
133140
}

m365/terraform/tagging.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ resource "azurerm_resource_group_policy_assignment" "tagging_assignments" {
2121
}
2222

2323
resource "azurerm_role_assignment" "tag_contributor" {
24-
for_each = var.tags
24+
for_each = var.tags
2525
scope = azurerm_resource_group.rg.id
2626
role_definition_name = "Tag Contributor"
2727
principal_id = azurerm_resource_group_policy_assignment.tagging_assignments[each.key].identity[0].principal_id
2828
}
2929

3030
resource "azurerm_resource_group_policy_remediation" "remediation" {
31-
for_each = var.tags
32-
name = "add-tags-policy-remediation-${each.key}"
33-
resource_group_id = azurerm_resource_group.rg.id
34-
policy_assignment_id = azurerm_resource_group_policy_assignment.tagging_assignments[each.key].id
31+
for_each = var.tags
32+
name = "add-tags-policy-remediation-${each.key}"
33+
resource_group_id = azurerm_resource_group.rg.id
34+
policy_assignment_id = azurerm_resource_group_policy_assignment.tagging_assignments[each.key].id
3535
resource_discovery_mode = "ReEvaluateCompliance"
36-
depends_on = [ azurerm_role_assignment.tag_contributor, module.app, module.container, module.networking ]
36+
depends_on = [azurerm_role_assignment.tag_contributor, module.app, module.container, module.networking]
3737
}

m365/terraform/variables.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ variable "image_path" {
7979
description = "Path to image used for app logo. Displayed in Azure console on installed tenants"
8080
}
8181

82+
variable "output_all_files" {
83+
default = false
84+
type = bool
85+
description = "If true, will output all files generated by ScubaGear instead of just the ScubaResults.json"
86+
}
87+
8288
### ADVANCED ###
8389

8490
variable "create_app" {
@@ -151,12 +157,12 @@ variable "secondary_app_info" {
151157
Set `environment_to_use` to the environment the manual app is in, either "commericial" or "gcchigh"
152158
EOF
153159
type = object({
154-
app_id = string
160+
app_id = string
155161
environment_to_use = string
156162
})
157163
default = null
158164
validation {
159-
condition = var.secondary_app_info == null ? true : contains(["commercial", "gcchigh"], var.secondary_app_info.environment_to_use)
165+
condition = var.secondary_app_info == null ? true : contains(["commercial", "gcchigh"], var.secondary_app_info.environment_to_use)
160166
error_message = "Valid values for create_mode are (Default, PointInTimeRestore, Replica)"
161167
}
162168
}

0 commit comments

Comments
 (0)