Ask Your Question
1

What is the method for incorporating multiple address prefixes within a single admin rule when utilizing Terraform AzureRm?

asked 2021-09-03 11:00:00 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-10-08 04:00:00 +0000

djk gravatar image

The method for incorporating multiple address prefixes within a single admin rule when utilizing Terraform AzureRm is to define the address prefix as a list and use the "any" function to apply the rule to all of the listed prefixes.

For example, the code would look like this:

resource "azurerm_network_security_group" "example" {
  name                = "example-nsg"
  location            = "East US"
  resource_group_name = azurerm_resource_group.example.name

  security_rule {
    name                       = "allow-admin-access"
    priority                   = 100
    direction                  = "Inbound"
    access                     = "Allow"
    protocol                   = "Tcp"
    source_port_range          = "*"
    destination_port_range     = "3389"
    source_address_prefix      = "*"
    destination_address_prefix = any(azurerm_subnet.backend.*.address_prefix)
  }
}

In this example, the "destinationaddressprefix" is defined as "any(azurermsubnet.backend.*.addressprefix)", which applies the rule to all of the address prefixes listed in the "azurerm_subnet.backend" resource.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-09-03 11:00:00 +0000

Seen: 9 times

Last updated: Oct 08 '21