【问题标题】:terraform apply reporting backend configuration error with S3 after terraform init & terraform plan worked successfullyterraform init & terraform plan 成功运行后,terraform apply 使用 S3 报告后端配置错误
【发布时间】:2018-11-21 23:49:03
【问题描述】:

我在我的 Linux 实例上运行 terraform,但我遇到了以下问题。

+ /usr/local/bin/terraform workspace new test
enter code here[0m[0m[1m[33mBackend reinitialization required. Please run "terraform init".[0m

[33mReason: Initial configuration of the requested backend "s3"
The "backend" is the interface that Terraform uses to store state,
perform operations, etc. If this message is showing up, it means that the
Terraform configuration you're using is using a custom configuration for
the Terraform backend.

Changes to backend configurations require reinitialization. This allows
Terraform to setup the new configuration, copy existing state, etc. This is
only done during "terraform init". Please run that command now then try again.

If the change reason above is incorrect, please verify your configuration
hasn't changed and try again. At this point, no changes to your existing
configuration or state have been made.
[0m
[31mFailed to load backend: Initialization required. Please see the error message above.

这是 Terraform 配置文件。

provider "aws" {
  # don't touch below here
  access_key = "${var.aws_access_key}"
  secret_key = "${var.aws_secret_key}"
  region     = "us-west-2"
}

# Configure Terraform to store this in S3
terraform {
  backend "s3" {
    bucket = "nom-terraform"
    key    = "apps/onboarding/terraform.tfstate"
    region = "us-west-2"
  }
}

在运行 terraform apply 之前,我成功地运行了terraform plan

【问题讨论】:

  • 尝试删除“.terraform”文件夹并重新运行 terraform init ?
  • @keety 我在 linux 环境中运行它,你能告诉我在哪里可以找到那个 .terraform 文件夹吗?
  • 它在您正在使用的任何目录中。

标签: amazon-web-services terraform terraform-provider-aws


【解决方案1】:

似乎您已经添加了新的 s3 作为后端。 所以 terraform 需要重新初始化。 只需运行terraform init,它将添加s3作为后端并请求将本地状态文件传输到s3的权限。

【讨论】:

  • 我试过了。还是一样。 terraform init 有效,并且 apply 抛出了同样的错误。 :(
  • 同样的问题
  • 能否请您分享错误@PedroBezanilla
  • @deepak " 需要重新初始化后端。请运行 "terraform init"。原因:请求后端 "s3" " 的初始配置显示,因为我开始使用后端配置:terraform init \ -backend- config=backend.tfvars
【解决方案2】:

您需要首先初始化提供,下载最新版本的提供,输出将是这样的:-

# terraform init

Initializing provider plugins...
- Checking for available provider plugins on https://releases.hashicorp.com...
- Downloading plugin for provider "spotinst" (1.1.1)...

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.

* provider.aws: version = "~> 1.2"
* provider.cloudflare: version = "~> 0.1"
* provider.spotinst: version = "~> 1.1"

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.`

【讨论】:

    【解决方案3】:

    我会先删除任何状态文件和 .terraform 文件夹,由于损坏有时会出现许多错误。

    之后我会运行 init,它应该会运行。

    我不认为添加后端是问题,因为它应该尝试在状态之间合并

    【讨论】:

      猜你喜欢
      • 2018-11-28
      • 1970-01-01
      • 2019-08-22
      • 1970-01-01
      • 1970-01-01
      • 2021-09-26
      • 2021-12-23
      • 2021-03-19
      • 2021-09-28
      相关资源
      最近更新 更多