For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/ansible-azure-security-group-is-not-configured.md.
A documentation index is available at /llms.txt.
A subnet without an associated Network Security Group (NSG) lacks network-level access controls, increasing exposure to unauthorized access and enabling lateral movement between resources.
For Ansible azure_rm_subnet resources (modules azure.azcollection.azure_rm_subnet and azure_rm_subnet), the security_group or security_group_name property must be defined and set to a non-empty value. Resources that omit these properties or set them to null/empty strings are flagged. Ensure the value references the appropriate NSG (name or ID) for your environment.
Secure configuration example:
- name:Create subnet with NSGazure.azcollection.azure_rm_subnet:resource_group:my-rgvirtual_network:my-vnetname:my-subnetaddress_prefix:10.0.1.0/24security_group:my-nsg
Compliant Code Examples
#this code is a correct code for which the query should not find any result- name:Create a subnetazure_rm_subnet:resource_group:myResourceGroupvirtual_network_name:myVirtualNetworkname:mySubnetaddress_prefix_cidr:10.1.0.0/24security_group:mySecurityGroup
Non-Compliant Code Examples
#this is a problematic code where the query should report a result(s)- name:Create a subnet1azure_rm_subnet:resource_group:myResourceGroup1virtual_network_name:myVirtualNetwork1name:mySubnet1address_prefix_cidr:"10.1.0.0/24"- name:Create a subnet2azure_rm_subnet:resource_group:myResourceGroup2virtual_network_name:myVirtualNetwork2name:mySubnet2address_prefix_cidr:"10.1.0.0/24"security_group:- name:Create a subnet3azure_rm_subnet:resource_group:myResourceGroup3virtual_network_name:myVirtualNetwork3name:mySubnet3address_prefix_cidr:"10.1.0.0/24"security_group_name:- name:Create a subnet4azure_rm_subnet:resource_group:myResourceGroup4virtual_network_name:myVirtualNetwork4name:mySubnet4address_prefix_cidr:"10.1.0.0/24"security_group:""- name:Create a subnet5azure_rm_subnet:resource_group:myResourceGroup5virtual_network_name:myVirtualNetwork5name:mySubnet5address_prefix_cidr:"10.1.0.0/24"security_group_name:""
1
2
rulesets:- Ansible / Azure # Rules to enforce / Azure.
Request a personalized demo
Get Started with Datadog
Ask AI
AI-generated responses may be inaccurate. Verify important info.