Skip to content
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

Core subnets pipeline run #4347

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0487de5
Update Azure RM provider version and refactor subnet IP range filters…
ShakutaiGit Jan 6, 2025
983353b
Add .terraform.lock.hcl for Azure RM provider version 4.14.0
ShakutaiGit Jan 6, 2025
d1a4ab2
Update Terraform provider versions and constraints in .terraform.lock…
ShakutaiGit Jan 6, 2025
e8320b0
hcl
ShakutaiGit Jan 7, 2025
9b2d576
lock file
ShakutaiGit Jan 7, 2025
d7f216a
remove locks files
ShakutaiGit Jan 7, 2025
8ee780f
lock files
ShakutaiGit Jan 7, 2025
b9ef327
Merge branch 'main' into core-network-subnets-change
ShakutaiGit Jan 8, 2025
99d695d
Merge branch 'main' into core-network-subnets-change
ShakutaiGit Jan 8, 2025
b297723
Merge branch 'main' of https://github.com/microsoft/AzureTRE into cor…
ShakutaiGit Feb 2, 2025
6f24989
change log update
ShakutaiGit Feb 3, 2025
dc2c846
version update
ShakutaiGit Feb 3, 2025
9ec2ab3
Add Terraform lock file for Azure providers
ShakutaiGit Feb 3, 2025
a494ead
save the current state
ShakutaiGit Feb 5, 2025
82032b0
migration work without apply
ShakutaiGit Feb 6, 2025
206875a
Disable xtrace for migration script
ShakutaiGit Feb 6, 2025
1d2e90c
remove the change on the lock file.
ShakutaiGit Feb 6, 2025
0837a41
Merge branch 'main' of https://github.com/microsoft/AzureTRE into cor…
ShakutaiGit Feb 6, 2025
648e00d
Implement migration steps for managing private endpoints in Terraform
ShakutaiGit Feb 6, 2025
53ef850
Update private endpoints in migration script
ShakutaiGit Feb 6, 2025
be7aed9
Refactor migration script to not remove old private endpoints and rel…
ShakutaiGit Feb 9, 2025
99d4869
Merge branches 'core-network-subnets-change' and 'main' of https://gi…
ShakutaiGit Feb 9, 2025
7ef995b
lint changes
ShakutaiGit Feb 9, 2025
a376222
bump version to 0.11.24
ShakutaiGit Feb 9, 2025
fc00a2e
Merge branch 'main' of https://github.com/microsoft/AzureTRE into cor…
ShakutaiGit Feb 9, 2025
29f1b99
PR comments addressed
ShakutaiGit Feb 9, 2025
a624f15
Terraform fmt
ShakutaiGit Feb 9, 2025
7c70cd5
Merge branch 'main' into core-subnets-pipeline-run
ShakutaiGit Feb 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ BUG FIXES:
* Windows R version must be 4.1.2 otherwise post install script doesn't update package mirror URL ([#4288](https://github.com/microsoft/AzureTRE/issues/4288))
* Recreate tre_output.json if empty. ([[#4292](https://github.com/microsoft/AzureTRE/issues/4292)])
* Ensure R directory is present before attempting to update package mirror URL ([#4332](https://github.com/microsoft/AzureTRE/pull/4332))
* Upgrade AzureRM Terraform provider from `3.117.0` to `4.14.0`. ([[PR_link](https://github.com/microsoft/AzureTRE/pull/4255/)])
* Subnet definitions are now inline in the `azurerm_virtual_network` resource, and NSG associations are set using `security_group` in each subnet block (no separate `azurerm_subnet_network_security_group_association` needed). ([[PR_link](https://github.com/microsoft/AzureTRE/pull/4255/)])

COMPONENTS:

Expand Down
29 changes: 14 additions & 15 deletions core/terraform/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/terraform/cosmos_mongo.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resource "azurerm_cosmosdb_account" "mongo" {
kind = "MongoDB"
automatic_failover_enabled = false
mongo_server_version = 4.2
ip_range_filter = "${local.azure_portal_cosmos_ips}${var.enable_local_debugging ? ",${local.myip}" : ""}"
ip_range_filter = local.cosmos_ip_filter_set

capabilities {
name = "EnableServerless"
Expand Down
15 changes: 14 additions & 1 deletion core/terraform/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,20 @@ locals {
docker_registry_server = data.azurerm_container_registry.mgmt_acr.login_server

# https://learn.microsoft.com/en-us/azure/cosmos-db/how-to-configure-firewall#allow-requests-from-the-azure-portal
azure_portal_cosmos_ips = "104.42.195.92,40.76.54.131,52.176.6.30,52.169.50.45,52.187.184.26"

azure_portal_cosmos_ips_list = [
"104.42.195.92",
"40.76.54.131",
"52.176.6.30",
"52.169.50.45",
"52.187.184.26"
]

cosmos_ip_filter_set = toset(
var.enable_local_debugging
? concat(local.azure_portal_cosmos_ips_list, [local.myip])
: local.azure_portal_cosmos_ips_list
)

# we define some zones in core despite not used by the core infra because
# it's the easier way to make them available to other services in the system.
Expand Down
2 changes: 1 addition & 1 deletion core/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=3.117.0"
version = "=4.14.0"
}
random = {
source = "hashicorp/random"
Expand Down
105 changes: 69 additions & 36 deletions core/terraform/migrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,25 @@ set -o pipefail
set -o nounset
# set -o xtrace

# Configure AzureRM provider to user Azure AD to connect to storage accounts
get_resource_id() {
local json_data="$1"
local resource_addr="$2"
echo "$json_data" | jq -r --arg addr "$resource_addr" '
def walk_resources:
(.resources[]?),
(.child_modules[]? | walk_resources);
.values.root_module | walk_resources | select(.address==$addr) | .values.id
'
}

# Configure AzureRM provider to use Azure AD to connect to storage accounts
export ARM_STORAGE_USE_AZUREAD=true

# Configure AzureRM backend to user Azure AD to connect to storage accounts
# Configure AzureRM backend to use Azure AD to connect to storage accounts
export ARM_USE_AZUREAD=true
export ARM_USE_OIDC=true

# terraform_wrapper_path="../../devops/scripts/terraform_wrapper.sh"

# This variables are loaded in for us
# These variables are loaded in for us
# shellcheck disable=SC2154
terraform init -input=false -backend=true -reconfigure \
-backend-config="resource_group_name=${TF_VAR_mgmt_resource_group_name}" \
Expand All @@ -24,41 +33,65 @@ terraform init -input=false -backend=true -reconfigure \

echo "*** Migrating TF Resources... ***"

terraform refresh

# get TF state in JSON
terraform_show_json=$(terraform show -json)

# Remove cnab-state legacy state path form state. Needs to be run before refresh, as refresh will fail.
state_store_legacy_path=$(echo "${terraform_show_json}" \
| jq 'select(.values.root_module.resources != null) | .values.root_module.resources[] | select(.address=="azurerm_storage_share.storage_state_path") | .values.id')

if [ -n "${state_store_legacy_path}" ]; then
echo -e "\n\e[96mRemoving legacy state path from TF state\e[0m..."
terraform state rm azurerm_storage_share.storage_state_path
fi

# terraform show might fail if provider schema has changed. Since we don't call apply at this stage a refresh is needed
terraform refresh
# List of resource addresses to remove.
declare -a RESOURCES_TO_REMOVE=(
"module.network.azurerm_subnet_network_security_group_association.bastion"
"module.network.azurerm_subnet_network_security_group_association.app_gw"
"module.network.azurerm_subnet_network_security_group_association.shared"
"module.network.azurerm_subnet_network_security_group_association.web_app"
"module.network.azurerm_subnet_network_security_group_association.resource_processor"
"module.network.azurerm_subnet_network_security_group_association.airlock_processor"
"module.network.azurerm_subnet_network_security_group_association.airlock_notification"
"module.network.azurerm_subnet_network_security_group_association.airlock_storage"
"module.network.azurerm_subnet_network_security_group_association.airlock_events"
"module.network.azurerm_subnet.bastion"
"module.network.azurerm_subnet.azure_firewall"
"module.network.azurerm_subnet.app_gw"
"module.network.azurerm_subnet.web_app"
"module.network.azurerm_subnet.shared"
"module.network.azurerm_subnet.resource_processor"
"module.network.azurerm_subnet.airlock_processor"
"module.network.azurerm_subnet.airlock_notification"
"module.network.azurerm_subnet.airlock_storage"
"module.network.azurerm_subnet.airlock_events"
"module.network.azurerm_subnet.firewall_management"
)

# 1. Check we have a root_module in state
# 2. Grab the Resource ID
# 3. Delete the old resource from state
# 4. Import the new resource type in using the existing Azure Resource ID
migration_is_needed=0
for resource in "${RESOURCES_TO_REMOVE[@]}"; do
resource_id=$(get_resource_id "${terraform_show_json}" "$resource")
if [ -n "$resource_id" ] && [ "$resource_id" != "null" ]; then
migration_is_needed=1
break
fi
done

terraform_show_json=$(terraform show -json)
if [ "$migration_is_needed" -eq 0 ]; then
echo "No old resources found in the state, skipping migration."
exit 0
fi

# example migration
# # azurerm_app_service_plan -> azurerm_service_plan
# core_app_service_plan_id=$(echo "${terraform_show_json}" \
# | jq -r 'select(.values.root_module.resources != null) | .values.root_module.resources[] | select(.address=="azurerm_app_service_plan.core") | .values.id')
# if [ -n "${core_app_service_plan_id}" ]; then
# echo "Migrating ${core_app_service_plan_id}"
# terraform state rm azurerm_app_service_plan.core
# if [[ $(az resource list --query "[?id=='${core_app_service_plan_id}'] | length(@)") == 0 ]];
# then
# echo "The resource doesn't exist on Azure. Skipping importing it back to state."
# else
# terraform import azurerm_service_plan.core "${core_app_service_plan_id}"
# fi
# fi
# remove resources from state
for resource in "${RESOURCES_TO_REMOVE[@]}"; do
resource_id=$(get_resource_id "${terraform_show_json}" "$resource")
if [ -n "$resource_id" ] && [ "$resource_id" != "null" ]; then
terraform state rm "$resource"
else
echo "Resource that supposed to be removed not found in state: ${resource}"
fi
done

echo "*** Migration is done. ***"
# remove & import VNet
vnet_address="module.network.azurerm_virtual_network.core"
vnet_id=$(get_resource_id "${terraform_show_json}" "$vnet_address" "vnet")
if [ -n "${vnet_id}" ] && [ "${vnet_id}" != "null" ]; then
terraform state rm "${vnet_address}"
terraform import "${vnet_address}" "${vnet_id}"
else
echo "VNet resource not found in state: ${vnet_address}"
fi
22 changes: 22 additions & 0 deletions core/terraform/network/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions core/terraform/network/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ locals {
"privatelink.queue.core.windows.net",
"privatelink.table.core.windows.net"
])

subnet_ids_map = { for s in azurerm_virtual_network.core.subnet : s.name => s.id }
}
2 changes: 1 addition & 1 deletion core/terraform/network/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 3.117"
version = ">= 4.14.0"
}
}
}
Loading
Loading