Azure virtual networks enable Azure resources to securely communicate with each other, which then allow companies to control inbound and outbound traffic using Network Security Groups. Network and application security groups are used to specify inbound and outbound security rules similar to the functionality of a firewall. Configuring a virtual network helps prevent unauthorized access to containers within a container group and is considered best practice.
In Azure Console -
In Terraform -
For current Azure provider versions:
For Azure provider versions prior to v3.16.0:
References:
https://learn.microsoft.com/en-us/azure/container-instances/container-instances-virtual-network-concepts
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_group
https://learn.microsoft.com/en-us/azure/container-instances/container-instances-virtual-network-concepts
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_group#subnet_ids