【问题标题】:Terraform cloud run triggers with Azure使用 Azure 的 Terraform 云运行触发器
【发布时间】:2022-02-23 03:44:18
【问题描述】:

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

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

我试图关注 hasicorp 网站上的内容,但它是针对 aws 的,所以可能是因为 azure 我错过了一些东西。我将发布我的输出,然后是第二个工作区的一些代码。

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

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:位置= data.terraform_remote_state.network.outputs.location │
├──────────────── │ │ data.terraform_remote_state.network.outputs 是没有属性的对象│ │ 这个对象没有 名为“位置”的属性。

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

【问题讨论】:

    标签: azure terraform azure-rm terraform-cloud terraform-remote-state


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2020-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-21
      • 2022-10-19
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      相关资源
      最近更新 更多