-
Notifications
You must be signed in to change notification settings - Fork 117
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
3.4.x (and later) still has a resource replacement bug #324
Comments
Hi @ohookins 👋 Thanks for raising this and sorry you ran into trouble here. This is the first I think we're hearing of 3.4.x issues with the Would it be possible for you to show the (redacted if necessary) current state of that particular resource? e.g. $ terraform state show random_pet.db_username We can use that to track down the "invisible" difference that Terraform is trying to report (for legacy reasons it tends to hide It's also possible that the JSON output of the plan might show the underlying attribute value difference that not shown in the normal command output: $ terraform plan -json Thanks so much. |
@bflad you want me to run both of those commands with the latest provider version? |
Apologies for being unclear in that regard. |
Nothing really amazing to show. Current state:
Not sure if you were looking for the JSON output of the run or the actual plan in JSON format. For us we have our plans/applies in an ephemeral container so it's a bit hard to get the plan out as a file. {"@level":"info","@message":"random_pet.db_username: Plan to replace","@module":"terraform.ui","@timestamp":"2022-09-20T04:46:08.077123Z","change":{"resource":{"addr":"random_pet.db_username","module":"","resource":"random_pet.db_username","implied_provider":"random","resource_type":"random_pet","resource_name":"db_username","resource_key":null},"action":"replace","reason":"cannot_update"},"type":"planned_change"} |
I've tried to reproduce by running terraform apply using resource "random_pet" "db_username" {
length = 2
separator = ""
} terraform state show random_pet.db_username
# random_pet.db_username:
resource "random_pet" "db_username" {
id = "learningreindeer"
length = 2
} Then upgraded to terraform plan -json
{"@level":"info","@message":"Terraform 1.2.8","@module":"terraform.ui","@timestamp":"2022-09-20T09:11:57.166799+01:00","terraform":"1.2.8","type":"version","ui":"1.0"}
{"@level":"warn","@message":"Warning: Provider development overrides are in effect","@module":"terraform.ui","@timestamp":"2022-09-20T09:11:57.167831+01:00","diagnostic":{"severity":"warning","summary":"Provider development overrides are in effect","detail":"The following provider development overrides are set in the CLI configuration:\n - hashicorp/random in /Users/bdb/go/bin\n - bendbennett/playground in /Users/bdb/go/bin\n - bendbennett/timeouts in /Users/bdb/go/bin\n - bendbennett/attributes in /Users/bdb/go/bin\n - hashicorp/time in /Users/bdb/go/bin\n\nThe behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases."},"type":"diagnostic"}
{"@level":"info","@message":"random_pet.db_username: Refreshing state... [id=learningreindeer]","@module":"terraform.ui","@timestamp":"2022-09-20T09:11:57.703687+01:00","hook":{"resource":{"addr":"random_pet.db_username","module":"","resource":"random_pet.db_username","implied_provider":"random","resource_type":"random_pet","resource_name":"db_username","resource_key":null},"id_key":"id","id_value":"learningreindeer"},"type":"refresh_start"}
{"@level":"info","@message":"random_pet.db_username: Refresh complete [id=learningreindeer]","@module":"terraform.ui","@timestamp":"2022-09-20T09:11:57.704131+01:00","hook":{"resource":{"addr":"random_pet.db_username","module":"","resource":"random_pet.db_username","implied_provider":"random","resource_type":"random_pet","resource_name":"db_username","resource_key":null},"id_key":"id","id_value":"learningreindeer"},"type":"refresh_complete"}
{"@level":"info","@message":"Plan: 0 to add, 0 to change, 0 to destroy.","@module":"terraform.ui","@timestamp":"2022-09-20T09:11:57.706595+01:00","changes":{"add":0,"change":0,"remove":0,"operation":"plan"},"type":"change_summary"} |
I faced the same problem with v3.4.3:
I pulled the state from the remote, and this is how it looked like:
As a workaround, I set the Alternatively, you could import the random resource and let it be replaced by running targeted |
Hi @mshkrebtan 👋 Sorry you ran into trouble here. Can you let us have:
|
I used
|
Didn't work... setting id = 2 in the state file and pushing it back, still makes it wanting to replace it and terraform state show still shows id = "2" |
@ohookins are you able to provide any further information on the issue you're experiencing with random_pet? I've tried to reproduce the issue but I've been unable to do so. @mshkrebtan @trunet @MortezaBashsiz it appears that you are describing an issue on a different resource to the one outlined by @ohookins. The issue you're describing for random_integer is fixed in |
I was able to work around this by removing from the state file and importing with the old value. terraform state rm module.example.random_id.this
terraform import module.example.random_id.this NWZuNHcK |
Sorry I haven't written back for a while, other things have taken precedence and I haven't been able to provide much that is useful to debugging this issue. I've upgraded in the meantime to 3.5.1 and still encounter the issue:
The resource is defined as:
How it appears in the state file:
I'm wondering about |
I edited one state file and replaced the null attribute with an actual empty string - this appears to fix the problem. Unfortunately we have far too many random_pet resources and statefiles in numerous environments to apply the same fix to all. It would be ideal if the provider would treat the |
So, we've just tried upgrading to the latest provider version (3.6.0 at time of writing) and the bug is still there. I've conducted some further tests. Unfortunately the trace logs aren't particularly illuminating but I can post them if desired. Here's the resource configuration: resource "random_pet" "db_username" {
length = 2
separator = ""
} The previous resource state from the state file: {
"schema_version": 0,
"attributes": {
"id": "speedytortoise",
"keepers": null,
"length": 2,
"prefix": null,
"separator": null
},
"sensitive_attributes": []
} Applying with the current version provider wants to destroy and recreate the resource. Allowing it to do so results in this resource in the state file: {
"schema_version": 0,
"attributes": {
"id": "presentinsect",
"keepers": null,
"length": 2,
"prefix": null,
"separator": ""
},
"sensitive_attributes": []
} You will note that the only thing that changes is the Looking back at my previous comment I guess this doesn't add much to it. Could we safely treat the previous |
Upon further testing, this appears to only affect a couple of our oldest workspaces. I suspect there was a bug in very old versions around whether an empty separator was stored as So the "real" bug in this case is probably quite far back in history, but versions 3.4 and later don't allow for it to be gracefully fixed without replacing the random id. In our case I think I'll just modify the state file to resolve the problem - I'll leave it for others affected to suggest the criticality. It may also be tricky to resolve in terms of backwards/forwards compatibility. |
Terraform CLI and Provider Versions
Terraform 1.1.8
hashicorp/random 3.4.0 - 3.4.3
Terraform Configuration
Expected Behavior
Unchanged
random_pet
resources should not be touched.Actual Behavior
It seems like this started occurring after 3.4.0 and I can confirm it is still broken in 3.4.3.
On the face of it, it looks like #302 but it is not fixed in 3.4.3.
Steps to Reproduce
terraform apply
How much impact is this issue causing?
High
Logs
No response
Additional Information
I'm marking this high severity as we use this for numerous usernames/passwords and this is causing Terraform to want to destroy databases and other stateful data stores, and destroying these is pretty bad.
We are reverting to 3.3.2 for the moment.
Code of Conduct
The text was updated successfully, but these errors were encountered: