How to add Network security group, application security group & custom NIC to existing virtual machine using azure bicep

Satish B 70 Reputation points
2024-01-08T10:11:30.6833333+00:00

How to add Network security group, application security group & custom NIC to existing virtual machine using azure bicep

and also, is azure bicep support migrated virtual machine module?

Azure Virtual Network
Azure Virtual Network
An Azure networking service that is used to provision private networks and optionally to connect to on-premises datacenters.
2,762 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sedat SALMAN 14,180 Reputation points MVP
    2024-01-08T12:32:47.8733333+00:00

    here is an example for you to use but be careful you need to modify it

    // Define the Network Security Group (NSG)
    resource nsg 'Microsoft.Network/networkSecurityGroups@2023-04-01' = {
      name: 'nsgName'
      location: 'location'
      tags: {
        // Your tags here
      }
      properties: {
        // Define your security rules and other properties here
      }
    }
    
    // Define the Application Security Group (ASG)
    resource asg 'Microsoft.Network/applicationSecurityGroups@2023-04-01' = {
      name: 'asgName'
      location: 'location'
      tags: {
        // Your tags here
      }
    }
    
    // Define the Virtual Machine
    resource vm 'Microsoft.Compute/virtualMachines@2020-06-01' = {
      name: 'vmName'
      location: 'location'
      properties: {
        // Other VM properties
        networkProfile: {
          networkInterfaceConfigurations: [
            {
              name: 'nicConfigurationName'
              properties: {
                ipConfigurations: [
                  {
                    name: 'ipConfigName'
                    properties: {
                      // IP configuration properties
                      subnet: {
                        // Subnet reference
                      }
                      privateIPAllocationMethod: 'Dynamic'
                      publicIPAddress: {
                        // Public IP address reference
                      }
                      // Associate the NSG with NIC
                      networkSecurityGroup: {
                        id: nsg.id
                      }
                      // Associate the ASG with NIC
                      applicationSecurityGroups: [
                        {
                          id: asg.id
                        }
                      ]
                    }
                  }
                ]
                // Other NIC properties
              }
            }
          ]
        }
      }
    }
    
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.