Skip to content

Allow the use of ephemeral values in the output for test modules #37805

@whereyourspace

Description

@whereyourspace

Terraform Version

Terraform v1.13.1
on linux_amd64

Use Cases

  1. Create a subdirectory testing/setup with:
ephemeral "vault_kv_secret_v2" "proxmox_creds" {
  mount = "infra-secrets"
  name  = "testing/proxmox/creds"
}

locals {
  proxmox_creds = ephemeral.vault_kv_secret_v2.proxmox_creds.data
}

output "creds" {
  description = "Sensitive information obtained from Vault"
  ephemeral   = true
  sensitive   = true

  value = {
    proxmox = {
      username = local.proxmox_creds.username
      password = local.proxmox_creds.password
    }
  }
}
  1. Reference it from a .tftest.hcl file:
run "setup" {
  module {
    source = "./testing/setup"
  }
}
  1. Run:
terraform test

And you will see errors related to the fact that terraform does not allow the use of ephemeral values in the output of root modules.

$ > terraform test
tests/main.tftest.hcl... in progress
  run "setup"... fail
╷
│ Error: Ephemeral output not allowed
│ 
│   on testing/setup/outputs.tf line 20:
│   20: output "creds" {
│ 
│ Ephemeral outputs are not allowed in context of a root module
╵
  run "apply"... skip
  run "verify"... skip

$ > terraform validate
╷
│ Error: Ephemeral output not allowed
│ 
│   on testing/setup/outputs.tf line 20:
│   20: output "creds" {
│ 
│ Ephemeral outputs are not allowed in context of a root module
╵

I think this is not entirely correct, although it is not critical, given that corresponding data sources are deprecated.

> $ terraform validate
╷
│ Warning: Deprecated Resource
│ 
│   with data.vault_kv_secret_v2.proxmox_creds,
│   on testing/setup/main.tf line 1, in data "vault_kv_secret_v2" "proxmox_creds":
│    1: data "vault_kv_secret_v2" "proxmox_creds" {
│ 
│ Deprecated. Please use new Ephemeral KVV2 Secret resource `vault_kv_secret_v2` instead
╵
Success! The configuration is valid, but there were some validation warnings as shown above.

Attempted Solutions

I didn't find it. I had to use data sources instead of ephemeral data.

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