当不存在周期时,terraform destroy会产生周期错误 地形版本 地形配置文件
当不存在周期时,terraform destroy会产生周期错误 地形版本 地形配置文件,terraform,terraform-provider-gcp,terraform0.12+,Terraform,Terraform Provider Gcp,Terraform0.12+,main.tf在我的根提供程序中: provider "google" {} module "organisation_info" { source = "../../modules/organisation-info" top_level_domain = "smoothteam.fi" region = "us-central1" } module "stack_info" { source = "../../
main.tf
在我的根提供程序中:
provider "google" {}
module "organisation_info" {
source = "../../modules/organisation-info"
top_level_domain = "smoothteam.fi"
region = "us-central1"
}
module "stack_info" {
source = "../../modules/stack-info"
organisation_info = "${module.organisation_info}"
}
这是“组织信息”模块:
variable "top_level_domain" {}
variable "region" {}
data "google_organization" "organization" {
domain = "${var.top_level_domain}"
}
locals {
organization_id = "${data.google_organization.organization.id}"
ns = "${replace("${var.top_level_domain}", ".", "-")}-"
}
output "organization_id" {
value = "${local.organization_id}"
}
output "ns" {
value = "${local.ns}"
}
然后是模块“堆栈信息”:
variable "organisation_info" {
type = any
description = "The organisation-scope this environment exists in."
}
module "project_info" {
source = "../project-info"
organisation_info = "${var.organisation_info}"
name = "${local.project}"
}
locals {
# Use the 'default' workspace for the 'staging' stack.
name = "${terraform.workspace == "default" ? "staging" : terraform.workspace}"
# In the 'production' stack, target the production project. Otherwise, target the staging project.
project = "${local.name == "production" ? "production" : "staging"}"
}
output "project" {
value = "${module.project_info}" # COMMENTING THIS OUTPUT REMOVES THE CYCLE.
}
最后,“项目信息”模块:
variable "organisation_info" {
type = any
}
variable "name" {}
data "google_project" "project" {
project_id = "${local.project_id}"
}
locals {
project_id = "${var.organisation_info.ns}${var.name}"
}
output "org" {
value = "${var.organisation_info}"
}
调试输出
执行地形销毁-自动批准后,我得到:
Error: Cycle: module.stack_info.module.project_info.local.project_id, module.stack_info.output.project, module.stack_info.module.project_info.data.google_project.project (destroy), module.organisation_info.data.google_organization.organization (destroy), module.stack_info.var.organisation_info, module.stack_info.module.project_info.var.organisation_info, module.stack_info.module.project_info.output.org
而terraformgraph-verbose-draw cycles-type=plan destroy
为我提供了以下图形:
资料来源:
预期行为
其思想是在组织、项目和堆栈级别使用模块来设置命名约定,这些命名约定可以在所有资源中重复使用。组织信息加载组织信息、关于项目的项目信息,堆栈信息根据当前工作空间确定目标项目
我在模块中省略了一些其他的逻辑,以便在这个问题上保持它们的整洁
根据terraform
的说法,没有循环,destroy
应该可以正常工作
实际行为
我们得到了我在上面发布的周期,尽管terraform没有显示周期
复制步骤
如上所示,设置三个模块,组织信息
、项目信息
和堆栈信息
如上所示设置根提供程序
terraforminit
terraform destroy
(如果您先申请,这似乎并不重要)
附加上下文
奇怪的是,如果我在stack info
中注释掉这个输出,循环就会停止:
output "project" {
value = "${module.project_info}" # IT'S THIS... COMMENTING THIS OUT REMOVES THE CYCLE.
}
这看起来真的很奇怪。。。我既不明白为什么输出一个变量会产生影响,也不明白为什么在没有循环的情况下会出现循环错误
奇怪的是,terraform plan-destroy
并没有揭示周期,只是terraform destroy
我的蜘蛛感觉告诉我邪恶正在酝酿
感谢任何能告诉我发生了什么,这是否是一个bug,以及如何解决的人。在我的例子中,相同的周期错误是因为map type variable inside variables.tf未在main.tf或anywhere中声明的模块的key:pair中的out of 3 key:pair是key:pair中的一个。我有类似的情况,同样的版本。有什么想法吗?我正在和Hashicorp的伙计们讨论这个问题,请随意插话,描述一下你的经历。谢谢,我会关注的。同样的问题。我升级到Terraform v0.13.2。。但仍然存在相同的问题错误:循环:…销毁废品
:(
digraph {
compound = "true"
newrank = "true"
subgraph "root" {
"[root] module.organisation_info.data.google_organization.organization" [label = "module.organisation_info.data.google_organization.organization", shape = "box"]
"[root] module.stack_info.module.project_info.data.google_project.project" [label = "module.stack_info.module.project_info.data.google_project.project", shape = "box"]
"[root] provider.google" [label = "provider.google", shape = "diamond"]
"[root] module.organisation_info.data.google_organization.organization" -> "[root] module.stack_info.module.project_info.data.google_project.project"
"[root] module.organisation_info.data.google_organization.organization" -> "[root] provider.google"
"[root] module.stack_info.module.project_info.data.google_project.project" -> "[root] provider.google"
}
}
output "project" {
value = "${module.project_info}" # IT'S THIS... COMMENTING THIS OUT REMOVES THE CYCLE.
}