我有这个基础设施说明
variable "HEROKU_API_KEY" {}
provider "heroku" {
email = "sebastrident@gmail.com"
api_key = "${var.HEROKU_API_KEY}"
}
resource "heroku_app" "default" {
name = "judge-re"
region = "us"
}
原来我忘了指定buildpack
。它在heroku上创建了应用程序。我决定将其添加到resource
条目
buildpacks = [
"heroku/java"
]
但是当我尝试在terraform
中应用该计划时,我收到此错误
Error: Error applying plan:
1 error(s) occurred:
* heroku_app.default: 1 error(s) occurred:
* heroku_app.default: Post https://api.heroku.com/apps: Name is already taken
Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
Terraform计划如下所示
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
------------------------------------------------------------------------
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
+ heroku_app.judge_re
id: <computed>
all_config_vars.%: <computed>
buildpacks.#: "1"
buildpacks.0: "heroku/java"
config_vars.#: <computed>
git_url: <computed>
heroku_hostname: <computed>
name: "judge-re"
region: "us"
stack: <computed>
web_url: <computed>
Plan: 1 to add, 0 to change, 0 to destroy.
------------------------------------------------------------------------
Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.
作为一种解决方法,我尝试在destroy
脚本中添加deploy.sh
terraform init
terraform plan
terraform destroy -force
terraform apply -auto-approve
但是当我收到消息Destroy complete! Resources: 0 destroyed.
有什么问题?
链接到build
答案 0 :(得分:1)
看起来您还更改了资源的名称。您的计划有heroku_app.default
时,原始示例的资源名称为heroku_app.judge_re
。
要将您的状态指向远程资源,因此Terraform知道您正在编辑而不是尝试重新创建资源,请使用terraform import
:
terraform import heroku_app.judge_re judge-re
答案 1 :(得分:0)
在terraform中,通常你不需要销毁整个堆栈,你只想在其中重新构建一个或多个资源。
terraform taint做了这个伎俩。 terraform污染命令手动将Terraform管理的资源标记为污染,强制它在下一次应用时被销毁并重新创建。
terraform taint heroku_app.default
其次,在排除资源不在destroy资源中列出的原因时,请确保指向右侧的terraform tfstate文件。
当您运行terraform plan
时,您是否看到了已创建的资源?