I am starting to use Terraform and I have a .terraform folder created by "terraform init/apply" containing :
Should I version these files ? I would say no ...
The .terraform
directory is a local cache where Terraform retains some files it will need for subsequent operations against this configuration. Its contents are not intended to be included in version control.
However, you can ensure that you can faithfully reproduce this directory on other systems by specifying certain things in your configuration that inform what Terraform will place in there:
Use required_providers
in a terraform
block to specify an exact version constraint for the Google Cloud Platform provider:
terraform {
required_providers {
google = "3.0.0"
}
}
(this relates to the .terraform/plugins
directory)
In each module you call (which seems to be none so far, but perhaps in future), ensure its source
refers to an exact version rather than to a floating branch (for VCS modules) or set version
to an exact version (for modules from Terraform Registry):
module "example"
source = "git::https://github.com/example/example.git?ref=v2.0.0"
# ...
}
module "example"
source = "hashicorp/consul/aws"
version = "v1.2.0
}
(this relates to the .terraform/modules
directory)
If you are using a remote backend, include the full configuration in the backend
block inside the terraform
block, rather than using the -backend-config
argument to terraform init
.
(this relates to the .terraform/terraform.tfstate
file, which remembers your active backend configuration for later operations)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With