Skip to content

Commit

Permalink
Merge pull request #66 from hmcts/DTSPO-18619-windows
Browse files Browse the repository at this point in the history
DTSPO-18661 -  windows - set tags and allow xdr environment
  • Loading branch information
cpareek authored Aug 30, 2024
2 parents bd12923 + b01625e commit 71e96da
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ A virtual machine or virtual machine scale set.
| <a name="input_virtual_machine_id"></a> [virtual\_machine\_id](#input\_virtual\_machine\_id) | Virtual machine resource id. | `string` | `null` | no |
| <a name="input_virtual_machine_scale_set_id"></a> [virtual\_machine\_scale\_set\_id](#input\_virtual\_machine\_scale\_set\_id) | Virtual machine scale set resource id. | `string` | `null` | no |
| <a name="input_virtual_machine_type"></a> [virtual\_machine\_type](#input\_virtual\_machine\_type) | vm or vmss. | `string` | n/a | yes |
| <a name="input_xdr_env"></a> [xdr\_env](#input\_xdr\_env) | Set environment for XDR Agent to make sure which environment it should go to, defaults to prod | `string` | `"prod"` | no |
| <a name="input_xdr_tags"></a> [xdr\_tags](#input\_xdr\_tags) | XDR specific Tags | `string` | `""` | no |

## Outputs
Expand Down
4 changes: 2 additions & 2 deletions run_command.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ resource "azurerm_virtual_machine_extension" "azure_vm_run_command" {
STORAGE_ACCOUNT_KEY = var.run_command_sa_key
RUN_XDR_COLLECTOR = var.run_xdr_collector ? "true" : "false"
RUN_XDR_AGENT = var.run_xdr_agent ? "true" : "false"
ENV = var.env == "prod" ? var.env : "nonprod"
ENV = var.xdr_env == "prod" ? var.xdr_env : "nonprod"
XDR_TAGS = local.xdr_tags_list
})) }) : jsonencode({ script = compact(tolist([templatefile("${path.module}/scripts/windows_run_script.ps1", {
STORAGE_ACCOUNT_KEY = var.run_command_sa_key
RUN_CIS = var.rc_script_file == "scripts/windows_cis.ps1" || var.run_cis ? "true" : "false"
RUN_XDR_COLLECTOR = var.run_xdr_collector ? "true" : "false"
RUN_XDR_AGENT = var.run_xdr_agent ? "true" : "false"
ENV = var.env == "prod" ? var.env : "nonprod"
ENV = var.xdr_env == "prod" ? var.xdr_env : "nonprod"
XDR_TAGS = local.xdr_tags_list
})]))
})
Expand Down
8 changes: 4 additions & 4 deletions scripts/linux_run_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ install_agent() {
if [[ "$OS_TYPE" == *"Red Hat Enterprise Linux"* ]]; then

# Download conf file
local BLOB_NAME="${ENV}/agent-HMCTS_Linux_rpm/cortex.conf"
local BLOB_NAME="${ENV}/${ENV}_agent-HMCTS_Linux_rpm_8.5.0.125392/cortex.conf"
local LOCAL_FILE_PATH="XDR_DOWNLOAD/cortex.conf"
download_blob "$STORAGE_ACCOUNT_NAME" "$SA_KEY" "$CONTAINER_NAME" "$BLOB_NAME" "$LOCAL_FILE_PATH"
sudo echo "$STRING_TO_APPEND" >> $LOCAL_FILE_PATH
sudo mkdir -p /etc/panw
sudo cp $LOCAL_FILE_PATH /etc/panw/

# Install agent
local BLOB_NAME="${ENV}/agent-HMCTS_Linux_rpm_8.5.0.125392/cortex-8.5.0.125392.rpm"
local BLOB_NAME="${ENV}/${ENV}_agent-HMCTS_Linux_rpm_8.5.0.125392/cortex-8.5.0.125392.rpm"
local LOCAL_FILE_PATH="XDR_DOWNLOAD/cortexagent.rpm"
download_blob "$STORAGE_ACCOUNT_NAME" "$SA_KEY" "$CONTAINER_NAME" "$BLOB_NAME" "$LOCAL_FILE_PATH"
rpm -qa | grep -i cortex-agent || rpm -Uh $LOCAL_FILE_PATH
Expand All @@ -106,15 +106,15 @@ install_agent() {
else

# Download conf file
local BLOB_NAME="${ENV}/agent-HMCTS_Linux_deb/cortex.conf"
local BLOB_NAME="${ENV}/${ENV}_agent-HMCTS_Linux_deb_8.5.0.125392/cortex.conf"
local LOCAL_FILE_PATH="XDR_DOWNLOAD/cortex.conf"
download_blob "$STORAGE_ACCOUNT_NAME" "$SA_KEY" "$CONTAINER_NAME" "$BLOB_NAME" "$LOCAL_FILE_PATH"
sudo echo "$STRING_TO_APPEND" >> $LOCAL_FILE_PATH
sudo mkdir -p /etc/panw
sudo cp $LOCAL_FILE_PATH /etc/panw/

# Install agent
local BLOB_NAME="${ENV}/agent-HMCTS_Linux_deb_8.5.0.125392/cortex-8.5.0.125392.deb"
local BLOB_NAME="${ENV}/${ENV}_agent-HMCTS_Linux_deb_8.5.0.125392/cortex-8.5.0.125392.deb"
local LOCAL_FILE_PATH="XDR_DOWNLOAD/cortexagent.deb"
download_blob "$STORAGE_ACCOUNT_NAME" "$SA_KEY" "$CONTAINER_NAME" "$BLOB_NAME" "$LOCAL_FILE_PATH"
dpkg -l | grep -i cortex-agent || dpkg -i $LOCAL_FILE_PATH
Expand Down
4 changes: 2 additions & 2 deletions scripts/windows_run_script.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ function Install-AGENT {
$storageAccountName = "cftptlintsvc"
$storageAccountKey = "${STORAGE_ACCOUNT_KEY}"
$containerName = "xdr-collectors"
$blobName = "${ENV}/agent-HMCTS_Windows_x64_agent.msi"
$blobName = "${ENV}/${ENV}_agent-HMCTS_Windows_x64_agent.msi"
$destinationPath = "C:\Temp\Cortex_XDR_8_4_0\HMCTS_Windows_x64_agent.msi"

$tempFolder= "C:\Temp"
$agentLogPath = "C:\Temp\Cortex_XDR_8_4_0\xdr_install.txt"
$folderPath = "C:\Temp\Cortex_XDR_8_4_0"
$endpointTags = "hmcts,server"
$endpointTags = "${XDR_TAGS}"

$arguments = "/i `"$destinationPath`" /qn /l*v `"$agentLogPath`" ENDPOINT_TAGS=`"$endpointTags`""

Expand Down
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,8 @@ variable "run_xdr_agent" {
default = false
description = "Install XDR agents using run command script?"
}
variable "xdr_env" {
description = "Set environment for XDR Agent to make sure which environment it should go to, defaults to prod"
type = string
default = "prod"
}

0 comments on commit 71e96da

Please sign in to comment.