-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicBlockExample.tf
More file actions
56 lines (51 loc) · 1.94 KB
/
DynamicBlockExample.tf
File metadata and controls
56 lines (51 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
}
}
}
provider "azurerm" {
features {}
}
locals {
location = "westeurope"
}
variable "security_rules" {
type = list(object({
name = string
priority = string
direction = string
access = string
protocol = string
source_port_range = string
destination_port_range = string
source_address_prefix = string
destination_address_prefix = string
}))
}
resource "azurerm_resource_group" "rg" {
name = "RG-TF-DynamicBlockTest2"
location = local.location
}
resource "azurerm_network_security_group" "nsg" {
name = "nsg1"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
dynamic "security_rule" {
for_each = var.security_rules
# iterator = "secrule"
# The iterator argument (optional) sets the name of a temporary variable that represents the current element of the complex value. If omitted, the name of the variable defaults to the label of the dynamic block ("setting" in the example above).
content {
name = security_rule.value["name"]
priority = security_rule.value["priority"]
direction = security_rule.value["direction"]
access = security_rule.value["access"]
protocol = security_rule.value["protocol"]
source_port_range = security_rule.value["source_port_range"]
destination_port_range = security_rule.value["destination_port_range"]
source_address_prefix = security_rule.value["source_address_prefix"]
destination_address_prefix = security_rule.value["destination_address_prefix"]
}
}
}