actions: fix panic during query plan by not planning actions

We don't need to plan any actions during query plan mode.
Test stolen from DanielMSchmidt, thank you!
pull/37663/head
Kristin Laemmert 7 months ago committed by Daniel Schmidt
parent 152ce1df8f
commit f6ad8d3215

@ -4,6 +4,7 @@
package terraform
import (
"maps"
"path/filepath"
"slices"
"sort"
@ -144,7 +145,70 @@ action "test_action" "hello" {}
}
},
},
"query run": {
module: map[string]string{
"main.tf": `
action "test_action" "hello" {}
resource "test_object" "a" {
lifecycle {
action_trigger {
events = [before_create, after_update]
actions = [action.test_action.hello]
}
}
}
`,
"main.tfquery.hcl": `
list "test_resource" "test1" {
provider = "test"
config {
filter = {
attr = "foo"
}
}
}
`,
},
expectPlanActionCalled: false,
planOpts: &PlanOpts{
Mode: plans.NormalMode,
Query: true,
},
},
"query run, action references resource": {
module: map[string]string{
"main.tf": `
action "test_action" "hello" {
config {
attr = resource.test_object.a
}
}
resource "test_object" "a" {
lifecycle {
action_trigger {
events = [before_create, after_update]
actions = [action.test_action.hello]
}
}
}
`,
"main.tfquery.hcl": `
list "test_resource" "test1" {
provider = "test"
config {
filter = {
attr = "foo"
}
}
}
`,
},
expectPlanActionCalled: false,
planOpts: &PlanOpts{
Mode: plans.NormalMode,
Query: true,
},
},
"invalid config": {
module: map[string]string{
"main.tf": `
@ -3269,6 +3333,47 @@ resource "test_object" "a" {
},
},
},
ListResourceTypes: map[string]providers.Schema{
"test_resource": {
Body: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"data": {
Type: cty.DynamicPseudoType,
Computed: true,
},
},
BlockTypes: map[string]*configschema.NestedBlock{
"config": {
Block: configschema.Block{
Attributes: map[string]*configschema.Attribute{
"filter": {
Required: true,
NestedType: &configschema.Object{
Nesting: configschema.NestingSingle,
Attributes: map[string]*configschema.Attribute{
"attr": {
Type: cty.String,
Required: true,
},
},
},
},
},
},
Nesting: configschema.NestingSingle,
},
},
},
},
},
},
ListResourceFn: func(req providers.ListResourceRequest) providers.ListResourceResponse {
resp := []cty.Value{}
ret := req.Config.AsValueMap()
maps.Copy(ret, map[string]cty.Value{
"data": cty.TupleVal(resp),
})
return providers.ListResourceResponse{Result: cty.ObjectVal(ret)}
},
}

@ -174,9 +174,10 @@ func (b *PlanGraphBuilder) Steps() []GraphTransformer {
},
&ActionPlanTransformer{
Config: b.Config,
Operation: b.Operation,
Targets: b.ActionTargets,
Config: b.Config,
Operation: b.Operation,
Targets: b.ActionTargets,
queryPlanMode: b.queryPlan,
},
// Add dynamic values

@ -16,10 +16,12 @@ type ActionPlanTransformer struct {
Config *configs.Config
Targets []addrs.Targetable
Operation walkOperation
queryPlanMode bool
}
func (t *ActionPlanTransformer) Transform(g *Graph) error {
if t.Operation != walkPlan {
if t.Operation != walkPlan || t.queryPlanMode {
return nil
}

Loading…
Cancel
Save