Search code examples
amazon-web-servicesterraform

What does version in Terraform state mean?


I'm using s3 bucket as remote state. I'm just confused what the value of version ("version": 4) in tfstate file means.

{
  "version": 4,
  "terraform_version": "1.2.1",
  "serial": 402,
  "lineage": "0e5a03fc-1b6f-e56b-8c9b-a0e0a1756f12",
  "outputs": {},
  "resources": [
    {
      "module": "module.aws_cloudwatch",
      "mode": "managed",

Solution

  • It's the version of the terraform state file. The version is managed by terraform itself.

    In a Terraform state file, there are three "types of versions":

    • The syntax version of the state file itself
    • The versions of the provider used to create each of the resources
    • The Terraform version used to initially create the state file

    The versions of a state file may change due to the following:

    • An updated version of the Terraform core that works with the state file
    • An updated provider is used to apply resources
    • This one can't change, as the state file is only every created for the first time once
    • The versions within a state file can only be updated (and are only updated) by running a terraform apply