If the timestamp()
function is added to the tags, then it destroys all of the default tags.
In order to prevent this, use the timestamp()
function under a locals block and reference the locals block in the tags.
Example: Below example depicts the use of timestamp()
, tags and along with merge()
.
provider "aws" {
region = "us-west-2"
}
variable "extra_tags" {
default = {
tags = {
Enviroment = "tags-test-env"
}
}
}
data "aws_caller_identity" "current" {}
locals {
computed_tags = {
LastModifiedTime = "${timestamp()}"
LastModifiedBy = "${data.aws_caller_identity.current.arn}"
}
merged_tags = merge(local.computed_tags, var.extra_tags)
}
output "map" {
value = local.merged_tags
}
output "ignore_list" {
value = ["${keys(local.merged_tags)}"]
}
Output:
+ ignore_list = [
+ [
+ "LastModifiedBy",
+ "LastModifiedTime",
+ "tags",
],
]
+ map = {
+ LastModifiedBy = "arn:aws:sts::323533494701:assumed-role/support_terraform_dev-developer/mtadiparthi@hashicorp.com"
+ LastModifiedTime = (known after apply)
+ tags = {
+ Enviroment = "tags-test-env"
}
}
Documentation: