0

我在访问我的数据“ terrafrom_remote_state”对象时遇到问题。所以我正在关注 hashcorp 站点,以使用带有运行触发器的 terraform 云部署 azure 资源。触发器正在工作,正在运行第二个工作区的计划,但它无法访问我通过输出传递的数据。

我已经为要共享的第一个工作区设置了“状态”,并将第二个工作区上的运行触发器设置为由第一个工作区触发。这里没有问题。

我试图关注 hasicorp 网站上的内容,但它是针对 aws 的,也许对于天蓝色我错过了一些东西。我将发布我的输出,然后发布第二个工作区的一些代码。

输出:我在状态文件中查看过并且看起来不错。

output "rgName" {
  description = "The resource group for resources"
  value = var.rgName
}

output "location" {
  description = "The location for resources"
  value = var.location
}

output "subnet1_id" {
  description = "subnet 1"
  value = azurerm_subnet.subnet1.id
}

第二工作区

data "terraform_remote_state" "network" {
  backend = "remote"

  config = {

    organization = "Awesome-Company"
    workspaces = {
          name = "TFCloud-Trigger-Network"
    }
  }
}

provider "azurerm" {
  version =  "2.66.0"

  subscription_id = var.subscription_id
  client_id = var.client_id
  client_secret = var.clientSecret
  tenant_id = var.tenant_id

  features{}
}

#Deploy Public IP
resource "azurerm_public_ip" "pip1" {
  name                = "TFC-pip1"
  location            = data.terraform_remote_state.network.outputs.location
  resource_group_name = data.terraform_remote_state.network.outputs.rgName  
  allocation_method   = "Dynamic"
  sku                 = "Basic"
}

#Create NIC
resource "azurerm_network_interface" "nic1" {
  name                = "TFC-TestVM-Nic"  
  location            = data.terraform_remote_state.network.outputs.location  
  resource_group_name = data.terraform_remote_state.network.outputs.rgName 

    ip_configuration {
    name                          = "ipconfig1"
    subnet_id                     = date.terraform_remote_state.network.outputs.subnet1_id 
    private_ip_address_allocation  = "Dynamic"
    public_ip_address_id          = azurerm_public_ip.pip1.id
  }
}

错误是

错误:不支持的属性│ │ 在 main.tf 第 26 行,资源“azurerm_public_ip”“pip1”中:│ 26:location = data.terraform_remote_state.network.outputs.location │<br />├──────── ──────── │ │ data.terraform_remote_state.network.outputs 是没有属性的对象 │ │ 这个对象没有名为“位置”的属性。

我无法访问 data.terraform_remote_state.network.outputs

4

1 回答 1

0

所以,我想通了,它不在文档中。由另一个工作空间触发的工作空间不会自动更新其 terrafrom 计划。

通常,当我在 github(或其他 repo)中编辑代码时,一旦您保存了新代码,terraform cloud 将自动运行计划。由另一个人触发的工作空间不会这样做。因此,即使我更改了代码,我也必须手动转到 TF Cloud 丢弃该触发工作区上的当前运行,然后重新运行计划。在此之后,运行触发器将成功运行。

这是一件很奇怪的事情...

于 2022-02-22T19:44:18.707 回答