Score:0

Modification timestamp of Terraform state/files disagrees significantly with application timestamp

cn flag

So, I have a constellation of Terraform projects. I just built an image of a specific application, which ultimately ends-up updating the tags in the auto-vars file of the corresponding project in the Terraform repository and then applies it, and I noticed that the mtimes are really wacky. It's the 28th, today. The state file shows an mtime of three weeks ago (the 5th) even though I've probably done dozens of tangible releases since then, including having just updated these and applied them a moment ago. The mtime on the auto-vars file and the timestamps in the actual Docker image tags prove it (while taking my word for it that these were applied soon after updating the auto-vars).

$ ls -la
total 56
drwxr-xr-x 3 dustin dustin  4096 May 28 14:38 .
drwxr-xr-x 6 dustin dustin  4096 May  4 12:13 ..
-rw-r--r-- 1 dustin dustin  4300 May 16 12:34 main.tf
-rwxr-xr-x 1 dustin dustin    49 May  4 12:13 run.sh
drwxr-xr-x 4 dustin dustin  4096 May  5 15:30 .terraform
-rw-r--r-- 1 dustin dustin   298 May 28 14:38 terraform.auto.tfvars.json
-rw-r--r-- 1 dustin dustin  1409 May  5 15:30 .terraform.lock.hcl
-rw-r--r-- 1 dustin dustin 17556 May  5 15:29 terraform.tfstate.backup
-rw-r--r-- 1 dustin dustin   196 May  4 12:13 variables.tf

$ ls -la .terraform
total 20
drwxr-xr-x 4 dustin dustin 4096 May  5 15:30 .
drwxr-xr-x 3 dustin dustin 4096 May 28 14:38 ..
drwxr-xr-x 2 dustin dustin 4096 May  5 15:29 modules
drwxr-xr-x 3 dustin dustin 4096 May  5 15:30 providers
-rw-r--r-- 1 dustin dustin 1600 May  5 15:29 terraform.tfstate

$ cat terraform.auto.tfvars.json 
{
  "taskdefinition-web-fq-docker-image": "326764833890.dkr.ecr.us-east-1.amazonaws.com/workflow-web:eb241c0",
  "taskdefinition-app-fq-docker-image": "326764833890.dkr.ecr.us-east-1.amazonaws.com/workflow-api:20230528143624-abca7cf",
  "taskdefinition-release-version": "20230528143624-abca7cf"
}

The application I just did showed actions taken:

Plan: 1 to add, 1 to change, 1 to destroy.
module.task-definition.aws_ecs_task_definition.task-definition-default: Destroying... [id=workflow-api-staging]
module.task-definition.aws_ecs_task_definition.task-definition-default: Destruction complete after 1s
module.task-definition.aws_ecs_task_definition.task-definition-default: Creating...
module.task-definition.aws_ecs_task_definition.task-definition-default: Creation complete after 0s [id=workflow-api-staging]
module.load-balancer.module.service.aws_ecs_service.default: Modifying... [id=arn:aws:ecs:us-east-1:326764833890:service/internal-webserver-ssl/staging-workflow-api]
module.load-balancer.module.service.aws_ecs_service.default: Modifications complete after 0s [id=arn:aws:ecs:us-east-1:326764833890:service/internal-webserver-ssl/staging-workflow-api]

Apply complete! Resources: 1 added, 1 changed, 1 destroyed.

Can someone explain how Terraform manages the state mtimes? The documentation doesn't seem to go into detail.

cn flag
As a secondary question, I've begun capturing the state files into the repository in addition to the backend, but the local one never seems to change. What am I missing?
cn flag
Because it looks like the state-file itself will just have static references, at least when the backend is configured to store the state elsewhere.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.