Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions internal/terraform/context_plan_actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,52 @@ resource "test_object" "a" {
},
},

"ephemeral values": {
module: map[string]string{
"main.tf": `
variable "secret" {
type = string
ephemeral = true
}
action "test_action" "hello" {
config {
attr = var.secret
}
}
resource "test_object" "a" {
lifecycle {
action_trigger {
events = [before_create]
actions = [action.test_action.hello]
}
}
}
`,
},
planOpts: &PlanOpts{
Mode: plans.NormalMode,
SetVariables: InputValues{
"secret": &InputValue{
Value: cty.StringVal("secret"),
SourceType: ValueFromCLIArg,
}},
},
expectPlanActionCalled: false,
assertValidateDiagnostics: func(t *testing.T, diags tfdiags.Diagnostics) {
if len(diags) != 1 {
t.Fatalf("expected exactly 1 diagnostic but had %d", len(diags))
}

if diags[0].Severity() != tfdiags.Error {
t.Error("expected error diagnostic")
}

if diags[0].Description().Summary != "Invalid use of ephemeral value" {
t.Errorf("expected diagnostics to be because of ephemeral values but was %s", diags[0].Description().Summary)
}
},
},

"write-only attributes": {
module: map[string]string{
"main.tf": `
Expand Down
9 changes: 8 additions & 1 deletion internal/terraform/node_action_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ func (n *NodeActionDeclarationInstance) Execute(ctx EvalContext, _ walkOperation
configVal, _, configDiags = ctx.EvaluateBlock(n.Config.Config, n.Schema.ConfigSchema.DeepCopy(), nil, keyData)

diags = diags.Append(configDiags)
if diags.HasErrors() {
if configDiags.HasErrors() {
return diags
}

valDiags := validateResourceForbiddenEphemeralValues(ctx, configVal, n.Schema.ConfigSchema)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe we should rename the function to a more generic name since we call it for actions now as well

diags = diags.Append(valDiags.InConfigBody(n.Config.Config, n.Addr.String()))

if valDiags.HasErrors() {
return diags
}
}
Expand Down
3 changes: 3 additions & 0 deletions internal/terraform/node_action_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ func (n *NodeValidatableAction) Execute(ctx EvalContext, _ walkOperation) tfdiag
}
}

valDiags = validateResourceForbiddenEphemeralValues(ctx, configVal, schema.ConfigSchema)
diags = diags.Append(valDiags.InConfigBody(config, n.Addr.String()))

// Use unmarked value for validate request
unmarkedConfigVal, _ := configVal.UnmarkDeep()
log.Printf("[TRACE] Validating config for %q", n.Addr)
Expand Down