heroku - 使用 terraform 更新 heroku 上的现有基础设施

标签 heroku terraform

我有这个基础设施描述

variable "HEROKU_API_KEY" {}

provider "heroku" {
    email = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="54273136352720263d30313a20143339353d387a373b39" rel="noreferrer noopener nofollow">[email protected]</a>"
    api_key = "${var.HEROKU_API_KEY}"
}

resource "heroku_app" "default" {
    name = "judge-re"
    region = "us"
}

最初我忘记指定buildpack。它在heroku 上创建了应用程序。我决定将其添加到资源条目

    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.

作为解决方法,我尝试在 deploy.sh 脚本中添加 destroy

terraform init
terraform plan

terraform destroy -force

terraform apply -auto-approve

但当我收到消息销毁完成!时它不会销毁资源!资源:0 被毁。

问题是什么?

链接到build

最佳答案

您似乎还更改了资源的名称。您的原始示例的资源名称为 heroku_app.default,而您的计划的资源名称为 heroku_app.judge_re

要将您的状态指向远程资源,以便 Terraform 知道您正在编辑而不是尝试重新创建资源,请使用 terraform import:

terraform import heroku_app.judge_re Judge-re

关于heroku - 使用 terraform 更新 heroku 上的现有基础设施,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48851930/

相关文章:

css - 如何使用 Less CSS 将元素部署到 Heroku?

terraform - 除了反复试验之外,如何测试 terraform 模板

terraform 将输出保存到文件

terraform - Terraform 0.12 模块中的可选资源

java - 我们可以用Java解析terraform "variables.tf"文件吗?如果是这样如何实现相同的

heroku - 硬盘配额 — Cedar Stack (Heroku)

javascript - 在 Heroku Node.js/Express 应用程序上禁用 HTTPS

database - Heroku 在哪里存储其数据库?

Django/Heroku : FATAL: too many connections for role

shell - 使用 terraform 在 Azure VM 中运行自定义 shell 脚本