【问题标题】:Terraform Azure network securityTerraform Azure 网络安全
【发布时间】:2018-07-11 00:00:51
【问题描述】:

我正在尝试通过具有多个源地址的 Terraform 为 Azure 中的网络安全组配置网络安全规则。

根据文档 https://www.terraform.io/docs/providers/azurerm/r/network_security_rule.html

但是,我无法使其正常工作,也找不到任何示例:

https://www.terraform.io/docs/providers/azurerm/r/network_security_rule.html#source_address_prefixes

我得到错误:

错误:azurerm_network_security_rule.test0:“source_address_prefix”:未设置必填字段 错误:azurerm_network_security_rule.test0: : 无效或未知密钥:source_address_prefixes

这是我的示例:

resource "azurerm_network_security_rule" "test0" {
name = "RDP"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "TCP"
source_port_range = "*"
destination_port_range = "3389"
source_address_prefixes = "{200.160.200.30,200.160.200.60}"
destination_address_prefix = "VirtualNetwork"
network_security_group_name= "${azurerm_network_security_group.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
}

请告诉我。

谢谢!

【问题讨论】:

  • 你好,你解决了吗?我能帮你更多吗?

标签: azure terraform azure-virtual-network network-security-groups terraform-provider-azure


【解决方案1】:

source_address_prefixes 需要源地址前缀列表。

修改如下:

source_address_prefixes = ["200.160.200.30","200.160.200.60"]

azurerm_network_security_group.test.name也有错误,正确的类型是azurerm_network_security_group.test0.name。以下 tf 文件对我有用。

resource "azurerm_resource_group" "test0" {
  name     = "shuinsg"
  location = "West US"
}

resource "azurerm_network_security_group" "test0" {
  name                = "shuinsgtest"
  location            = "${azurerm_resource_group.test0.location}"
  resource_group_name = "${azurerm_resource_group.test0.name}"
}


resource "azurerm_network_security_rule" "test0" {
name = "RDP"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "TCP"
source_port_range = "*"
destination_port_range = "3389"
source_address_prefixes = ["200.160.200.30","200.160.200.60"]
destination_address_prefix = "VirtualNetwork"
network_security_group_name= "${azurerm_network_security_group.test0.name}"
resource_group_name = "${azurerm_resource_group.test0.name}"
}

这是我的测试结果。

【讨论】:

  • 当你问Azure问题时,最好加标签azure,你会更快得到答案。
  • 感谢@shengbao-shui-msft。我尝试了您在上面粘贴的完全相同的代码,但仍然失败并出现完全相同的错误。 {错误:azurerm_network_security_rule.test0:“source_address_prefix”:未设置必填字段错误:azurerm_network_security_rule.test0::无效或未知密钥:source_address_prefixes}
  • 您使用的是什么版本的 Terraform?我正在运行通过 Chocolatey 安装的 v0.11.2 版本。
  • 我使用v0.11.3。我确信 tf 文件对我有用。
  • 我建议你可以使用最新的 terrform。另外,你的provider "azurerm" 是什么?
【解决方案2】:

“address_prefix”是代表 CIDR 的字符串值,例如10.0.0.0/24。因此,在您的情况下,source_address_prefix = "200.160.200.30/32"destination_address_prefix = "${azurerm_virtual_network.test.address_space.0}" 取决于您要引用的内容。

【讨论】:

  • 感谢@GiulioVian
    但是,我收到以下错误:
    “错误:azurerm_network_security_group.test:security_rule.2.source_address_prefix 必须是单个值,而不是列表”
  • 我没有检查确切的语法(有些资源需要一个列表,有些需要一个单一的值):编辑答案
  • 还尝试了 source_address_prefixes:错误:azurerm_network_security_group.test:security_rule.2:无效或未知密钥:source_address_prefixes
  • @Parvez 根本原因source_address_prefixes 需要一个列表类型。 "" 这是一个字符串类型。看我的回答。
猜你喜欢
  • 2020-04-21
  • 1970-01-01
  • 1970-01-01
  • 2021-05-15
  • 2018-12-15
  • 2021-04-25
  • 2021-06-02
  • 2021-06-10
  • 1970-01-01
相关资源
最近更新 更多