Skip to content

timestamp() always triggers resource replacement, even when it is interpolated #22461

@eerkunt

Description

@eerkunt

Terraform Version

Terraform v0.12.6
+ provider.aws v2.23.0
+ provider.random v2.2.0

Terraform Configuration Files

resource "aws_lightsail_instance" "test" {
  name              = "test-${formatdate("YYYYMMDD", timestamp())}"
  availability_zone = "eu-west-1a"
  blueprint_id      = "ubuntu_18_04"
  bundle_id         = "small_2_0"
}

Expected Behavior

Resource replacement every day due to formatdate() interpolation with YYYYMMDD.

Actual Behavior

Resource replacement on every run.

Steps to Reproduce

  1. terraform init
  2. terraform apply

Additional Context

I also tried the same code using random_id with the code example below ;

resource "random_id" "test" {
  keepers = {
    date = formatdate("YYYYMMDD", timestamp())
  }

  byte_length = 8
}

resource "aws_lightsail_instance" "test" {
  name              = "test-${random_id.test}"
  availability_zone = "eu-west-1a"
  blueprint_id      = "ubuntu_18_04"
  bundle_id         = "small_2_0"
}

same problem. Whenever timestamp() is used, a new resource creation is triggered.

The only way I could fix this problem is to define a date variable and pass it via -var on the CLI.

References

Couldn't find any reference specific to this problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions