mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-25 01:00:16 -05:00
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:
committed by
Christian Mesh
parent
528b778363
commit
013097b631
@@ -8,21 +8,36 @@ terraform {
|
||||
}
|
||||
}
|
||||
|
||||
variable "simple_input" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "ephemeral_input" {
|
||||
type = string
|
||||
ephemeral = true
|
||||
validation {
|
||||
condition = var.ephemeral_input == "ephemeral_val"
|
||||
error_message = "this is just to ensure that error_message is not executed when condition suceeds. If the condition fails, it will fail because this message references an ephemeral value ${var.ephemeral_input}}"
|
||||
}
|
||||
}
|
||||
|
||||
provider "simple" {
|
||||
alias = "s1"
|
||||
// NOTE we want to ensure that ephemeral variables can be used as provider configuration
|
||||
i_depend_on = var.ephemeral_input
|
||||
}
|
||||
|
||||
data "simple_resource" "test_data1" {
|
||||
provider = simple.s1
|
||||
value = "initial data value"
|
||||
value = var.simple_input
|
||||
}
|
||||
|
||||
ephemeral "simple_resource" "test_ephemeral" {
|
||||
count = 2
|
||||
count = 2
|
||||
provider = simple.s1
|
||||
// Having that "-with-renew" suffix, later when this value will be passed into "simple_resource.test_res.value_wo",
|
||||
// the plugin will delay the response on some requests to allow ephemeral Renew calls to be performed.
|
||||
value = "${data.simple_resource.test_data1.value}-with-renew"
|
||||
value = "${data.simple_resource.test_data1.value}-${var.ephemeral_input}-with-renew"
|
||||
}
|
||||
|
||||
resource "simple_resource" "test_res" {
|
||||
@@ -36,27 +51,30 @@ resource "simple_resource" "test_res" {
|
||||
provisioner "local-exec" {
|
||||
command = "echo \"not visible ${ephemeral.simple_resource.test_ephemeral[0].value}\""
|
||||
}
|
||||
provisioner "local-exec" {
|
||||
command = "echo \"not visible ${var.ephemeral_input}\""
|
||||
}
|
||||
// NOTE: value_wo cannot be used in a provisioner because it is returned as null by the provider so the interpolation fails
|
||||
}
|
||||
|
||||
data "simple_resource" "test_data2" {
|
||||
provider = simple.s1
|
||||
value = "test"
|
||||
value = "test"
|
||||
lifecycle {
|
||||
precondition {
|
||||
// NOTE: precondition blocks can reference ephemeral values
|
||||
condition = ephemeral.simple_resource.test_ephemeral[0].value != null
|
||||
condition = ephemeral.simple_resource.test_ephemeral[0].value != null
|
||||
error_message = "test message"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
locals{
|
||||
locals {
|
||||
simple_provider_cfg = ephemeral.simple_resource.test_ephemeral[0].value
|
||||
}
|
||||
|
||||
provider "simple" {
|
||||
alias = "s2"
|
||||
alias = "s2"
|
||||
// NOTE: Ensure that ephemeral values can be used to configure a provider.
|
||||
// This is needed in two cases: during plan/apply and also during destroy.
|
||||
// This test has been updated when DestroyEdgeTransformer was updated to
|
||||
@@ -72,16 +90,18 @@ provider "simple" {
|
||||
|
||||
resource "simple_resource" "test_res_second_provider" {
|
||||
provider = simple.s2
|
||||
value = "just a simple resource to ensure that the second provider it's working fine"
|
||||
value = "just a simple resource to ensure that the second provider it's working fine"
|
||||
}
|
||||
|
||||
module "call" {
|
||||
source = "./mod"
|
||||
in = ephemeral.simple_resource.test_ephemeral[0].value // NOTE: because variable "in" is marked as ephemeral, this should work as expected.
|
||||
in = ephemeral.simple_resource.test_ephemeral[0].value
|
||||
// NOTE: because variable "in" is marked as ephemeral, this should work as expected.
|
||||
}
|
||||
|
||||
output "out_ephemeral" {
|
||||
value = module.call.out2 // TODO: Because the output ephemeral marking is not done yet entirely, this is working now but remove this output once the marking of outputs are done completely.
|
||||
value = module.call.out2
|
||||
// TODO: Because the output ephemeral marking is not done yet entirely, this is working now but remove this output once the marking of outputs are done completely.
|
||||
}
|
||||
|
||||
output "final_output" {
|
||||
|
||||
Reference in New Issue
Block a user