Skip to content

Commit

Permalink
Add support ephemeral variables in TestRunner (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
wata727 authored Jan 6, 2025
1 parent 75fd705 commit d18c34b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions helper/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ func decodeVariableBlock(block *hcl.Block) (*Variable, hcl.Diagnostics) {
{
Name: "sensitive",
},
{
Name: "ephemeral",
},
},
})
if diags.HasErrors() {
Expand All @@ -438,6 +441,15 @@ func decodeVariableBlock(block *hcl.Block) (*Variable, hcl.Diagnostics) {

v.Default = v.Default.Mark(marks.Sensitive)
}
if attr, exists := content.Attributes["ephemeral"]; exists {
var ephemeral bool
diags := gohcl.DecodeExpression(attr.Expr, nil, &ephemeral)
if diags.HasErrors() {
return v, diags
}

v.Default = v.Default.Mark(marks.Ephemeral)
}

return v, nil
}
Expand Down
14 changes: 14 additions & 0 deletions helper/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,20 @@ resource "aws_instance" "foo" {
}`,
Want: `cty.StringVal("secret").Mark(marks.Sensitive)`,
},
{
Name: "ephemeral variable",
Src: `
variable "instance_type" {
type = string
default = "secret"
ephemeral = true
}
resource "aws_instance" "foo" {
instance_type = var.instance_type
}`,
Want: `cty.StringVal("secret").Mark(marks.Ephemeral)`,
},
}

for _, test := range tests {
Expand Down

0 comments on commit d18c34b

Please sign in to comment.