Skip to content

Terraform test - Add support terraform functions in mock objects #34672

@LaurentLesle

Description

@LaurentLesle

Terraform Version

1.7.3

Use Cases

I want to generate test data based on specific data type or string format:

  • for a GUID use uuid()
  • for an Azure resource id use format("/subscriptions/%s", uuid())

Attempted Solutions

mock_data "azurerm_client_config" {
  defaults = {
    client_id = uuid()
  }
}


override_resource {
  target = azurerm_storage_account.example   
  values = {
      id = format("/subscriptions/%s/resourceGroups/example/providers/Microsoft.Storage/storageAccounts/myaccount", uuid())  
 }
}

Error when trying to use a function:

Error: Function calls not allowed
│ 
│   on tests/mock_data/data.tfmock.hcl line 9, in mock_data "azurerm_client_config":
│    9:     client_id = uuid()
│ 
│ Functions may not be called here.

Proposal

No response

References

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions