Skip to content

Commit 1d3ecb1

Browse files
committed
actions: add test that validates ephemeral behaviour
1 parent 62540da commit 1d3ecb1

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

internal/terraform/context_apply_action_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,54 @@ resource "test_object" "resource" {
13081308
}},
13091309
},
13101310

1311+
"ephemeral values": {
1312+
module: map[string]string{
1313+
"main.tf": `
1314+
variable "attr" {
1315+
type = string
1316+
ephemeral = true
1317+
}
1318+
1319+
resource "test_object" "resource" {
1320+
name = "hello"
1321+
lifecycle {
1322+
action_trigger {
1323+
events = [before_create]
1324+
actions = [action.action_example.hello]
1325+
}
1326+
}
1327+
}
1328+
1329+
action "action_example" "hello" {
1330+
config {
1331+
attr = var.attr
1332+
}
1333+
}
1334+
`,
1335+
},
1336+
expectInvokeActionCalled: true,
1337+
expectInvokeActionCalls: []providers.InvokeActionRequest{
1338+
{
1339+
ActionType: "action_example",
1340+
PlannedActionData: cty.ObjectVal(map[string]cty.Value{
1341+
"attr": cty.StringVal("wo-apply"),
1342+
}),
1343+
},
1344+
},
1345+
planOpts: SimplePlanOpts(plans.NormalMode, InputValues{
1346+
"attr": {
1347+
Value: cty.StringVal("wo-plan"),
1348+
},
1349+
}),
1350+
applyOpts: &ApplyOpts{
1351+
SetVariables: InputValues{
1352+
"attr": {
1353+
Value: cty.StringVal("wo-apply"),
1354+
},
1355+
},
1356+
},
1357+
},
1358+
13111359
"write-only attributes": {
13121360
module: map[string]string{
13131361
"main.tf": `

internal/terraform/context_plan_actions_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,55 @@ resource "test_object" "a" {
13511351
},
13521352
},
13531353

1354+
"ephemeral values": {
1355+
module: map[string]string{
1356+
"main.tf": `
1357+
variable "secret" {
1358+
type = string
1359+
ephemeral = true
1360+
}
1361+
action "test_action" "hello" {
1362+
config {
1363+
attr = var.secret
1364+
}
1365+
}
1366+
resource "test_object" "a" {
1367+
lifecycle {
1368+
action_trigger {
1369+
events = [before_create]
1370+
actions = [action.test_action.hello]
1371+
}
1372+
}
1373+
}
1374+
`,
1375+
},
1376+
planOpts: &PlanOpts{
1377+
Mode: plans.NormalMode,
1378+
SetVariables: InputValues{
1379+
"secret": &InputValue{
1380+
Value: cty.StringVal("secret"),
1381+
SourceType: ValueFromCLIArg,
1382+
}},
1383+
},
1384+
expectPlanActionCalled: true,
1385+
1386+
assertPlan: func(t *testing.T, p *plans.Plan) {
1387+
if len(p.Changes.ActionInvocations) != 1 {
1388+
t.Fatalf("expected 1 action in plan, got %d", len(p.Changes.ActionInvocations))
1389+
}
1390+
1391+
action := p.Changes.ActionInvocations[0]
1392+
ac, err := action.Decode(&testActionSchema)
1393+
if err != nil {
1394+
t.Fatalf("expected action to decode successfully, but got error: %v", err)
1395+
}
1396+
1397+
if !ac.ConfigValue.GetAttr("attr").IsNull() {
1398+
t.Fatal("should have converted ephemeral value to null in the plan")
1399+
}
1400+
},
1401+
},
1402+
13541403
"write-only attributes": {
13551404
module: map[string]string{
13561405
"main.tf": `

0 commit comments

Comments
 (0)