0.12.6
provider "aws" {}
resource "aws_s3_bucket" "foo" {
bucket = "bar"
logging {
target_bucket = "baz"
target_prefix = "log/"
}
lifecycle {
ignore_changes = [logging[0].target_bucket]
}
}
https://gist.github.com/ryzr/46c4dbd7f085efa76bb4aad96194b502
The target_bucket key of the first logging set should be ignored.
The following error output is produced:
Error: Cannot index a set value
on main.tf line 12, in resource "aws_s3_bucket" "foo":
12: ignore_changes = [logging[0].target_bucket]
Block type "logging" is represented by a set of objects, and set elements do
not have addressable keys. To find elements matching specific criteria, use a
"for" expression with an "if" clause.
terraform initterraform applyI've scoured the internet for any other possible variations I could use, and failed (all produce the same error):
logging.target_bucket
logging.0.target_bucket
logging["*"].target_bucket
logging["%"].target_bucket
logging["#"].target_bucket
Hi @ryzr,
Sorry you're experiencing an issue with this configuration. This does however appear to be working as intended.
A "set" data structure is unordered, and therefore has no way of consistently addressing individual elements of the set. One possibility here is that we might be able to extend the syntax to allow addressing an attribute of _all_ set elements, e.g. logging[*].target_bucket would ignore changes if _any_ target_bucket were to change, though it is a very limited use case.
The only way to allow addressing of individual logging instances at the moment would if the provider could change the structure to a TypeList allowing for indexed addressing of the elements.
Hi,
Having the same issue with autoscaling group when i'm trying to ignore a specific Tag :
lifecycle {
ignore_changes = [tag["DateTimeTag"]]
}
Block type "tag" is represented by a set of objects, and set elements do not
have addressable keys. To find elements matching specific criteria, use a
"for" expression with an "if" clause.
I'm using Terraform v0.12.6
I'm experiencing the same issue with ignoring snapshot_id in ebs_block_device sets. When we launch an instance from an ami created with Packer that has multiple block devices terraform wants to rebuild the instance after subsequent runs because of the presence of the snapshot id.
Error: Attribute name required
on main.tf line 226, in resource "aws_instance" "sql_server":
226: ignore_changes = ["ebs_block_device.*.snapshot_id"]
Splat expressions (.*) may not be used here.```
Error: Cannot index a set value
on main.tf line 226, in resource "aws_instance" "sql_server":
226: ignore_changes = ["ebs_block_device.snapshot_id"]
Block type "ebs_block_device" is represented by a set of objects, and set
elements do not have addressable keys. To find elements matching specific
criteria, use a "for" expression with an "if" clause.
So any solutions for this issue ?
Would it be possible to introduce a way of manually indexing set members?
provider "aws" {}
resource "aws_s3_bucket" "foo" {
bucket = "bar"
logging {
index = 0
target_bucket = "baz"
target_prefix = "log/"
}
lifecycle {
ignore_changes = [logging[0].target_bucket]
}
}
I'm unfamiliar with the internals of Terraform, but if this is doable, I could probably take a stab at it.
Also running into this issue when using kubernetes resources that can be dynamically updated by operators (e.g. a namespace where the operators add their own annotations to a namespace).
Related to this issue:
Some resources such as aws_autoscaling_group name-based tag indexing does not work the same as other aws_* resources. So it's not possible to use the normal syntax: ignore_changes = [ tags["Name_of_tag"] ]
It appears that tags on this resource are a set / list of maps. For example:
tags = [
{
"key" = "foo"
"propagate_at_launch" = "true"
"value" = "some value"
},
{
"key" = "bar"
"propagate_at_launch" = "true"
"value" = "another value"
},
## [...SNIP...]
]
The workaround is to use numeric list indexing like this:
lifecycle {
create_before_destroy = true
ignore_changes = [
# Ignore changes to first tag in list: "foo"
tags[0]
]
}
This breaks anytime the ordering of tags changes... so be aware of that issue, given that this is an order-based workaround for ignoring tag changes by name (ignore_changes = [ tags["foo"] ]).
The workaround is to use numeric list indexing like this:
lifecycle { create_before_destroy = true ignore_changes = [ # Ignore changes to first tag in list: "foo" tags[0] ] }.
It's not working for me, i'm receiving this error :
Error: Cannot index a set value
on autoscaling.tf line 61, in resource "aws_autoscaling_group" "ecs":
61: ignore_changes = [tag[10]]
Block type "tag" is represented by a set of objects, and set elements do not
have addressable keys. To find elements matching specific criteria, use a
"for" expression with an "if" clause.
And here is my tag variable :
variable "resource_tagging" {
type = "map"
default = {
"Name" = "to_be_filled",
"ApplicationCode" = "app",
"SubProject" = "",
"Automation" = "None",
"BU" = "xx",
"Creator" = "",
"Criticity" = "3",
"Environment" = "env",
"Note" = "",
"Owner" = "",
"Support" = "",
"DateTimeTag" = "nodef"
}
}
@jbardin is this a bug in the documention at https://www.terraform.io/docs/configuration/resources.html#ignore_changes or a bug in terraform?
The tags applied here make it seem like you think this is a bug in the documentation but I have the same behavior as other reporters regarding changes to parts of a tags structure.
@janxious, this issue is not in reference to a bug in terraform or the documentation. Individual set elements are not addressable, and therefore cannot be referenced in ignore_changes. There may be some more helpful errors that terraform could return for now, and it may be possible to implement the functionality in some other way in the future, so for now this is marked as an enhancement.
for maps it would also be nice if the key could be supplied as a prefix or wildcard .. ie tags["xyz*"]
Ran into this issue when attempting to ignore the the aws_ecs_service load_balancer target_group_arn, which is updated dynamically via CodeDeploy during containerized Blue/Green deployments.
There might be something more actionable happen if you open an issue in https://github.com/terraform-providers/terraform-provider-aws repo (or search for a relevant issue); you could potentially suggest @jbardin 's idea of using a TypeList rather than a Set. I'm not actively developing with Terraform at the moment, so I'll leave that to someone else.
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.
Most helpful comment
Ran into this issue when attempting to ignore the the aws_ecs_service load_balancer target_group_arn, which is updated dynamically via CodeDeploy during containerized Blue/Green deployments.