stacks: track resource deferrals in apply

TF-13968
Daniel Schmidt 2 years ago
parent 46a6d3f637
commit 1d45d12f40
No known key found for this signature in database
GPG Key ID: 377C3A4D62FBBBE2

@ -1109,6 +1109,58 @@ func TestApplyWithStateManipulation(t *testing.T) {
}),
expectedWarnings: []string{"Some objects will no longer be managed by Terraform"},
},
"deferred": {
store: stacks_testing_provider.NewResourceStoreBuilder().
AddResource("self", cty.ObjectVal(map[string]cty.Value{
"id": cty.StringVal("deferred"),
"value": cty.UnknownVal(cty.String),
})).
Build(),
changes: []stackstate.AppliedChange{
&stackstate.AppliedChangeComponentInstance{
ComponentAddr: mustAbsComponent("component.deferred"),
ComponentInstanceAddr: mustAbsComponentInstance("component.deferred"),
OutputValues: make(map[addrs.OutputValue]cty.Value),
},
&stackstate.AppliedChangeComponentInstance{
ComponentAddr: mustAbsComponent("component.ok"),
ComponentInstanceAddr: mustAbsComponentInstance("component.ok"),
OutputValues: make(map[addrs.OutputValue]cty.Value),
},
&stackstate.AppliedChangeResourceInstanceObject{
ResourceInstanceObjectAddr: mustAbsResourceInstanceObject("component.ok.testing_resource.self"),
NewStateSrc: &states.ResourceInstanceObjectSrc{
AttrsJSON: mustMarshalJSONAttrs(map[string]interface{}{
"id": "ok",
"value": "ok",
}),
Status: states.ObjectReady,
AttrSensitivePaths: nil,
Dependencies: []addrs.ConfigResource{},
},
ProviderConfigAddr: mustDefaultRootProvider("testing"),
PreviousResourceInstanceObjectAddr: nil,
Schema: stacks_testing_provider.TestingResourceSchema,
},
},
counts: collections.NewMap[stackaddrs.AbsComponentInstance, *hooks.ComponentInstanceChange](
collections.MapElem[stackaddrs.AbsComponentInstance, *hooks.ComponentInstanceChange]{
K: mustAbsComponentInstance("component.ok"),
V: &hooks.ComponentInstanceChange{
Addr: mustAbsComponentInstance("component.ok"),
Add: 1,
Defer: 0,
},
},
collections.MapElem[stackaddrs.AbsComponentInstance, *hooks.ComponentInstanceChange]{
K: mustAbsComponentInstance("component.deferred"),
V: &hooks.ComponentInstanceChange{
Addr: mustAbsComponentInstance("component.deferred"),
Defer: 1,
},
},
),
},
}
for name, tc := range tcs {

@ -948,6 +948,7 @@ func (c *ComponentInstance) ApplyModuleTreePlan(ctx context.Context, plan *plans
cic.Forget++
}
}
cic.Defer = plan.DeferredResourceInstanceChanges.Len()
hookMore(ctx, seq, h.ReportComponentInstanceApplied, cic)
}

@ -0,0 +1,24 @@
required_providers {
testing = {
source = "hashicorp/testing"
version = "0.1.0"
}
}
provider "testing" "default" {}
component "ok" {
source = "./ok"
providers = {
testing = provider.testing.default
}
}
component "deferred" {
source = "./deferred"
providers = {
testing = provider.testing.default
}
}

@ -0,0 +1,14 @@
terraform {
required_providers {
testing = {
source = "hashicorp/testing"
version = "0.1.0"
}
}
}
resource "testing_deferred_resource" "resource" {
id = "hello"
value = "world"
deferred = true
}

@ -0,0 +1,13 @@
terraform {
required_providers {
testing = {
source = "hashicorp/testing"
version = "0.1.0"
}
}
}
resource "testing_resource" "self" {
id = "ok"
value = "ok"
}
Loading…
Cancel
Save