Open chdsbd opened 5 years ago
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."
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.
@mars I've updated my expected behavior a bit. Please reopen this PR.
I think I found the bug. Please see the updated references section of this issue.
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.
Thanks for looking that up @davidji99. It seems like this should be labeled "Heroku API Support".
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
.
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
}
}
Terraform Version
Heroku Provider Version
Affected Resource(s)
Terraform Configuration Files
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
terraform apply
and observe that a new resource is going to be createdImportant 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.