[User Guide] Upgrade from v0.3.3 to v0.4.0 - sblair01/terraform-azurerm-caf-enterprise-scale GitHub Wiki
Overview
As part of upgrade from release 0.3.3 to 0.4.0, the Terraform Module for Cloud Adoption Framework Enterprise-scale includes a number of breaking changes.
This update provides a number of new features, helps keep this module up to date with the latest reference architecture published in the Azure/Enterprise-Scale repository, and to support the latest releases of Terraform and the AzureRM Provider.
Required actions
Anyone using this module should be aware of the following when planning to upgrade from release 0.3.3 to 0.4.0:
-
A select number of policies and roles provided as part of this module will be redeployed. Please carefully review the output of
terraform plan
to ensure there are no issues with any custom configuration within your root module. -
The following library template types will need checking for references to policies as listed in the resource changes section below:
- Archetype Definitions
- Policy Assignments
- Policy Set Definitions
-
All Policy Assignments (and associated Role Assignments where a Managed Identity is required for policies with DeployIfNotExists or Modify effects) will be recreated to support moving these from the
azurerm_policy_assignment
(deprecated) toazurerm_management_group_policy_assignment
resource types. -
Adds provider configuration within the module, allowing creation of resources across multiple Subscriptions. This impacts existing Management and monitoring resources. To avoid the need to re-create these resources, please review the management resources section below. Please also review the provider configuration page for more detail on how you should configure this in your module declaration.
-
Adds new functionality to enable deployment of Network topology and connectivity resources into the connectivity Subscription context. Currently based on the hub & spoke deployment model.
-
Adds new functionality to manage Policy Assignments as part of delivering the Identity and access management
Resource changes
The following changes have been made within the module which may cause issues when using custom archetype definitions:
-
The following Policy Definition changes have been included in the
es_root
archetype definition:Audit-MachineLearning-PrivateEndpointId
addedDeny-MachineLearning-Aks
addedDeny-MachineLearning-Compute-SubnetId
addedDeny-MachineLearning-Compute-VmSize
addedDeny-MachineLearning-ComputeCluster-RemoteLoginPortPublicAccess
addedDeny-MachineLearning-ComputeCluster-Scale
addedDeny-MachineLearning-HbiWorkspace
addedDeny-MachineLearning-PublicAccessWhenBehindVnet
addedDeny-PublicEndpoint-Aks
removedDeny-PublicEndpoint-CosmosDB
removedDeny-PublicEndpoint-KeyVault
removedDeny-PublicEndpoint-MySQL
removedDeny-PublicEndpoint-PostgreSql
removedDeny-PublicEndpoint-Sql
removedDeny-PublicEndpoint-Storage
removedDeploy-Default-Udr
addedDeploy-Diagnostics-ActivityLog
removedDeploy-Diagnostics-AKS
removedDeploy-Diagnostics-Batch
removedDeploy-Diagnostics-DataLakeStore
removedDeploy-Diagnostics-EventHub
removedDeploy-Diagnostics-KeyVault
removedDeploy-Diagnostics-LogicAppsWF
removedDeploy-Diagnostics-RecoveryVault
removedDeploy-Diagnostics-SearchServices
removedDeploy-Diagnostics-ServiceBus
removedDeploy-Diagnostics-SQLDBs
removedDeploy-Diagnostics-StreamAnalytics
removedDeploy-DNSZoneGroup-For-Blob-PrivateEndpoint
removedDeploy-DNSZoneGroup-For-File-PrivateEndpoint
removedDeploy-DNSZoneGroup-For-KeyVault-PrivateEndpoint
removedDeploy-DNSZoneGroup-For-Queue-PrivateEndpoint
removedDeploy-DNSZoneGroup-For-Sql-PrivateEndpoint
removedDeploy-DNSZoneGroup-For-Table-PrivateEndpoint
removedDeploy-HUB
removedDeploy-LA-Config
removedDeploy-Log-Analytics
removedDeploy-vHUB
removedDeploy-vNet
removedDeploy-vWAN
removed
-
The following Policy Set Definition changes have been included in the
es_root
archetype definition:Deny-PublicEndpoints
replaced withDeny-PublicPaaSEndpoints
Deploy-Diag-LogAnalytics
replaced withDeploy-Diagnostics-LogAnalytics
Deploy-Private-DNS-Zones
added
-
The following Policy Assignment changes have been included
es_connectivity
archetype definition:Enable-DDoS-VNET
added
-
The following Policy Assignment changes have been included
es_corp
archetype definition:Deny-Public-Endpoints
addedDeploy-Private-DNS-Zones
added
-
The following Policy Assignment changes have been included
es_identity
archetype definition:Deny-Public-IP
addedDeny-RDP-From-Internet
addedDeny-Subnet-Without-Nsg
addedDeploy-VM-Backup
added
-
The following Policy Assignment changes have been included
es_landing_zones
archetype definition:Deny-http-Ingress-AKS
removed and replaced byEnforce-AKS-HTTPS
Deploy-SQL-Security
removedDeploy-SQL-Threat
addedEnable-DDoS-VNET
addedEnforce-TLS-SSL
added
NOTE: All references to resource names are Case Sensitive. Failure to use the correct case will result in an
Invalid index
error when runningterraform plan
, such as the following example:
Error: Invalid index
on ../../modules/archetypes/locals.policy_definitions.tf line 82, in locals:
82: template = local.archetype_policy_definitions_map[policy]
|----------------
| local.archetype_policy_definitions_map is object with 100 attributes
The given key does not identify an element in this collection value.
azurerm_policy_assignment
Resource type: All azurerm_policy_assignment
resources have been replaced by the azurerm_management_group_policy_assignment
resource type.
Please see the next section for a list of further changes.
azurerm_management_group_policy_assignment
Resource type: All azurerm_policy_assignment
resources have been replaced by the azurerm_management_group_policy_assignment
resource type.
In addition to the resource type change, the following Policy Assignment changes are included in this update:
Deny-http-Ingress-AKS
has been renamed toEnforce-AKS-HTTPS
Deny-IP-Forwarding
updated display name and description fieldsDeny-Priv-Containers-AKS
updated display name and description fieldsDeny-Priv-Escalation-AKS
updated display name and description fieldsDeny-Public-Endpoints
addedDeny-Public-IP
addedDeny-RDP-From-Internet
updated display name and description fieldsDeny-Storage-http
updated display name and description fieldsDeny-Subnet-Without-Nsg
updated display name and description fieldsDeny-Subnet-Without-Udr
updated display name and description fieldsDeploy-AKS-Policy
updated display name and description fieldsDeploy-ASC-Configuration
added (replacesDeploy-ASC-Defender
)Deploy-Private-DNS-Zones
added (still in development)Deploy-SQL-DB-Auditing
updated display name and description fieldsDeploy-SQL-Threat
addedDeploy-VM-Backup
updated display name and description fieldsDeploy-VM-Monitoring
updated display name and description fieldsDeploy-VMSS-Monitoring
updated display name and description fieldsDeploy-AzActivity-Log
updated to use new built-in Policy DefinitionDeploy-Log-Analytics
updated to use new built-in Policy DefinitionDeploy-Resource-Diag
updated to use new customDeploy-Diagnostics-LogAnalytics
Policy Set DefinitionEnable-DDoS-VNET
addedEnforce-TLS-SSL
added
azurerm_policy_definition
Resource type: All Policy Definition templates were updated to the latest apiVersion
of 2021-06-01
, although no impact as Terraform uses the Go SDK for interaction with Azure APIs.
A number of Policy Definition description
fields were also updated, which will result in an in-place update of these.
The following Policy Definition changes are included in this update:
Append-AppService-latestTLS
has been updated fromIndexed
toAll
for themode
attribute.Audit-MachineLearning-PrivateEndpointId
addedDeny-MachineLearning-Aks
addedDeny-MachineLearning-Compute-SubnetId
addedDeny-MachineLearning-Compute-VmSize
addedDeny-MachineLearning-ComputeCluster-RemoteLoginPortPublicAccess
addedDeny-MachineLearning-ComputeCluster-Scale
addedDeny-MachineLearning-HbiWorkspace
addedDeny-MachineLearning-PublicAccessWhenBehindVnet
addedDeploy-Default-Udr
addedDeny-PublicEndpoint-Aks
removedDeny-PublicEndpoint-CosmosDB
removedDeny-PublicEndpoint-KeyVault
removedDeny-PublicEndpoint-MySQL
removedDeny-PublicEndpoint-PostgreSql
removedDeny-PublicEndpoint-Sql
removedDeny-PublicEndpoint-Storage
removedDeny-Subnet-Without-Nsg
now includes a newexcludedSubnets
parameter to allow exclusions (default value =["GatewaySubnet", "AzureFirewallSubnet", "AzureFirewallManagementSubnet"]
)Deny-Subnet-Without-Udr
now includes a newexcludedSubnets
parameter to allow exclusions (default value =["AzureBastionSubnet"]
)Deny-VNET-Peer-Cross-Sub
has been updated fromIndexed
toAll
for themode
attribute.Deny-VNet-Peering
has been updated fromIndexed
toAll
for themode
attribute.Deploy-Default-Udr
addedDeploy-Diagnostics-ActivityLog
removedDeploy-Diagnostics-AKS
removedDeploy-Diagnostics-Batch
removedDeploy-Diagnostics-DataLakeStore
removedDeploy-Diagnostics-EventHub
removedDeploy-Diagnostics-KeyVault
removedDeploy-Diagnostics-LogicAppsWF
removedDeploy-Diagnostics-RecoveryVault
removedDeploy-Diagnostics-SearchServices
removedDeploy-Diagnostics-ServiceBus
removedDeploy-Diagnostics-SQLDBs
removedDeploy-Diagnostics-StreamAnalytics
removedDeploy-DNSZoneGroup-For-Blob-PrivateEndpoint
removedDeploy-DNSZoneGroup-For-File-PrivateEndpoint
removedDeploy-DNSZoneGroup-For-KeyVault-PrivateEndpoint
removedDeploy-DNSZoneGroup-For-Queue-PrivateEndpoint
removedDeploy-DNSZoneGroup-For-Sql-PrivateEndpoint
removedDeploy-DNSZoneGroup-For-Table-PrivateEndpoint
removedDeploy-HUB
removedDeploy-LA-Config
removedDeploy-Log-Analytics
removedDeploy-vHUB
removedDeploy-vNet
removedDeploy-VNET-HubSpoke
update with newparameters
andpolicyRule
configurationDeploy-vWAN
removed
azurerm_policy_set_definition
Resource type: All Policy Set Definition templates were updated to the latest apiVersion
of 2021-06-01
, although no impact as Terraform uses the Go SDK for interaction with Azure APIs.
A number of Policy Set Definition description
fields were also updated, which will result in an in-place update of these.
The following Policy Definition changes are included in this update:
Deny-PublicEndpoints
renamed toDeny-PublicPaaSEndpoints
and updated with new configuration to reflect Policy Definition updatesDeploy-Diag-LogAnalytics
renamed toDeploy-Diagnostics-LogAnalytics
and updated with new configuration to reflect Policy Definition updatesDeploy-Private-DNS-Zones
addedEnforce-Encryption-CMK
updated to replace invalid unicode (whitespace) character
Management resources
As part of enabling support for multiple providers within the module to allow resources to be deployed to multiple Subscriptions within a single module declaration, it has been necessary to rename some resources within the module. These are all resources relating to the management solution within the module.
The following resources have been renamed:
v0.3.x | v0.4.x |
---|---|
azurerm_automation_account.enterprise_scale[*] | azurerm_automation_account.management[*] |
azurerm_log_analytics_linked_service.enterprise_scale[*] | azurerm_log_analytics_linked_service.management[*] |
azurerm_log_analytics_solution.enterprise_scale[*] | azurerm_log_analytics_solution.management[*] |
azurerm_log_analytics_workspace.enterprise_scale[*] | azurerm_log_analytics_workspace.management[*] |
azurerm_resource_group.enterprise_scale[*] | azurerm_resource_group.management[*] |
This was necessary to allow the module to support deploying resources into different Subscriptions using dedicated providers for the core
, management
, and connectivity
capabilities.
NOTE: The
identity
capability doesn't deploy any resources, as it configures Azure Policy on the Identity Management Group only. As such,identity
doesn't have a dedicated provider.
To prevent the need to redeploy these resources, you can simply run the terraform state mv
command to move each updated resource within the state file before running terraform plan
and terraform apply
using the updated module version.
The following PowerShell script can be used to assist with this process, using a RegEx pattern to extract a list of the resources which should be updated, and then moving them to the target name:
[regex]$pattern = "(?<=module.([^.]+).(azurerm_resource_group|azurerm_log_analytics_workspace|azurerm_automation_account|azurerm_log_analytics_linked_service|azurerm_log_analytics_solution).)enterprise_scale"
[array]$(terraform state list) | ForEach-Object {
if ($pattern.IsMatch($_)) {
$newName = $pattern.Replace($_, "management")
Write-Host "Found resource to move..."
Write-Host " - Current resource name : $($_)"
Write-Host " - New resource name : $($newName)"
# Comment out the following line to check the script is proposing the expected resource moves.
terraform state mv $($_ -replace '"', '\"') $($newName -replace '"', '\"')
}
}
IMPORTANT: Whilst every effort has been made to ensure this script works correctly in a test environment, it may behave differently in your environment. Therefore we strongly recommend to backup your Terraform State files before attempting to run/use this script. As described in the MIT license associated with this repository, this script is provided as-is with no warranty or liability associated with its use.
Unfortunately it is not possible to take this approach with the azurerm_policy_assignment
(deprecated) resources, as these are being changed to a different resource type. As such, these resources will be redeployed as part of the upgrade process.
To provide consistency across Connectivity
, Identity
, and Management
resource configuration, the [currently undocumented] configure_management_resources.advanced.custom_settings_by_resource_type
configuration object has also been updated to follow a consistent schema.
Outputs
In line with the changes above, the module outputs have also been restructured to better reflect the resource naming.
This includes:
- Management Groups are now output by the actual resource name (i.e.
level_1
,level_2
,level_3
,level_4
,level_5
,level_6
instead ofenterprise_scale
) - Additional outputs are added to reflect the updated
management
resources and newconnectivity
resources.
Next steps
Take a look at the latest User Guide documentation and our Examples to understand the latest module configuration options, and review your implementation against the changes documented on this page.