多个Terraform环境失败

时间:2018-01-02 20:53:34

标签: terraform

我目前正在构建一个Terraform脚本,以在多个环境中构建资源。我想要一个非prod-1环境以及一个nonprod-2环境。

我能够构建nonprod-1。然后我也成功地构建了nonprod-2。

我将terraform.tfstate文件保存在名为:

的存储桶中
mybucket
  nonprod-1/terraform.tfstate
  nonprod-2/terraform.tfstate

并有一个provider_config.tf文件,其中包含:

terraform {
  backend "s3" {
    bucket = "mybucket"
//    Comment out key.  Enter as a command line parm in the init statement
//    key    = "nonprod-1/terraform.tfstate"
    region = "us-east-1"
  }
}

接下来,我想回到nonprod-1,做了一些改变。所以,我运行了命令行:

terraform init -backend-config="key=nonprod-1/terraform.tfstate"

这导致了问题:

 Do you want to copy the state from "s3"?
  Would you like to copy the state from your prior backend "s3" to the
  newly configured "s3" backend? If you're reconfiguring the same backend,
  answering "yes" or "no" shouldn't make a difference. Please answer exactly
  "yes" or "no".

  Enter a value:

我回答

接下来,我得到了提示:

Do you want to copy state from "s3" to "s3"?
  Pre-existing state was found in "s3" while migrating to "s3". An existing
  non-empty state exists in "s3". The two states have been saved to temporary
  files that will be removed after responding to this query.

  One ("s3"): C:\Users\foo\AppData\Local\Temp\terraform757778187\1-s3.tfstate
  Two ("s3"): C:\Users\foo\AppData\Local\Temp\terraform757778187\2-s3.tfstate

  Do you want to copy the state from "s3" to "s3"? Enter "yes" to copy
  and "no" to start with the existing state in "s3".

我再次回答

接下来,我运行了我的apply命令。它试图用nonprod-1资源替换所有非prod-2资源,而不是更新nonprod-1环境。

问题:

  1. 为什么要更新nonprod-2而不是切换到     nonprod-1(我假设init应该指向nonprod-1状态文件)
  2. 第一个提示是什么意思?我假设我想要从" s3"因为那是远程国家的目的。
  3. 第二个提示是什么意思?听起来好像在问我是否要覆盖现有的tfstate文件?为什么要问我是否要从" s3"到" s3"虽然?而且,为什么提到找到两个文件?
  4. 最后,现在一切都被搞砸了,最好的办法是什么 恢复?我试图破坏一切,但是一堆资源 留下了创造。随后的毁灭并没有摧毁任何其他东西。我可以删除S3中的状态文件吗? 一切都重建了?如果是这样,我猜这意味着我必须这样做 手动删除所有剩余资源?

0 个答案:

没有答案