Auto increment serial number on resource change

Is there a way to have a serial number that it’s increased each time a resource changes?

For example I have a SOA aws_route53_record and the first number in the record is the SOA Record SERIAL. Currently I have to manually update this serial number each time I do a modification on this record. Is there anyway to generate a serial number that it’s autoincremented on resource change?

resource "aws_route53_record" "soa" {
  allow_overwrite = true
  zone_id         = aws_route53_zone.main.zone_id
  name            =
  type            = "SOA"
  ttl             = "30"

  records = [ # serial refreshTTL retryTTL expiryTTL NXTTL
    format("%s. ${myserialnumber} 7200 900 1209600 300", aws_route53_zone.main.name_servers[0])
1 Like

I had a similar issue where I needed to generate an incrementing version number for a templated tampermonkey script, but only wanted to increment the number when another resource changed.


Example generates an epoch time stamp that would work for a zone serial

resource "time_static" "my_time_resource" {
  triggers = {
    changed_resource = resource.changed_resource_name

output "console_short_name_map_update_time" {
  value = time_static.my_time_resource.unix
1 Like