docs: add explicit instruction for windows filepaths (#34193)

* docs: add explicit instruction for windows filepaths

* fix you/we/Terraform usage
pull/32328/merge
Liam Cervante 2 years ago committed by GitHub
parent ba57efb468
commit 1974c9ec16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -55,3 +55,80 @@ The `-cloud-run` option accepts a [private registry module source](/terraform/la
You must provide a module from a _private_ registry, not the public Terraform registry.
You must execute [`terraform login`](/terraform/cli/commands/login) before using this option, and ensure that your `hostname` argument matches the private registry hostname of your target module.
## Example: Test Directory Structure and Commands
The following directory structure represents an example directory tree for a Terraform module with tests and a setup module.
```
project/
|-- main.tf
|-- outputs.tf
|-- terraform.tf
|-- variables.tf
|-- tests/
| |-- validations.tftest.hcl
| |-- outputs.tftest.hcl
|-- testing/
|-- setup/
|-- main.tf
|-- outputs.tf
|-- terraform.tf
|-- variables.tf
```
At the root directory of the project, there are some typical Terraform configuration files: `main.tf`, `outputs.tf`, `terraform.tf`, and `variables.tf`. The test files, `validations.tftest.hcl` and `outputs.tftest.hcl`, are within the default tests directory: `tests`.
In addition, a [setup module](/terraform/language/tests#modules) for the tests exists within the `testing` directory.
In order to execute the tests you should run `terraform test` from the root configuration directory as if running `terraform plan` or `terraform apply`. Despite the actual test files being in the nested `tests` directory, Terraform executes from the main configuration directory.
Specific test files can be executed using the `-filter` option.
Linux, Mac OS, and UNIX:
```shell
terraform test -filter=tests/validations.tftest.hcl
```
PowerShell:
```shell
terraform test -filter='tests\validations.tftest.hcl'
```
Windows `cmd.exe`:
```shell
terraform test -filter=tests\validations.tftest.hcl
```
### Alternate Test Directories
In the above example the tests are in the default testing directory of `tests`. Test files can also be included directly within the main configuration directory:
```
project/
|-- main.tf
|-- outputs.tf
|-- terraform.tf
|-- variables.tf
|-- validations.tftest.hcl
|-- outputs.tftest.hcl
|-- testing/
|-- setup/
|-- main.tf
|-- outputs.tf
|-- terraform.tf
|-- variables.tf
```
The location of the testing files does not affect the operation of `terraform test`. All references to, and absolute file paths within, the testing files should be relative to the main configuration directory.
You can also use the `-test-directory` argument to change the location of the testing files. For example, `terraform test -test-directory=testing` would instruct Terraform to load tests from the directory `testing` instead of `tests`.
The testing directory must be beneath the main configuration directory, but it can be nested many times.
> Note: Test files within the root configuration directory are always loaded, regardless of the `-test-directory` value.
We do not recommend changing the default test directory. The option for customization is included for configuration authors who may have included a `tests` submodule in their configuration before the `terraform test` command was released. In general, the default test directory of `tests` should always be used.

@ -367,7 +367,21 @@ a _variable definitions file_ (with a filename ending in either `.tfvars`
or `.tfvars.json`) and then specify that file on the command line with
`-var-file`:
Linux, Mac OS, and UNIX:
```shell
terraform apply -var-file="testing.tfvars"
```
PowerShell:
```shell
terraform apply -var-file='testing.tfvars'
```
Windows `cmd.exe`:
```shell
terraform apply -var-file="testing.tfvars"
```

Loading…
Cancel
Save