You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the initial apply, everything works as expected:
Terraform will perform the following actions:
# tls_private_key.tls_keys1["test1-1"] will be created
+ resource "tls_private_key" "tls_keys1" {
+ algorithm = "ECDSA"
+ ecdsa_curve = "P224"
+ id = (known after apply)
+ private_key_pem = (sensitive value)
+ public_key_fingerprint_md5 = (known after apply)
+ public_key_openssh = (known after apply)
+ public_key_pem = (known after apply)
+ rsa_bits = 2048
}
# tls_private_key.tls_keys2["test2-1"] will be created
+ resource "tls_private_key" "tls_keys2" {
+ algorithm = "ECDSA"
+ ecdsa_curve = "P224"
+ id = (known after apply)
+ private_key_pem = (sensitive value)
+ public_key_fingerprint_md5 = (known after apply)
+ public_key_openssh = (known after apply)
+ public_key_pem = (known after apply)
+ rsa_bits = 2048
}
Plan: 2 to add, 0 to change, 0 to destroy.
tls_private_key.tls_keys1["test1-1"]: Creating...
tls_private_key.tls_keys2["test2-1"]: Creating...
tls_private_key.tls_keys2["test2-1"]: Creation complete after 0s [id=09bdf230615fda93e7acc5d2dce16b2963f156b2]
tls_private_key.tls_keys1["test1-1"]: Creation complete after 0s [id=e6c1bfd162e419c300f87313d528ebf917db8896]
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
Outputs:
tls_keys = {
"test1-1" = {
"algorithm" = "ECDSA"
"ecdsa_curve" = "P224"
"id" = "e6c1bfd162e419c300f87313d528ebf917db8896"
"private_key_pem" = "-----BEGIN EC PRIVATE KEY-----\nMGgCAQEEHDmoj0hG1d5vJ/LvfaaLSXig0pwxlYLCzdEqnb2gBwYFK4EEACGhPAM6\nAAQke9vNeguf8Rr1Qve0BmgkMnQDFjfoqBkCvWSL5Vv6mC9nxom7xeQF8OcucVIO\n0jLn1ND9eg8Ozg==\n-----END EC PRIVATE KEY-----\n"
"public_key_fingerprint_md5" = ""
"public_key_openssh" = ""
"public_key_pem" = "-----BEGIN PUBLIC KEY-----\nME4wEAYHKoZIzj0CAQYFK4EEACEDOgAEJHvbzXoLn/Ea9UL3tAZoJDJ0AxY36KgZ\nAr1ki+Vb+pgvZ8aJu8XkBfDnLnFSDtIy59TQ/XoPDs4=\n-----END PUBLIC KEY-----\n"
"rsa_bits" = 2048
}
"test2-1" = {
"algorithm" = "ECDSA"
"ecdsa_curve" = "P224"
"id" = "09bdf230615fda93e7acc5d2dce16b2963f156b2"
"private_key_pem" = "-----BEGIN EC PRIVATE KEY-----\nMGgCAQEEHAzq+mlr0E1BxxUfgWR3JzyaDMOwZtcobPWY5CigBwYFK4EEACGhPAM6\nAAR7dyfyWGZGLyupIcivfhrg0FJ9xpErYcIy+rS0wknVy9MJNM++y8eSFjD9cDx9\nciTOpHEFFMvNpQ==\n-----END EC PRIVATE KEY-----\n"
"public_key_fingerprint_md5" = ""
"public_key_openssh" = ""
"public_key_pem" = "-----BEGIN PUBLIC KEY-----\nME4wEAYHKoZIzj0CAQYFK4EEACEDOgAEe3cn8lhmRi8rqSHIr34a4NBSfcaRK2HC\nMvq0tMJJ1cvTCTTPvsvHkhYw/XA8fXIkzqRxBRTLzaU=\n-----END PUBLIC KEY-----\n"
"rsa_bits" = 2048
}
}
Then, when one of the local maps is emptied, it is expected that the removed objects get destroyed and the remaining objects are not touched. Up to and including the destroy of the removed objects this works as expected, but afterwards the merge output is unexpectedly empty:
There, when one of the merge inputs get empty due to destroyed objects, Terraform fails (after the actual destroy) with the following error:
Error: each.value cannot be used in this context
on main.tf line 87, in resource "hcloud_ssh_key" "ssh_keys":
87: public_key = each.value
A reference to "each.value" has been used in a context in which it
unavailable, such as when the configuration no longer contains the value in
its "for_each" expression. Remove this reference to each.value in your
configuration to work around this error.
Interestingly, this error never occurs with create_before_destroy = true.
@peterpramb Thank you for this excellent reproduction case!
I was able to confirm this issue on Terraform 0.13.2. Happily, it seems to be fixed as of Terraform 0.13.3, I believe due to #26264. As a result, I'm marking this issue as closed, but if the bug in your real configuration still exists, please do comment here or open another issue so that we can investigate further.
alisdair
added
explained
a Terraform Core team member has described the root cause of this issue in code
and removed
new
new issue not yet triaged
labels
Sep 17, 2020
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
ghost
locked as resolved and limited conversation to collaborators
Oct 18, 2020
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
bugexplaineda Terraform Core team member has described the root cause of this issue in code
Terraform Version
Terraform Configuration Files
Expected Behavior
merge
will return all remaining objects, when one of the inputs tomerge
gets empty.Actual Behavior
merge
result is empty, when one of the inputs tomerge
gets empty.Steps to Reproduce
terraform init
terraform apply
terraform apply
terraform apply
Additional Context
With the initial
apply
, everything works as expected:Then, when one of the local maps is emptied, it is expected that the removed objects get destroyed and the remaining objects are not touched. Up to and including the destroy of the removed objects this works as expected, but afterwards the
merge
output is unexpectedly empty:Please note the missing
outputs
. The state is now empty too:Just with the next
apply
the missing objects appear again:Additional info:
The provided code above is for simple reproduction. In the real code
merge
is used on a cloud resource, like shown:There, when one of the
merge
inputs get empty due to destroyed objects,Terraform
fails (after the actual destroy) with the following error:Interestingly, this error never occurs with
create_before_destroy = true
.References
The text was updated successfully, but these errors were encountered: