【问题标题】:Terraform crash error while running terraform plan运行 terraform plan 时出现 Terraform 崩溃错误
【发布时间】:2020-12-15 01:27:53
【问题描述】:

我正在运行 terraform 版本 0.12.24,按计划我收到以下错误:

Configuring remote state backend...
Initializing Terraform configuration...
2020/12/08 02:35:21 [DEBUG] Using modified User-Agent: Terraform/0.12.24 TFC/ed5bcca736
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0xdb92be]

goroutine 37 [running]:
github.com/hashicorp/terraform/lang/blocktoattr.walkVariables(0x236eac0, 0xc0016e2420, 0x0, 0xc0000b2001, 0x236eac0, 0xc0016e2420, 0x0, 0x0, 0x0, 0x74)
    /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/lang/blocktoattr/variables.go:34 +0x1ae
github.com/hashicorp/terraform/lang/blocktoattr.ExpandedVariables(...)
    /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/lang/blocktoattr/variables.go:24
github.com/hashicorp/terraform/lang.ReferencesInBlock(0x236eac0, 0xc0016e2420, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc002bb3230)
    /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/lang/references.go:68 +0x66
github.com/hashicorp/terraform/terraform.(*NodeAbstractResource).References(0xc001c41ba0, 0x0, 0x0, 0x0)
    /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/terraform/node_resource_abstract.go:195 +0x33d
github.com/hashicorp/terraform/terraform.NewReferenceMap(0xc002260000, 0x86e, 0x86e, 0x86e)
    /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/terraform/transform_reference.go:492 +0x24a
github.com/hashicorp/terraform/terraform.(*ReferenceTransformer).Transform(0x3523918, 0xc001274730, 0x14, 0x0)
    /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/terraform/transform_reference.go:79 +0x71
github.com/hashicorp/terraform/terraform.(*BasicGraphBuilder).Build(0xc001ddb8e8, 0x0, 0x0, 0x0, 0x3503c40, 0xc002653918, 0x4e57b0, 0xc0000b2000)
    /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/terraform/graph_builder.go:50 +0x477
github.com/hashicorp/terraform/terraform.(*PlanGraphBuilder).Build(0xc000359c70, 0x0, 0x0, 0x0, 0x1, 0x1f31e00, 0xc00171d701, 0xc002653978)
    /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/terraform/graph_builder_plan.go:65 +0xbc
github.com/hashicorp/terraform/terraform.(*Context).Graph(0xc001be22d0, 0x6, 0xc00265396e, 0xc002be2200, 0x47, 0x14, 0xbfebd77acf8e1043)
    /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/terraform/context.go:292 +0x1b8
github.com/hashicorp/terraform/terraform.(*Context).Validate(0xc001be22d0, 0x0, 0x0, 0x0)
    /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/terraform/context.go:675 +0xc9
github.com/hashicorp/terraform/backend/local.(*Local).context(0xc00043a1a0, 0xc0004d6c40, 0x1, 0x1, 0x2, 0xc0006d4180, 0x1, 0x2, 0x0)
    /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/backend/local/backend_local.go:120 +0x974
github.com/hashicorp/terraform/backend/local.(*Local).opPlan(0xc00043a1a0, 0x236e140, 0xc00063a900, 0x236e140, 0xc00063a940, 0xc0004d6c40, 0xc00063a8c0)
    /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/backend/local/backend_plan.go:70 +0x2a3
github.com/hashicorp/terraform/backend/local.(*Local).Operation.func1(0xc0006bbb00, 0xc0006bbb10, 0xc0006bbb30, 0xc0004d6c40, 0xc00043a1a0, 0xc00063a8c0, 0xc0006bbae0, 0x236e140, 0xc00063a900, 0x236e140, ...)
    /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/backend/local/backend.go:350 +0x135
created by github.com/hashicorp/terraform/backend/local.(*Local).Operation
    /opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/backend/local/backend.go:334 +0x36b

我的 tf 对这些资源进行了以下更改

  • aws_db_proxy_target
  • aws_db_proxy_default_target_group
  • aws_db_proxy

当我将 aws 提供程序切换到 3.20.0 时,故障不再发生。但是,其余 repo 的版本需要 2.x。

我尝试使用多个提供商:

provider "aws" {
  version = "~> 2.60.0"
  region  = "us-west-2"
}

provider "aws" {
  version = "~> 3.20.0"
  region  = "us-west-2"
  alias   = "version_3"
}


module "my-module" 
  ...
  ...
  providers = {
    aws = aws.version_3
  }
}

但是运行 terraform init 会返回:

No provider "aws" plugins meet the constraint " < 4.0, < 4.0,>= 2.0,>= 2.0,>= 2.25,>= 2.42,>= 2.42,>= 2.49,>= 2.49,>= 2.49,>= 2.49,>= 2.49,~> 2.0,~> 2.0,~> 2.0,~> 2.0,~> 2.0,~> 2.0,~> 2.0,~> 2.0,~> 2.0,~> 2.60.0,~> 3.20.0".

The version constraint is derived from the "version" argument within the
provider "aws" block in configuration. Child modules may also apply
provider version constraints. To view the provider versions requested by each
module in the current configuration, run "terraform providers".

To proceed, the version constraints for this provider must be relaxed by
either adjusting or removing the "version" argument in the provider blocks
throughout the configuration.

- Downloading plugin for provider "template" (hashicorp/template) 2.2.0...

Error: no suitable version is available

【问题讨论】:

  • 这似乎是 tf 错误。您可以尝试使用较新的 tf 版本吗?
  • 最新版本似乎是 0.29。我试过了,但似乎有同样的问题。
  • 0.12 中有一堆段错误在 0.13 中得到修复,因为这是路线图中的核心目标。我不知道是否可以选择升级,但请与 0.13 并行尝试,问题可能会消失。
  • 有趣的是,当我将 aws 提供程序切换到 3.20.0 时,故障不再发生。但是,其余 repo 的版本需要 2.x。

标签: terraform


【解决方案1】:

我之前在多个提供商处遇到过这个问题。最后,我将第二个提供程序块与模块本身的别名一起嵌入并且它起作用了。显然,我建议您将该模块中的任何敏感或变化的值作为变量传递。

这不是最优雅的方式,但它为我完成了工作。希望它对你也一样。

祝你好运!

【讨论】:

    猜你喜欢
    • 2021-07-13
    • 1970-01-01
    • 1970-01-01
    • 2021-05-10
    • 2018-11-28
    • 1970-01-01
    • 1970-01-01
    • 2018-11-21
    • 2020-09-18
    相关资源
    最近更新 更多