首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误::不支持的属性。此对象没有名为"nsg_name“的属性。

错误::不支持的属性。此对象没有名为"nsg_name“的属性。
EN

Stack Overflow用户
提问于 2022-04-05 06:09:53
回答 1查看 1.3K关注 0票数 -1
代码语言:javascript
复制
│ Error: Unsupported attribute
│
│   on nsgs.tf line 27, in resource "azurerm_network_security_rule" "example":
│   27:   network_security_group_name = module.nsg-networkcore.nsg_name
│     ├────────────────
│     │ module.nsg-networkcore is a object, known only after apply
│
│ This object does not have an attribute named "nsg_name".

运行TF应用时创建的所有(网络安全规则除外)

样板

代码语言:javascript
复制
        |_ providers.tf
        |_ locals.tf
        |_ resource_groups.tf
        |_ networking_vnets.tf
        |_ nsgs.tf
        |_ subnets.tf
        |_ terraform.tfvars
        |_ variables.tf
    
    modules
    |_ resource-group
              |_ main.tf
              |_ outputs.tf
              |_ variables.tf

    |_ virtual-network
              |_ main.tf
              |_ outputs.tf
              |_ variables.tf

          |_ subnet
              |_ main.tf
              |_ outputs.tf
              |_ variables.tf

          |_ nsg
              |_ main.tf
              |_ outputs.tf
              |_ variables.tf

modules/terraform-azure-module-resourcegroup/main.tf

代码语言:javascript
复制
resource "azurerm_resource_group" "rg" {
  name     = var.resource_group_name
  location = var.location
  tags     = var.tags
}

modules/terraform-azure-module-resourcegroup/outputs.tf

代码语言:javascript
复制
# Output Variables of the module

output "resource_group_name" {
  value       = azurerm_resource_group.rg.name
  description = "name of resource group"
}

output "location" {
  value       = azurerm_resource_group.rg.location
  description = "location of resource group"
}

modules/terraform-azure-module-resourcegroup/variables.tf

代码语言:javascript
复制
# Input Variables of the module

variable "resource_group_name" {
  type        = string
  description = "name of resource group"
}

variable "location" {
  type        = string
  description = "location of resource group"
}

variable "tags" {
  type    = map(any)
  default = {}
}

modules/terraform-azure-module-network/virtual-network/main.tf

代码语言:javascript
复制
# Create the Virtual Network
resource "azurerm_virtual_network" "vnet" {
  name                = var.vnet_name
  location            = var.vnet_location
  resource_group_name = var.resource_group_name
  address_space       = var.vnet_address_space
  dns_servers         = var.dns_servers
}

modules/terraform-azure-module-network/virtual-network/outputs.tf

代码语言:javascript
复制
 # Vnet Outputs

output "vnet_id" {
  value       = azurerm_virtual_network.vnet.id
  description = "Virutal Network id"
}

output "vnet_name" {
  description   = "The Name of the newly created vNet"
  value         = azurerm_virtual_network.vnet.name
}

output "vnet_location" {
  description   = "The location of the newly created vNet"
  value         = azurerm_virtual_network.vnet.location
}

output "vnet_address_space" {
  value       = azurerm_virtual_network.vnet.address_space
  description = "Virutal Network address_space"
}

output "dns_servers" {
  value       = azurerm_virtual_network.vnet.dns_servers
  description = "Virutal Network dns_servers"
}

output "resource_group_name" {
  value       = azurerm_virtual_network.vnet.resource_group_name
  description = "Virutal Network resource_group_name"

}

modules/terraform-azure-module-network/virtual-network/variables.tf

代码语言:javascript
复制
# Vnet Variables

variable "vnet_location" {
  type        = string
  description = "Location of environment"
}

variable "resource_group_name" {
  type        = string
  description = "name of resource group"
}

variable "vnet_name" {
  type        = string
  description = "Name of Virtual Network"
}

variable "vnet_address_space" {
  type        = list(any)
  description = "Address space of Virtual Network"
}

variable "dns_servers" {
  type        = list(any)
  description = "Dns servers for Virtual Network"
}

modules/terraform-azure-module-network/virtual-network/subnet/main.tf

代码语言:javascript
复制
# Create the Subnet
resource "azurerm_subnet" "subnet" {
  name                 = var.subnet_name
  resource_group_name  = var.resource_group_name
  virtual_network_name = var.vnet_name
  address_prefixes     = var.subnet_address_prefixes
}

modules/terraform-azure-module-network/virtual-network/subnet/outputs.tf

代码语言:javascript
复制
output "subnet_name" {
  value = azurerm_subnet.subnet.name
}

output "subnet_id" {
  value = azurerm_subnet.subnet.id
}

output "subnet_address_prefixes" {
  value = azurerm_subnet.subnet.address_prefixes
}

modules/terraform-azure-module-network/virtual-network/subnet/variables.tf

代码语言:javascript
复制
variable "subnet_name" {
type        = string
}

variable "resource_group_name" {
  type        = string
  description = "name of resource group"
}

variable "subnet_address_prefixes" {
  type                 = list(any)
  description          = "Address prefixes of Subnet"
}

variable "vnet_name" {
  type                 = string
  description          = "Name of Virtual Network"
}

modules/terraform-azure-module-network/virtual-network/nsg/main.tf

代码语言:javascript
复制
resource "azurerm_network_security_group" "nsg" {
  name                = var.nsg_name
  location            = var.nsg_location
  resource_group_name = var.resource_group_name
}

modules/terraform-azure-module-network/virtual-network/nsg/outputs.tf

代码语言:javascript
复制
output "nsg_id" {
  value = azurerm_network_security_group.nsg.*.id
}

output "nsg_name" {
  value = azurerm_network_security_group.nsg.name
}

modules/terraform-azure-module-network/virtual-network/nsg/variables.tf

代码语言:javascript
复制
variable "resource_group_name" {
  type        = string
  description = "name of resource group"
}

variable "nsg_location" {
  type        = string
  description = "location of resource group"
}

variable "nsg_name" {
  type        = string
  description = "name of nsg group"

订阅/样板/Providers.tf

代码语言:javascript
复制
# Terraform Block
terraform {
  required_version = ">= 1.0.0"
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = ">= 2.0"
    }
  }
}

# Provider Block
provider "azurerm" {
  subscription_id = "*"
  features {}
}

订阅/样板/locals.tf

代码语言:javascript
复制
locals {
  resource_group_name     = "rg-${var.environment}-${var.project_office}-${var.asset_name}"
  vnet_name               = "vn-${var.environment}-${var.project_office}-coreservice"
  location                = var.location
}

订阅/样板/资源组

代码语言:javascript
复制
module "rg-networkcore" {
  # source = "../../modules/terraform-azure-module-resourcegroup"
  source                  = "git::ssh://git@ssh.dev.azure.com/v3/*/*/terraform-azure-module-resourcegroup"
  resource_group_name     = "rg-d-lxr-network"
  resource_group_location = local.location

}

module "rg-ansiblecontroller" {
  # source = "../../modules/terraform-azure-module-resourcegroup"
  source                  = "git::ssh://git@ssh.dev.azure.com/v3/*/*/terraform-azure-module-resourcegroup"
  resource_group_name     = local.resource_group_name
  resource_group_location = local.location
  tags                    = var.tags

}

订阅/样板/网络_vnets.tf

代码语言:javascript
复制
module "vnet-networkcore" {
  source              = "git::ssh://git@ssh.dev.azure.com/v3/*/*/terraform-azure-module-network//virtual-network"
  vnet_name           = local.vnet_name
  vnet_location       = module.rg-networkcore.location
  resource_group_name = module.rg-networkcore.resource_group_name
  vnet_address_space  = var.vnet_address_space
  dns_servers         = var.dns_servers

  depends_on = [module.rg-networkcore]
}

module "subnet-networkcore" {
  source = "git::ssh://git@ssh.dev.azure.com/v3/*/*/terraform-azure-module-network//virtual-network/subnet"
  resource_group_name     = module.rg-networkcore.resource_group_name
  vnet_name               = module.vnet-networkcore.vnet_name
  subnet_name             = var.subnet_name
  subnet_address_prefixes = var.subnet_address_prefixes

  depends_on = [
    module.rg-networkcore,
    module.vnet-networkcore
  ]
}

订阅/样板/nsgs.tf

代码语言:javascript
复制
module "nsg-networkcore" {
  # source = "../../modules/terraform-azure-module-resourcegroup"
  source              = "git::ssh://git@ssh.dev.azure.com/v3/*/*/terraform-azure-module-network//virtual-network/nsg"
  nsg_name            = var.nsg_name
  nsg_location        = local.location
  resource_group_name = local.resource_group_name
  #   tags                    = var.tags

  depends_on = [
    module.subnet-networkcore
  ]
}


resource "azurerm_network_security_rule" "example" {
  name                        = "test123"
  priority                    = 100
  direction                   = "Outbound"
  access                      = "Allow"
  protocol                    = "Tcp"
  source_port_range           = "*"
  destination_port_range      = "*"
  source_address_prefix       = "*"
  destination_address_prefix  = "*"
  resource_group_name         = module.rg-networkcore.resource_group_name
  # network_security_group_name = module.nsg-networkcore.nsg_name
  network_security_group_name = module.nsg-networkcore.nsg_name

  depends_on = [
    module.nsg-networkcore
  ]
}

订阅/样板/Terraform.tfvars

代码语言:javascript
复制
location       = "Australia Southeast"
environment    = "d"
project_office = "lxr"
asset_name     = "ansiblecontroller"

tags = {
  env     = "dev"
  project = "ansible controller"
}

vnet_address_space = ["10.1.0.0/16"]
dns_servers        = ["1.1.1.1", "4.4.4.4"]

subnet_address_prefixes = ["10.1.0.0/24"]

subnet_name = "Ansible"

nsg_name = "nsg-ansible"

订阅/样板/Variables.tf

代码语言:javascript
复制
   # Resource Group Variables

variable "location" {
  type        = string
  description = "location of resource group"
}

variable "tags" {
  type    = map(any)
  default = {}
}

variable "project_office" {
  description = "Project Office Name"
  type        = string
}

variable "environment" {
  description = "Environment Name"
  type        = string
}

variable "asset_name" {
  description = "Project Office Name"
  type        = string
}

# Vnet & Subnet Variables

variable "vnet_address_space" {
  type        = list(any)
  description = "Address space of Virtual Network"
}

variable "dns_servers" {
  type        = list(any)
  description = "Dns servers for Virtual Network"
}

variable "subnet_address_prefixes" {
  type                 = list(any)
  description          = "Address prefixes of Subnet"
}

variable "subnet_name" {
type        = string
}

# NSG Variables

variable "nsg_name" {
  type        = string
  description = "name of nsg group"
}

当我使用vars时,Terraform计划/应用工作,如下所示:

代码语言:javascript
复制
  network_security_group_name = var.nsg_name

当我引用模块时,我不知道问题是什么,因为它确实包含一个名为"nsg_name“的属性

非常感谢你的帮助

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-05 09:33:08

抱歉,伙计们,这件事很容易解决。我当时在跑地形,而我应该在里面运行地形。新秀错误

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71746995

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档