Testing - passing input variables to a module

How can I pass variable to a module:


provider "azurerm" {
  features {}
}

run "default_location" {
  command = plan

  module {
    source = "../../module/resource"

    #Input variables
    environment  =  "sand"
    costCentre = "123456"
    application = "myapp"
    resourceName = "rg-sand-myapp"
  }

  assert {
    condition     = azurerm_resource_group.main.location == "uksouth"
    error_message = "Resource group default location incorrect."
  }
}

When I run this I get these errors:

│ Error: Unsupported argument
│ on tests/unit.tftest.hcl line 13, in run “default_location”:
│ 13: environment = “sand”

│ An argument named “environment” is not expected here.


│ Error: Unsupported argument

│ on tests/unit.tftest.hcl line 14, in run “default_location”:
│ 14: costCentre = “123456”

│ An argument named “costCentre” is not expected here.


│ Error: Unsupported argument

│ on tests/unit.tftest.hcl line 15, in run “default_location”:
│ 15: application = “myapp”

│ An argument named “application” is not expected here.


│ Error: Unsupported argument

│ on tests/unit.tftest.hcl line 16, in run “default_location”:
│ 16: resourceName = “rg-sand-myapp”

│ An argument named “resourceName” is not expected here.

Found the answer here: How do I pass provider information to tests?

run "default_location" {
  command = plan

  module {
      source = "../../module/resource"
    }

    variables {
      # Module Input variables
      environment  =  "sand"
      costCentre = "123456"
      application = "myapp"
      resourceName = "rg-sand-myapp"
    }

  assert { .....
1 Like