mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-12 09:01:58 -06:00
Merge pull request #22811 from notchairmk/b-apply-node-removed-targeted
bug: fix terraform trying to clean up orphan modules on target
This commit is contained in:
commit
43c66c2048
@ -8847,6 +8847,52 @@ module.child:
|
||||
`)
|
||||
}
|
||||
|
||||
func TestContext2Apply_targetedResourceOrphanModule(t *testing.T) {
|
||||
m := testModule(t, "apply-targeted-resource-orphan-module")
|
||||
p := testProvider("aws")
|
||||
p.ApplyFn = testApplyFn
|
||||
p.DiffFn = testDiffFn
|
||||
|
||||
// Create a state with an orphan module
|
||||
state := MustShimLegacyState(&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: []string{"root", "child"},
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.bar": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Primary: &InstanceState{},
|
||||
Provider: "provider.aws",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
ProviderResolver: providers.ResolverFixed(
|
||||
map[string]providers.Factory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
),
|
||||
State: state,
|
||||
Targets: []addrs.Targetable{
|
||||
addrs.RootModuleInstance.Resource(
|
||||
addrs.ManagedResourceMode, "aws_instance", "foo",
|
||||
),
|
||||
},
|
||||
})
|
||||
|
||||
if _, diags := ctx.Plan(); diags.HasErrors() {
|
||||
t.Fatalf("plan errors: %s", diags.Err())
|
||||
}
|
||||
|
||||
if _, diags := ctx.Apply(); diags.HasErrors() {
|
||||
t.Fatalf("apply errors: %s", diags.Err())
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Apply_unknownAttribute(t *testing.T) {
|
||||
m := testModule(t, "apply-unknown")
|
||||
p := testProvider("aws")
|
||||
|
@ -14,6 +14,7 @@ type NodeModuleRemoved struct {
|
||||
|
||||
var (
|
||||
_ GraphNodeSubPath = (*NodeModuleRemoved)(nil)
|
||||
_ RemovableIfNotTargeted = (*NodeModuleRemoved)(nil)
|
||||
_ GraphNodeEvalable = (*NodeModuleRemoved)(nil)
|
||||
_ GraphNodeReferencer = (*NodeModuleRemoved)(nil)
|
||||
_ GraphNodeReferenceOutside = (*NodeModuleRemoved)(nil)
|
||||
@ -63,6 +64,13 @@ func (n *NodeModuleRemoved) References() []*addrs.Reference {
|
||||
}
|
||||
}
|
||||
|
||||
// RemovableIfNotTargeted
|
||||
func (n *NodeModuleRemoved) RemoveIfNotTargeted() bool {
|
||||
// We need to add this so that this node will be removed if
|
||||
// it isn't targeted or a dependency of a target.
|
||||
return true
|
||||
}
|
||||
|
||||
// EvalCheckModuleRemoved is an EvalNode implementation that verifies that
|
||||
// a module has been removed from the state as expected.
|
||||
type EvalCheckModuleRemoved struct {
|
||||
|
1
terraform/testdata/apply-targeted-resource-orphan-module/child/main.tf
vendored
Normal file
1
terraform/testdata/apply-targeted-resource-orphan-module/child/main.tf
vendored
Normal file
@ -0,0 +1 @@
|
||||
resource "aws_instance" "bar" {}
|
5
terraform/testdata/apply-targeted-resource-orphan-module/main.tf
vendored
Normal file
5
terraform/testdata/apply-targeted-resource-orphan-module/main.tf
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
//module "child" {
|
||||
// source = "./child"
|
||||
//}
|
||||
|
||||
resource "aws_instance" "foo" {}
|
Loading…
Reference in New Issue
Block a user