简体   繁体   English

将 terraform 与 heroku 一起使用时,是否可以在附加插件后刷新应用程序状态?

[英]When using terraform with heroku, is there a way to refresh app state after an addon is attached?

I'm using terraform to set up an app on heroku.我正在使用 terraform 在 heroku 上设置一个应用程序。 The app needs a mysql database and I'm using ClearDB addon for that.该应用程序需要一个 mysql 数据库,我为此使用了 ClearDB 插件。 When ClearDB is attached to the app, it sets a CLEARDB_DATABASE_URL config variable.当 ClearDB 附加到应用程序时,它会设置一个CLEARDB_DATABASE_URL配置变量。 The app requires the database url to be in a DATABASE_URL config variable.该应用程序要求数据库 url 位于DATABASE_URL配置变量中。 So what I'm trying to do is to use resource heroku_app_config_association to copy the value from CLEARDB_DATABASE_URL to DATABASE_URL .所以我想要做的是使用资源heroku_app_config_association将值从CLEARDB_DATABASE_URL复制到DATABASE_URL The problem is that after heroku_app resource is created, its state does not yet contain CLEARDB_DATABASE_URL , and after heroku_addon is created, the state of heroku_app is not updated.问题是,经过heroku_app创建资源,其状态尚不包含CLEARDB_DATABASE_URL ,经过heroku_addon被创建,状态heroku_app不会被更新。

This is the content of my main.tf file:这是我的main.tf文件的内容:

provider "heroku" {}

resource "heroku_app" "main" {
  name = var.app_name
  region = "eu"
}

resource "heroku_addon" "database" {
    app = heroku_app.main.name
    plan = "cleardb:punch"
}

resource "heroku_app_config_association" "main" {
    app_id = heroku_app.main.id
    sensitive_vars = {
        DATABASE_URL = heroku_app.main.all_config_vars.CLEARDB_DATABASE_URL
    }
    depends_on = [
        heroku_addon.database
    ]
}

This is the error that I get:这是我得到的错误:

Error: Missing map element

  on main.tf line 22, in resource "heroku_app_config_association" "main":
  22:           DATABASE_URL = heroku_app.main.all_config_vars.CLEARDB_DATABASE_URL
    |----------------
    | heroku_app.main.all_config_vars is empty map of string

This map does not have an element with the key "CLEARDB_DATABASE_URL".

The configuration variable is copied successfully when terraform apply is executed second time.第二次执行terraform apply时,配置变量复制成功。 Is there a way to make it work on the first run?有没有办法让它在第一次运行时工作?

To get up-to-date state of the heroku_app resource I used the data source:为了获取heroku_app资源的最新状态,我使用了数据源:

data "heroku_app" "main" {
    name = heroku_app.main.name
    depends_on = [
        heroku_addon.database
    ]
}

I could then access the value in heroku_app_config_association resource:然后我可以访问heroku_app_config_association资源中的值:

resource "heroku_app_config_association" "main" {
    app_id = heroku_app.main.id
    sensitive_vars = {
        DATABASE_URL = data.heroku_app.main.config_vars.CLEARDB_DATABASE_URL
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用ClearDB插件将使用MySQL的rails应用程序部署到Heroku - Deploy a rails app using MySQL to Heroku using ClearDB addon Spring 部署到 Heroku 的引导应用在升级插件后无法连接到 ClearDB - Spring boot app deployed to Heroku can't connect to a ClearDB after upgrading addon 将Nodejs应用程序投放到heroku后出现SequelizeDatabaseError - SequelizeDatabaseError after deplying nodejs app to heroku php - 如何在刷新后保持图像按钮状态 - php - How to keep image buttons state after refresh 刷新页面时如何使赞按钮保持赞state - How to make like button stay as liked state when refresh the page 有没有办法在 Heroku 部署的应用程序上的jawsdb 中创建数据库和表? - Is there a way to create databases and tables in jawsdb on Heroku deployed app? 使用Heroku ClearDB插件更改MySQL auto_increment - Alter MySQL auto_increment with Heroku ClearDB addon 在Java Web Services方法中添加项目后刷新应用程序 - refresh app after item added in java web services method 如何在heroku上部署节点应用程序时连接mysql - How to connect mysql when deploying node app on heroku 在Heroku上远程连接到MySQL数据库时,Rails应用程序崩溃 - Rails app crashes when connecting remotely to MySQL Database on Heroku
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM