attach action config to config resource nodes

mildwonkey/action-in-resource
Kristin Laemmert 2 months ago
parent 06224cf6cd
commit ecf72704c5

@ -10,6 +10,8 @@ import (
"github.com/hashicorp/hcl/v2/hclsyntax"
"github.com/hashicorp/hcl/v2/hcltest"
"github.com/zclconf/go-cty/cty"
"github.com/hashicorp/terraform/internal/addrs"
)
func TestDecodeActionBlock(t *testing.T) {
@ -80,7 +82,9 @@ func TestDecodeActionTriggerBlock(t *testing.T) {
eventsListExpr := hcltest.MockExprList([]hcl.Expression{hcltest.MockExprTraversalSrc("after_create"), hcltest.MockExprTraversalSrc("after_update")})
fooActionExpr := hcltest.MockExprTraversalSrc("action.action_type.foo")
fooConfigAction := addrs.ConfigAction{Action: addrs.Action{Type: "action_type", Name: "foo"}}
barActionExpr := hcltest.MockExprTraversalSrc("action.action_type.bar")
barConfigAction := addrs.ConfigAction{Action: addrs.Action{Type: "action_type", Name: "bar"}}
fooAndBarExpr := hcltest.MockExprList([]hcl.Expression{fooActionExpr, barActionExpr})
// bad inputs!
@ -110,10 +114,12 @@ func TestDecodeActionTriggerBlock(t *testing.T) {
{
fooActionExpr,
fooActionExpr.Range(),
fooConfigAction,
},
{
barActionExpr,
barActionExpr.Range(),
barConfigAction,
},
},
},
@ -189,6 +195,7 @@ func TestDecodeActionTriggerBlock(t *testing.T) {
{
fooActionExpr,
fooActionExpr.Range(),
fooConfigAction,
},
},
},
@ -215,6 +222,7 @@ func TestDecodeActionTriggerBlock(t *testing.T) {
{
fooActionExpr,
fooActionExpr.Range(),
fooConfigAction,
},
},
},

@ -100,13 +100,12 @@ func TestContextPlan_actions(t *testing.T) {
}
for topic, tcs := range map[string]map[string]struct {
toBeImplemented bool
module map[string]string
buildState func(*states.SyncState)
planActionFn func(*testing.T, providers.PlanActionRequest) providers.PlanActionResponse
planResourceFn func(*testing.T, providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse
readResourceFn func(*testing.T, providers.ReadResourceRequest) providers.ReadResourceResponse
planOpts *PlanOpts
module map[string]string
buildState func(*states.SyncState)
planActionFn func(*testing.T, providers.PlanActionRequest) providers.PlanActionResponse
planResourceFn func(*testing.T, providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse
readResourceFn func(*testing.T, providers.ReadResourceRequest) providers.ReadResourceResponse
planOpts *PlanOpts
expectPlanActionCalled bool
@ -712,36 +711,7 @@ resource "test_object" "a" {
)
},
},
"splat is not supported": {
module: map[string]string{
"main.tf": `
action "test_action" "hello" {
count = 42
}
resource "test_object" "a" {
lifecycle {
action_trigger {
events = [before_create]
actions = [action.test_action.hello[*]]
}
}
}
`,
},
expectPlanActionCalled: false,
expectPlanDiagnostics: func(m *configs.Config) tfdiags.Diagnostics {
return tfdiags.Diagnostics{}.Append(&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Invalid action expression",
Detail: "Unexpected expression found in action_triggers.actions.",
Subject: &hcl.Range{
Filename: filepath.Join(m.Module.SourceDir, "main.tf"),
Start: hcl.Pos{Line: 9, Column: 18, Byte: 159},
End: hcl.Pos{Line: 9, Column: 47, Byte: 186},
},
})
},
},
"multiple events triggering in same action trigger": {
module: map[string]string{
"main.tf": `
@ -3905,10 +3875,6 @@ resource "test_object" "b" {
t.Run(topic, func(t *testing.T) {
for name, tc := range tcs {
t.Run(name, func(t *testing.T) {
if tc.toBeImplemented {
t.Skip("Test not implemented yet")
}
opts := SimplePlanOpts(plans.NormalMode, InputValues{})
if tc.planOpts != nil {
opts = tc.planOpts

Loading…
Cancel
Save