│ 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 Apply
шаблонный
|_ 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
модули/terraform-azure-module-resourcegroup/main.tf
resource "azurerm_resource_group" "rg" {
name = var.resource_group_name
location = var.location
tags = var.tags
}
модули/terraform-azure-module-resourcegroup/outputs.tf
# 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"
}
модули/terraform-azure-module-resourcegroup/variables.tf
# 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 = {}
}
модули/terraform-azure-module-network/virtual-network/main.tf
# 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
}
модули/terraform-azure-module-network/virtual-network/outputs.tf
# 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"
}
модули/terraform-azure-module-network/virtual-network/variables.tf
# 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"
}
модули/terraform-azure-module-network/virtual-network/subnet/main.tf
# 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
}
модули/terraform-azure-module-network/virtual-network/subnet/outputs.tf
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
}
модули/terraform-azure-module-network/virtual-network/subnet/variables.tf
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"
}
модули/terraform-azure-module-network/virtual-network/nsg/main.tf
resource "azurerm_network_security_group" "nsg" {
name = var.nsg_name
location = var.nsg_location
resource_group_name = var.resource_group_name
}
модули/terraform-azure-module-network/virtual-network/nsg/outputs.tf
output "nsg_id" {
value = azurerm_network_security_group.nsg.*.id
}
output "nsg_name" {
value = azurerm_network_security_group.nsg.name
}
модули/terraform-azure-module-network/virtual-network/nsg/variables.tf
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
# 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
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
}
подписки/шаблон/resource_groups.tf
module "rg-networkcore" {
# source = "../../modules/terraform-azure-module-resourcegroup"
source = "git::ssh://[email protected]/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://[email protected]/v3/*/*/terraform-azure-module-resourcegroup"
resource_group_name = local.resource_group_name
resource_group_location = local.location
tags = var.tags
}
подписки/шаблон/networking_vnets.tf
module "vnet-networkcore" {
source = "git::ssh://[email protected]/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://[email protected]/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
module "nsg-networkcore" {
# source = "../../modules/terraform-azure-module-resourcegroup"
source = "git::ssh://[email protected]/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
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
# 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"
}
Terraform plan/apply работает, когда я использую vars, как показано ниже:
network_security_group_name = var.nsg_name
Я не уверен, в чем проблема, когда вместо этого я ссылаюсь на модуль, поскольку он содержит атрибут с именем «nsg_name».
Был бы признателен за помощь Спасибо
Ваш вопрос сбивает с толку. Некоторые модули находятся в ssh.dev.azure.com
, некоторые являются локальными. Что именно вы написали в вопросе? Кажется, вы разместили только локальные модули, а не удаленные.
извините, ребята, это было легко исправить. Я запускал terraform get, когда должен был запускать terraform init. Ошибка новичка
извините, ребята, это было легко исправить. Я запускал terraform get, когда должен был запускать terraform init. Ошибка новичка
Вы перезапускали
terraform init
после смены источника модуля?