我目前正在构建一个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环境。
问题: