We have a deployment of a VNET with bicep which works fine. Moving to Terraform and there are issues with Azure policy.
We have a policy which denies the creation of subnets with no NSGs. This is fine with Bicep as it seems to create the NSG link to the subnet as an atomic operation. Terraform doesn’t do this – it creates the subnet without an NSG attached and then runs a separate Terraform resource which connects them and so the subnet creation fails because of the policy. Same issue for Route tables.
Any general comment on this? There is no way to defer policy eval until after Terraform has finished and no inline way to force Terraform to do such things as an atomic operation …
2
Answers
Another example of the
azurerm
provider not being adequate and it appears that there is a reason it is done this way and HC don't intend to change this as it breaks other things. So, I reverted to theazapi
provider and which works fine for creating subnets in this scenario as it does atomic creation, along with the NSG/RT link.You can create one or more subnets associated to Network Security Groups (NSG) using the
subnet
block of the azurerm_virtual_network resource: