Variables.tf in terraform test

I’m trying to use the experimental terraform test command, and it appears to be ignoring my variables.tf in the test suite directory.

the tree looks something like;

.
├── README.md
├── data.tf
├── locals.tf
├── main.tf
├── nat.tf
├── outputs.tf
├── providers.tf
├── security.tf
├── tests
│   └── defaults
│       ├── main.tf
│       ├── providers.tf
│       ├── terraform.tfstate
│       ├── test-subnet-discovery.tf
│       └── variables.tf
└── variables.tf

and tests/defaults/variablles.tf contains “descriptive inputs” to my tests. e.g.

variable "min_private_hosts" {
  description = "minimum number of hosts in each private network block"
  default     = 1024
}

variable "min_intra_hosts" {
  description = "minimum number of hosts in each private network block"
  default     = 2048
}

variable "cidr" {
  default = "10.255.0.0/20"
}

upon running terraform test I am seeing:

─── Error: defaults (terraform plan) ──────────────────────────────────────────────────────────
failed to create a plan
╷
│ Error: Unassigned variable
│
│ The input variable "min_private_hosts" has not been assigned a value. This is a bug in
│ Terraform; please report it in a GitHub issue.
╵
╷
│ Error: Unassigned variable
│
│ The input variable "min_intra_hosts" has not been assigned a value. This is a bug in
│ Terraform; please report it in a GitHub issue.
╵
╷
│ Error: Unassigned variable
│
│ The input variable "cidr" has not been assigned a value. This is a bug in Terraform; please
│ report it in a GitHub issue.

Previously I organized my tests under the tests/ folder and have CI manually enter and run terraform init|apply|destroy – but I now would like to take advantage of the test_assertions resource.

Does the terraform test command skip loading of all files in the test suite directory?

Also I was wondering why limit terraform test to “module” testing?

1 Like