Skip to content

Commit d18c34b

Browse files
authored
Add support ephemeral variables in TestRunner (#361)
1 parent 75fd705 commit d18c34b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

helper/runner.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,9 @@ func decodeVariableBlock(block *hcl.Block) (*Variable, hcl.Diagnostics) {
415415
{
416416
Name: "sensitive",
417417
},
418+
{
419+
Name: "ephemeral",
420+
},
418421
},
419422
})
420423
if diags.HasErrors() {
@@ -438,6 +441,15 @@ func decodeVariableBlock(block *hcl.Block) (*Variable, hcl.Diagnostics) {
438441

439442
v.Default = v.Default.Mark(marks.Sensitive)
440443
}
444+
if attr, exists := content.Attributes["ephemeral"]; exists {
445+
var ephemeral bool
446+
diags := gohcl.DecodeExpression(attr.Expr, nil, &ephemeral)
447+
if diags.HasErrors() {
448+
return v, diags
449+
}
450+
451+
v.Default = v.Default.Mark(marks.Ephemeral)
452+
}
441453

442454
return v, nil
443455
}

helper/runner_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,20 @@ resource "aws_instance" "foo" {
622622
}`,
623623
Want: `cty.StringVal("secret").Mark(marks.Sensitive)`,
624624
},
625+
{
626+
Name: "ephemeral variable",
627+
Src: `
628+
variable "instance_type" {
629+
type = string
630+
default = "secret"
631+
ephemeral = true
632+
}
633+
634+
resource "aws_instance" "foo" {
635+
instance_type = var.instance_type
636+
}`,
637+
Want: `cty.StringVal("secret").Mark(marks.Ephemeral)`,
638+
},
625639
}
626640

627641
for _, test := range tests {

0 commit comments

Comments
 (0)