2

In the Source and Destination columns, VirtualNetwork, AzureLoadBalancer, and Internet are service tags, rather than IP addresses. How do i create this using terraform?

I am trying to create NSG on azure using terraform. While creating nsg security rules fields like source, source service tags and destination field is mandatory for creating nsg. How do i create this field using terraform ?

mikeknows
  • 105
  • 3
  • 13

1 Answers1

2

You could see source_address_prefix or destination_address_prefix in the Argument Reference. Tags such as ‘VirtualNetwork’, ‘AzureLoadBalancer’ and ‘Internet’ can also be used.

enter image description here

For example, you just need to add the specific service tag in the source_address_prefix and destination_address_prefix field.

 # VirtualNetwork
   security_rule {
     name                       = "RDP"
     priority                   = 300
     direction                  = "Inbound"
     access                     = "Allow"
     protocol                   = "Tcp"
     source_port_range          = "*"
     destination_port_range     = "80"
     source_address_prefix      = "VirtualNetwork"
     destination_address_prefix = "VirtualNetwork"
   }
#AppService
     security_rule {
     name                       = "SQL"
     priority                   = 310
     direction                  = "Inbound"
     access                     = "Allow"
     protocol                   = "Tcp"
     source_port_range          = "*"
     destination_port_range     = "80"
     source_address_prefix      = "AppService"
     destination_address_prefix = "*"
   }

result enter image description here

Nancy
  • 26,865
  • 3
  • 18
  • 34
  • source_address_prefix = "Service Tag" then what is the reference for source service tags field ? – mikeknows Jul 15 '20 at 06:57
  • I have attached a screenshot , i want to create similar fields using terraform – mikeknows Jul 15 '20 at 07:01
  • just need to add the specific service tag in the source_address_prefix and destination_address_prefix field. – Nancy Jul 15 '20 at 07:06
  • So we have to only use source_address_prfix and destination_address_prefix parameters? does that means we can ignore the first field source as shown in screenshot? will terraform autopopulate the source field as service tag? – mikeknows Jul 15 '20 at 07:26
  • Yes, just ignore it. You can see expected result on my screenshot? – Nancy Jul 15 '20 at 07:27
  • Then you should accept it as an answer refer to [this](https://stackoverflow.com/help/someone-answers). – Nancy Jul 15 '20 at 09:57