Terraform数据块一直显示资源未找到。

huangapple go评论67阅读模式
英文:

Terraform data block keeps saying the resources were not found

问题

我正在尝试通过使用数据块从另一个Terraform管道部署的资源中获取一些资源ID,例如在Azure中用于存储账户块中的子网ID。但是,我在尝试的所有4个数据块上都遇到了相同类型的错误:

data "azurerm_subnet" "data_subnet" {
  name                = "DataSubnet"
  virtual_network_name = "vnet-${var.lztri}-${var.env}-${var.loc}${var.stage != "" ? "-" : ""}${var.stage}-01"
  resource_group_name = "rg-${var.lztri}-network-${var.env}${var.stage != "" ? "-" : ""}${var.stage}-${var.loc}"
}
错误: 未找到子网:(名称 "DataSubnet" / 虚拟网络名称 "vnet-phr-dev-weu-01" / 资源组 "rg-phr-network-dev-weu")

在 data.azurerm_subnet.data_subnet 上,
位于 main.tf 第 12 行,在 data "azurerm_subnet" "data_subnet" 内:
12: data "azurerm_subnet" "data_subnet" {

但是,如果我搜索“未找到”的资源,我能够在门户中找到它们。

英文:

I'm trying to get some resource ID's from resources that were deployed by another terraform pipeline, by using a data block. For example, subnet ID's for usage in a storage account block in azure.
But, I'm getting the same kind of error on all 4 data blocks that I'm trying:

data "azurerm_subnet" "data_subnet" {
  name = "DataSubnet"
  virtual_network_name = "vnet-${var.lztri}-${var.env}-${var.loc}${var.stage != "" ? "-" : ""}${var.stage}-01"
  resource_group_name = "rg-${var.lztri}-network-${var.env}${var.stage != "" ? "-" : ""}${var.stage}-${var.loc}"
}
 Error: Subnet: (Name "DataSubnet" / Virtual Network Name "vnet-phr-dev-weu-01" / Resource Group "rg-phr-network-dev-weu") was not found
 
   with data.azurerm_subnet.data_subnet,
   on main.tf line 12, in data "azurerm_subnet" "data_subnet":
   12: data "azurerm_subnet" "data_subnet" {

But if I look for the 'not found' resources, I'm able to find them in the portal.

答案1

得分: 1

问题已解决,在Azure DevOps控制台中,我遇到了错误,提示找不到资源,但我在我的笔记本上本地执行了同样的代码,也出现了相同的错误,但附带了一些额外的信息;它显示了试图查找资源的订阅ID。但这是错误的,这是SPN的订阅,而不是部署的订阅。所以我不得不在提供程序中指定订阅ID,然后它就正常工作了!

英文:

Got this issue solved, in the azure devops console I got the errors, saying the resources were not found, but I executed that piece of code locally on my laptop, got the same error, but with an piece of extra info; it showed the subscriptionID where it was trying to find the resources. And this was wrong, this was the subscription of the SPN, not of the deployment. So I had to specify the subscription ID in the provider and it worked!

huangapple
  • 本文由 发表于 2023年7月17日 22:35:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76705530.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定