.terraformignorefile serves the purpose of ignoring parts of the configuration that a user uploads to Terraform Cloud in order to save time on CLI-driven runs. More information on the use case can be found in this article.
In certain situations, the
.terraformingore file may appear as it is not performing as expected. That could be due to a wrong configuration.
TF_IGNORE=trace environment variable while performing your Terraform runs will show an output of which files inside the configuration will not be uploaded to Terraform Cloud.
As a demonstration consider the following configuration tree structure:
├── .DS_Store ├── .terraformignore ├── directory1 │ ├── .DS_Store │ └── subdirectory1 │ ├── .DS_Store │ ├── .terraform │ │ ├── environment │ │ ├── providers │ │ │ └── registry.terraform.io │ │ │ └── hashicorp │ │ │ └── null │ │ │ └── 3.1.0 │ │ │ └── darwin_amd64 │ │ │ └── terraform-provider-null_v3.1.0_x5 │ │ └── terraform.tfstate │ ├── .terraform.lock.hcl │ ├── largefolder │ │ └── largefile70mb │ └── main.tf ├── directory2 │ └── main.tf ├── directory3 │ └── main.tf ├── directory4 │ └── main.tf └── largefile70mb
.terraformignore file in the above example should ignore all folders and files except contents of
directory1 but ignore everything inside the
We are using a working directory in the Terraform Cloud Workspace -
$ export TF_IGNORE=trace $ cd directory1/subdirectory1 $ terraform plan Running plan in the remote backend. Output will stream here. Pressing Ctrl-C will stop streaming the logs, but will not stop the plan running remotely. Preparing the remote plan... The remote workspace is configured to work with configuration at directory1/subdirectory1 relative to the target repository. Terraform will upload the contents of the following directory, excluding files or directories as defined by a .terraformignore file at /terraform/testing_terraform_ignore/.terraformignore (if it is present), in order to capture the filesystem context the remote workspace expects: /terraform/testing_terraform_ignore Skipping excluded path: .DS_Store Skipping excluded path: .terraformignore Skipping excluded path: directory1 Skipping excluded path: directory1/subdirectory1/largefolder/ Skipping excluded path: directory1/subdirectory1/largefolder/largefile70mb Skipping excluded path: directory2 Skipping excluded path: directory2/main.tf Skipping excluded path: directory3 Skipping excluded path: directory3/main.tf Skipping excluded path: directory4 Skipping excluded path: directory4/main.tf Skipping excluded path: largefile70mb Waiting for the plan to start...
TF_IGNOREwill show every single file that will be skipped from upload in the output. If a directory path is shown as skipped that is not a sign of its contents being skipped as well.