Terraform folder structure ready to run terraform test command
.
├── main.tf
├── modules
│ └── resource_group
│ ├── main.tf
│ ├── output.tf
│ └── variables.tf
├── providers.tf
└── tests
└── main.tftest.hcl
providers.tf
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "\~> 4.10.0"
}
}
}
provider "azurerm" {
features {}
}
Error below
% terraform test -verbose
tests/main.tftest.hcl... in progress
run "verify_azure_resource_group_creation"... fail
╷
│ Error: Invalid provider configuration
│
│ Provider " registry.terraform.io/hashicorp/azurerm " requires explicit configuration. Add a provider block to the root module and configure
│ the provider's required arguments as described in the provider documentation.
│
╵
╷
│ Error: Missing required argument
│
│ with provider\[" registry.terraform.io/hashicorp/azurerm "\],
│ on line 0:
│ (source code not available)
│
│ The argument "features" is required, but no definition was found.
╵
tests/main.tftest.hcl... tearing down
tests/main.tftest.hcl... fail
Failure! 0 passed, 1 failed
I’m struggling to get this running, as I don’t understand how the terraform test folder structure is working. My aim to define the folder structure like above where all terraform resources are in each subfolder of modules folder and the final terraform module declarative is in the root folder. What did I do wrong?