Bootstrap FreeKB - Terraform - Refresh Terraform using the terraform refresh command
Terraform - Refresh Terraform using the terraform refresh command

Updated:   |  Terraform articles

The terraform refresh command can be used to refresh Terraform, typically after you make an update to one or more of your .tf files. Additionally, the terraform refresh command will create the terraform.tfstate file if it does not yet exist in your present working directory.

Let's say you have the following files on your Terraform server.

├── main.tf (root module)
├── data.tf
├── locals.tf
├── outputs.tf
├── providers.tf
├── terraform.tfstate
├── variables.tf
├── child (directory)
│   ├── main.tf (child module)
│   ├── data.tf
│   ├── outputs.tf
│   ├── resources.tf

 

And let's say you make a change to one or more of the files. For example, perhaps you add an output to the outputs.tf files in the child module and main root module.

output "my_vpcs" {
  value = data.aws_vpcs.my-vpcs
}

 

The terraform refresh command can then be used to refresh Terraform to pick up this change which in this example may return something like this, the newly added output.

~]$ terraform refresh

Outputs:

vpcs = {
  "filter" = toset(null) /* of object */
  "id" = "us-east-2"
  "ids" = tolist([])
  "tags" = tomap({
    "Name" = "my-vpc"
  })
  "timeouts" = null /* object */
}

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter b277f0 in the box below so that we can be sure you are a human.