-
Notifications
You must be signed in to change notification settings - Fork 176
Migrate Azure Firewall and route tables to core configuration #4342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 15 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
762ca46
Add Terraform configuration for Azure Firewall and route tables to mo…
marrobi 49da7fc
Airlock function storage to use manage identity
tamirkamara 83d3f07
version
tamirkamara 5015aae
changelog
tamirkamara 92d47e7
storage permissions
tamirkamara fa16b21
Merge branch 'tamirkamara/function-host-storage-mi' of https://github…
marrobi 57a30df
Fix merge issues.
marrobi 3646280
Merge branch 'main' of https://github.com/microsoft/AzureTRE into mar…
marrobi e517835
remove forced tunneling from shared service
marrobi f942623
Fix linting
marrobi dbd3b15
Merge branch 'main' of https://github.com/microsoft/AzureTRE into mar…
marrobi ff24de2
Update to work with latest changes.
marrobi 9cbf076
Fix linting
marrobi 72fa0da
fix linting
marrobi 917efeb
Update changelog
marrobi c73a127
Remove Firewall SKU from shared services and RP
marrobi 07ebda0
fix linting
marrobi c61ee60
fix linting
marrobi 0918606
Fix PR comments.
marrobi ee4ef36
Merge branch 'main' of https://github.com/microsoft/AzureTRE into mar…
marrobi e2ab94e
Fix migrate script issues
marrobi 4c8dcf1
Merge branch 'main' of https://github.com/microsoft/AzureTRE into mar…
marrobi 9db999a
Merge branch 'main' of https://github.com/microsoft/AzureTRE into mar…
marrobi 9c43f75
Fix merge issues.
marrobi 65ef756
Update policy name and other merge issues.
marrobi fde34db
Check for core resouce gorup before migration.
marrobi 438ad94
Fix linting.
marrobi 3761015
fix linting
marrobi c87a6ac
Set default firewall sku
marrobi 6696d1c
Set script to handle if FIREWALL_SKU is not set.
marrobi 0d7e6a4
Fix script existing if resource does not exist.
marrobi cc14315
Update comment
marrobi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
marrobi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| #!/bin/bash | ||
| # shellcheck disable=SC2154 | ||
|
|
||
| # See remove_state.sh for the purpose of these scripts | ||
| echo "IMPORTING STATE FOR FIREWALL..." | ||
|
|
||
| # check for the existence of the RG. If it's not there it's because we're in CI and building from scratch - we can skip this script | ||
| set +e | ||
| RESOURCE_GROUP_ID="rg-${TRE_ID}" | ||
| if ! az group show -n "$RESOURCE_GROUP_ID"; then | ||
| echo "RG not found, skipping import_state" | ||
| exit 0 | ||
| fi | ||
|
|
||
| set -e | ||
|
|
||
| # shellcheck disable=SC1091 | ||
| source "$(dirname "$0")/../../../devops/scripts/mgmtstorage_enable_public_access.sh" | ||
|
|
||
| # Initialise state for Terraform | ||
| terraform init -input=false -backend=true -reconfigure -upgrade \ | ||
| -backend-config="resource_group_name=${TF_VAR_mgmt_resource_group_name}" \ | ||
| -backend-config="storage_account_name=${TF_VAR_mgmt_storage_account_name}" \ | ||
| -backend-config="container_name=${TF_VAR_terraform_state_container_name}" \ | ||
| -backend-config="key=${TRE_ID}" | ||
|
|
||
| # Import a resource if it exists in Azure but doesn't exist in Terraform | ||
| tf_state_list="$(terraform state list)" | ||
| function import_if_exists() { | ||
| ADDRESS=$1 | ||
| ID=$2 | ||
| CMD=$3 | ||
|
|
||
| # Check if the resource exists in Terraform | ||
| echo "Checking if ${ADDRESS} exists in Terraform state..." | ||
| ESCAPED_ADDRESS=$(printf '%q' "${ADDRESS}") | ||
| TF_RESOURCE_EXISTS=$(echo "$tf_state_list" | grep -q ^"${ESCAPED_ADDRESS}"$; echo $?) | ||
|
|
||
| if [[ ${TF_RESOURCE_EXISTS} -eq 0 ]]; then | ||
| echo "${ADDRESS} already in TF State, ignoring..." | ||
| return | ||
| fi | ||
|
|
||
| # Some resources, e.g. Firewall rules and Diagnostics, don't show up in `az resource show`, | ||
| # so we need a way to set up a custom command for them | ||
| if [[ -z ${CMD} ]]; then | ||
| CMD="az resource show --ids ${ID}" | ||
| fi | ||
| ${CMD} > /dev/null | ||
| AZ_RESOURCE_EXISTS=$? | ||
|
|
||
|
|
||
|
|
||
| # If resource exists in Terraform, it's already managed -- don't do anything | ||
| # If resource doesn't exist in Terraform and doesn't exist in Azure, it will be created -- don't do anything | ||
| # If resource doesn't exist in Terraform but exist in Azure, we need to import it | ||
| if [[ ${TF_RESOURCE_EXISTS} -ne 0 && ${AZ_RESOURCE_EXISTS} -eq 0 ]]; then | ||
| echo "IMPORTING ${ADDRESS} ${ID}" | ||
| terraform import -var "tre_id=${TRE_ID}" -var "location=${LOCATION}" "${ADDRESS}" "${ID}" | ||
| fi | ||
| } | ||
|
|
||
| # Firewall | ||
| import_if_exists module.firewall.azurerm_firewall.fw "/subscriptions/${ARM_SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP_ID}/providers/Microsoft.Network/azureFirewalls/fw-${TRE_ID}" | ||
|
|
||
| # Firewall IPs | ||
| if [[ "${FIREWALL_SKU}" == "Basic" ]]; then | ||
| import_if_exists module.firewall.azurerm_public_ip.fwmanagement[0] "/subscriptions/${ARM_SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP_ID}/providers/Microsoft.Network/publicIPAddresses/pip-fw-management-${TRE_ID}" | ||
| fi | ||
|
|
||
| import_if_exists module.firewall.azurerm_public_ip.fwtransit[0] "/subscriptions/${ARM_SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP_ID}/providers/Microsoft.Network/publicIPAddresses/pip-fw-${TRE_ID}" | ||
|
|
||
| # Firewall policy | ||
| import_if_exists module.firewall.azurerm_firewall_policy.root "/subscriptions/${ARM_SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP_ID}/providers/Microsoft.Network/firewallPolicies/fw-policy-${TRE_ID}" | ||
| import_if_exists module.firewall.azurerm_firewall_policy_rule_collection_group.core \ | ||
| "/subscriptions/${ARM_SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP_ID}/providers/Microsoft.Network/firewallPolicies/fw-policy-${TRE_ID}/ruleCollectionGroups/rcg-core" | ||
|
|
||
|
|
||
| # Diagnostic settings | ||
| import_if_exists module.firewall.azurerm_monitor_diagnostic_setting.firewall \ | ||
| "/subscriptions/${ARM_SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP_ID}/providers/Microsoft.Network/azureFirewalls/fw-${TRE_ID}|diagnostics-fw-${TRE_ID}" \ | ||
| "az monitor diagnostic-settings show --resource /subscriptions/${ARM_SUBSCRIPTION_ID}/resourceGroups/rg-${TRE_ID}/providers/microsoft.network/azureFirewalls/fw-${TRE_ID} --name diagnostics-fw-${TRE_ID}" | ||
|
|
||
| # Route tables | ||
| import_if_exists azurerm_route_table.rt \ | ||
| "/subscriptions/${ARM_SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP_ID}/providers/Microsoft.Network/routeTables/rt-${TRE_ID}" | ||
|
|
||
| # import_if_exists azurerm_subnet_route_table_association.rt_shared_subnet_association \ | ||
| # "/subscriptions/${ARM_SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP_ID}/providers/Microsoft.Network/virtualNetworks/vnet-${TRE_ID}/subnets/SharedSubnet" | ||
|
|
||
| # import_if_exists azurerm_subnet_route_table_association.rt_resource_processor_subnet_association \ | ||
| # "/subscriptions/${ARM_SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP_ID}/providers/Microsoft.Network/virtualNetworks/vnet-${TRE_ID}/subnets/ResourceProcessorSubnet" | ||
|
|
||
| # import_if_exists azurerm_subnet_route_table_association.rt_web_app_subnet_association \ | ||
| # "/subscriptions/${ARM_SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP_ID}/providers/Microsoft.Network/virtualNetworks/vnet-${TRE_ID}/subnets/WebAppSubnet" | ||
|
|
||
| # import_if_exists azurerm_subnet_route_table_association.rt_airlock_processor_subnet_association \ | ||
| # "/subscriptions/${ARM_SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP_ID}/providers/Microsoft.Network/virtualNetworks/vnet-${TRE_ID}/subnets/AirlockProcessorSubnet" | ||
|
|
||
| # import_if_exists azurerm_subnet_route_table_association.rt_airlock_storage_subnet_association \ | ||
| # "/subscriptions/${ARM_SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP_ID}/providers/Microsoft.Network/virtualNetworks/vnet-${TRE_ID}/subnets/AirlockStorageSubnet" | ||
|
|
||
| # import_if_exists azurerm_subnet_route_table_association.rt_airlock_events_subnet_association \ | ||
| # "/subscriptions/${ARM_SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP_ID}/providers/Microsoft.Network/virtualNetworks/vnet-${TRE_ID}/subnets/AirlockEventsSubnet" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| locals { | ||
| core_resource_group_name = "rg-${var.tre_id}" | ||
| firewall_name = "fw-${var.tre_id}" | ||
| firewall_diagnostic_categories_enabled = [ | ||
| "AZFWApplicationRule", | ||
| "AZFWApplicationRuleAggregation", | ||
| "AZFWDnsProxy", | ||
| "AZFWDnsQuery", | ||
| "AZFWFatFlow", | ||
| "AZFWFlowTrace", | ||
| "AZFWIdpsSignature", | ||
| "AZFWInternalFqdnResolutionFailure", | ||
| "AZFWNatRule", | ||
| "AZFWNatRuleAggregation", | ||
| "AZFWNetworkRule", | ||
| "AZFWNetworkRuleAggregation", | ||
| "AZFWThreatIntel" | ||
| ] | ||
|
|
||
| firewall_policy_name = "fw-policy-${var.tre_id}" | ||
|
|
||
| default_firewall_sku = "Standard" | ||
| effective_firewall_sku = coalesce(var.firewall_sku, local.default_firewall_sku) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| terraform { | ||
| # In modules we should only specify the min version | ||
| required_providers { | ||
| azurerm = { | ||
| source = "hashicorp/azurerm" | ||
| version = ">= 3.117" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| output "private_ip_address" { | ||
| value = azurerm_firewall.fw.ip_configuration[0].private_ip_address | ||
| } |
marrobi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.