Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing postgres-db doesn't import config version #176

Open
chdsbd opened this issue Feb 13, 2019 · 8 comments
Open

Importing postgres-db doesn't import config version #176

chdsbd opened this issue Feb 13, 2019 · 8 comments
Labels
Heroku API Support Ticket/PR is blocked on the Heroku API supporting the use case

Comments

@chdsbd
Copy link

chdsbd commented Feb 13, 2019

Terraform Version

Terraform v0.11.11

Heroku Provider Version

provider.heroku v1.4.0

Affected Resource(s)

  • heroku_addon.postgres-db

Terraform Configuration Files

resource "heroku_addon" "postgres-db" {
  app  = "example-app"
  plan = "heroku-postgresql:hobby-basic"
  config = {
    version = "10"
  }
}

Debug Output

N/A

Panic Output

N/A

Expected Behavior

Importing a postgres-db resource should update the config state to match the version config definition on Heroku.

If I have a postgres database on Heroku that is configured to be version 10, when I import that resource, the Terraform state should include config.version = "10".

So in my example, while my Terraform configuration matches the Heroku add-on. When I import the Heroku resource, the config version of "10" is not imported. So Terraform thinks it needs to recreate the resource to update that state.

Actual Behavior

The config version was not updated and terraform wants to recreate the resource from scratch

Steps to Reproduce

  1. create a postgres database addon
  2. create a terraform resource for the database
  3. import the database into that resource
  4. terraform apply and observe that a new resource is going to be created

Important Factoids

N/A

References

It seems like the code for importing addons is incorrect.

When creating resources, we set config but when importing, we do not.

@mars
Copy link
Member

mars commented Feb 13, 2019

Hi @chdsbd 😄

Importing a postgres-db resource should update the config to match the version

This is not how terraform import works. The HCL config must already match the pre-existing resource's state.

See Terraform docs about import, "It does not generate configuration."

@mars mars closed this as completed Feb 13, 2019
@chdsbd
Copy link
Author

chdsbd commented Feb 13, 2019

I think you misunderstand. I created a resource that matches the Heroku config, but when I import, the heroku provider doesn't import the config version.

Edit: by "config", I literally mean the "config" field in the Terraform state. The "config" state is not pulled down from Heroku when importing.

@chdsbd
Copy link
Author

chdsbd commented Feb 13, 2019

@mars I've updated my expected behavior a bit. Please reopen this PR.

@chdsbd
Copy link
Author

chdsbd commented Feb 13, 2019

I think I found the bug. Please see the updated references section of this issue.

@mars mars reopened this Feb 13, 2019
@davidji99
Copy link
Collaborator

davidji99 commented Feb 15, 2019

This is a limitation of the Heroku Platform API. I'm not seeing an API endpoint that would allow the provider to GET the config of the addon. This endpoint only returns the full URL of the postgres DB and that's it. This endpoint doesn't return the config either; only the config vars for the addon, which are different. Without the ability to get GET the config of the postgres addon, it would be hard to set it during a terraform import.

@chdsbd
Copy link
Author

chdsbd commented Feb 15, 2019

Thanks for looking that up @davidji99. It seems like this should be labeled "Heroku API Support".

@chdsbd
Copy link
Author

chdsbd commented Feb 15, 2019

Actually, on second pass, I think this endpoint might work: https://devcenter.heroku.com/articles/platform-api-reference#add-on-config-list

EDIT: This is the endpoint for fetching config_vars, not config.

@davidji99 davidji99 added the Heroku API Support Ticket/PR is blocked on the Heroku API supporting the use case label Feb 15, 2019
@crisp2u
Copy link
Contributor

crisp2u commented Feb 21, 2020

Hello, I recently ran into this after Heroku updated Postgres to v12. Since we have now way to get the initial config from the API, my workaround for existing DB addons is to specify the desired version but ignore all changes in the attributes. Which I should have done in the first place since I don't want TF to manage changes to the database

resource "heroku_addon" "database" {
  app    = "myapp"
  plan   = "heroku-postgresql:standard-0"
  config = {
    version = "11"
  }
  lifecycle {
    ignore_changes = all
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Heroku API Support Ticket/PR is blocked on the Heroku API supporting the use case
Projects
None yet
Development

No branches or pull requests

4 participants