Ephemeral variables (#3108)

Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
This commit is contained in:
Andrei Ciobanu
2025-08-11 15:37:18 +03:00
committed by Christian Mesh
parent 528b778363
commit 013097b631
62 changed files with 1791 additions and 118 deletions

View File

@@ -0,0 +1,6 @@
// Running this configuration is expected to have an error since data sources are not allowed
// to use ephemeral values at all.
data "simple_resource" "test_data1" {
provider = simple.s1
value = var.in
}

View File

@@ -0,0 +1,6 @@
// Running this configuration is expected to return an error since variables not configured as ephemeral
// are not allowed to use ephemeral values.
module "test" {
source = "./non-ephemeral-mod"
in = var.in
}

View File

@@ -0,0 +1,5 @@
// Running this configuration is expected to have an error since output blocks not configured as ephemeral
// are not allowed to use ephemeral values.
output "out" {
value = var.in
}

View File

@@ -0,0 +1,6 @@
// Running this configuration is expected to have an error since `value` is not a write-only argument.
// Regular resources arguments are not allowed to use ephemeral variables and values
resource "simple_resource" "test_res" {
provider = simple.s1
value = var.in
}

View File

@@ -0,0 +1,28 @@
// the provider-plugin tests uses the -plugin-cache flag so terraform pulls the
// test binaries instead of reaching out to the registry.
terraform {
required_providers {
simple = {
source = "registry.opentofu.org/hashicorp/simple"
}
}
}
provider "simple" {
alias = "s1"
}
variable "in" {
ephemeral = true
type = string
}
variable "in2" {
ephemeral = true
type = string
default = "in2 default value just to test the validations"
validation {
condition = var.in2 != "fail_on_this_value"
error_message = "variable 'in2' value '${var.in2}' cannot be 'fail_on_this_value'"
}
}

View File

@@ -0,0 +1,8 @@
// Module that is used strictly to test passing in and out ephemeral variables.
variable "in" {
type = string
}
output "out" {
value = var.in
}