diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index 255cb91c8..4e0c2192e 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -290,7 +290,7 @@ func TestContext2Apply_resourceDependsOnModuleStateOnly(t *testing.T) { &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"parent"}`), - Dependencies: []addrs.ConfigResource{mustResourceAddr("module.child.aws_instance.child")}, + Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("module.child.aws_instance.child")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -1187,7 +1187,7 @@ func testContext2Apply_destroyDependsOn(t *testing.T) { &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"foo"}`), - Dependencies: []addrs.ConfigResource{mustResourceAddr("aws_instance.bar")}, + Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("aws_instance.bar")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -2517,7 +2517,7 @@ func TestContext2Apply_moduleDestroyOrder(t *testing.T) { &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"b"}`), - Dependencies: []addrs.ConfigResource{mustResourceAddr("module.child.aws_instance.a")}, + Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("module.child.aws_instance.a")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -7133,7 +7133,7 @@ func TestContext2Apply_taintDep(t *testing.T) { &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"bar","num": "2", "type": "aws_instance", "foo": "baz"}`), - Dependencies: []addrs.ConfigResource{mustResourceAddr("aws_instance.foo")}, + Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("aws_instance.foo")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -7185,7 +7185,7 @@ func TestContext2Apply_taintDepRequiresNew(t *testing.T) { &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"bar","num": "2", "type": "aws_instance", "foo": "baz"}`), - Dependencies: []addrs.ConfigResource{mustResourceAddr("aws_instance.foo")}, + Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("aws_instance.foo")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -7431,7 +7431,7 @@ func TestContext2Apply_targetedDestroyCountDeps(t *testing.T) { &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"i-abc123"}`), - Dependencies: []addrs.ConfigResource{mustResourceAddr("aws_instance.foo")}, + Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("aws_instance.foo")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -11355,7 +11355,7 @@ locals { &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"b", "require_new":"old.old"}`), - Dependencies: []addrs.ConfigResource{mustResourceAddr("test_instance.a")}, + Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("test_instance.a")}, CreateBeforeDestroy: true, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`), @@ -11366,8 +11366,8 @@ locals { Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"c", "require_new":"b"}`), Dependencies: []addrs.ConfigResource{ - mustResourceAddr("test_instance.a"), - mustResourceAddr("test_instance.b"), + mustConfigResourceAddr("test_instance.a"), + mustConfigResourceAddr("test_instance.b"), }, CreateBeforeDestroy: true, }, diff --git a/terraform/context_plan_test.go b/terraform/context_plan_test.go index 06f9a7baf..abf81b013 100644 --- a/terraform/context_plan_test.go +++ b/terraform/context_plan_test.go @@ -5221,7 +5221,7 @@ func TestContext2Plan_resourceNestedCount(t *testing.T) { &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"bar0"}`), - Dependencies: []addrs.ConfigResource{mustResourceAddr("aws_instance.foo")}, + Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("aws_instance.foo")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -5230,7 +5230,7 @@ func TestContext2Plan_resourceNestedCount(t *testing.T) { &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"bar1"}`), - Dependencies: []addrs.ConfigResource{mustResourceAddr("aws_instance.foo")}, + Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("aws_instance.foo")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -5239,7 +5239,7 @@ func TestContext2Plan_resourceNestedCount(t *testing.T) { &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"baz0"}`), - Dependencies: []addrs.ConfigResource{mustResourceAddr("aws_instance.bar")}, + Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("aws_instance.bar")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -5248,7 +5248,7 @@ func TestContext2Plan_resourceNestedCount(t *testing.T) { &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"baz1"}`), - Dependencies: []addrs.ConfigResource{mustResourceAddr("aws_instance.bar")}, + Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("aws_instance.bar")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -6236,7 +6236,7 @@ resource "test_instance" "b" { &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"b"}`), - Dependencies: []addrs.ConfigResource{mustResourceAddr("test_instance.a")}, + Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("test_instance.a")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`), ) diff --git a/terraform/graph_builder_apply_test.go b/terraform/graph_builder_apply_test.go index 357ca7f42..9f49ff743 100644 --- a/terraform/graph_builder_apply_test.go +++ b/terraform/graph_builder_apply_test.go @@ -104,7 +104,7 @@ func TestApplyGraphBuilder_depCbd(t *testing.T) { &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"B","test_list":["x"]}`), - Dependencies: []addrs.ConfigResource{mustResourceAddr("test_object.A")}, + Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("test_object.A")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`), ) @@ -272,7 +272,7 @@ func TestApplyGraphBuilder_destroyStateOnly(t *testing.T) { &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"bar"}`), - Dependencies: []addrs.ConfigResource{mustResourceAddr("module.child.test_object.A")}, + Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("module.child.test_object.A")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`), ) @@ -398,7 +398,7 @@ func TestApplyGraphBuilder_moduleDestroy(t *testing.T) { &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"foo","value":"foo"}`), - Dependencies: []addrs.ConfigResource{mustResourceAddr("module.A.test_object.foo")}, + Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("module.A.test_object.foo")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`), ) diff --git a/terraform/terraform_test.go b/terraform/terraform_test.go index 82cb757b4..c655d741b 100644 --- a/terraform/terraform_test.go +++ b/terraform/terraform_test.go @@ -250,7 +250,7 @@ func mustResourceInstanceAddr(s string) addrs.AbsResourceInstance { return addr } -func mustResourceAddr(s string) addrs.ConfigResource { +func mustConfigResourceAddr(s string) addrs.ConfigResource { addr, diags := addrs.ParseAbsResourceStr(s) if diags.HasErrors() { panic(diags.Err()) @@ -258,6 +258,14 @@ func mustResourceAddr(s string) addrs.ConfigResource { return addr.Config() } +func mustAbsResourceAddr(s string) addrs.AbsResource { + addr, diags := addrs.ParseAbsResourceStr(s) + if diags.HasErrors() { + panic(diags.Err()) + } + return addr +} + func mustProviderConfig(s string) addrs.AbsProviderConfig { p, diags := addrs.ParseAbsProviderConfigStr(s) if diags.HasErrors() { diff --git a/terraform/transform_destroy_cbd_test.go b/terraform/transform_destroy_cbd_test.go index 875e8ee93..4041f65bf 100644 --- a/terraform/transform_destroy_cbd_test.go +++ b/terraform/transform_destroy_cbd_test.go @@ -94,7 +94,7 @@ func TestCBDEdgeTransformer(t *testing.T) { &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"B","test_list":["x"]}`), - Dependencies: []addrs.ConfigResource{mustResourceAddr("test_object.A")}, + Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("test_object.A")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`), ) @@ -165,8 +165,8 @@ func TestCBDEdgeTransformerMulti(t *testing.T) { Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"C","test_list":["x"]}`), Dependencies: []addrs.ConfigResource{ - mustResourceAddr("test_object.A"), - mustResourceAddr("test_object.B"), + mustConfigResourceAddr("test_object.A"), + mustConfigResourceAddr("test_object.B"), }, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`), @@ -234,7 +234,7 @@ func TestCBDEdgeTransformer_depNonCBDCount(t *testing.T) { &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"B","test_list":["x"]}`), - Dependencies: []addrs.ConfigResource{mustResourceAddr("test_object.A")}, + Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("test_object.A")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`), ) @@ -243,7 +243,7 @@ func TestCBDEdgeTransformer_depNonCBDCount(t *testing.T) { &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"B","test_list":["x"]}`), - Dependencies: []addrs.ConfigResource{mustResourceAddr("test_object.A")}, + Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("test_object.A")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`), ) @@ -320,7 +320,7 @@ func TestCBDEdgeTransformer_depNonCBDCountBoth(t *testing.T) { &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"B","test_list":["x"]}`), - Dependencies: []addrs.ConfigResource{mustResourceAddr("test_object.A")}, + Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("test_object.A")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`), ) @@ -329,7 +329,7 @@ func TestCBDEdgeTransformer_depNonCBDCountBoth(t *testing.T) { &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"B","test_list":["x"]}`), - Dependencies: []addrs.ConfigResource{mustResourceAddr("test_object.A")}, + Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("test_object.A")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`), ) diff --git a/terraform/transform_destroy_edge_test.go b/terraform/transform_destroy_edge_test.go index 0fd1d6d33..107f26a43 100644 --- a/terraform/transform_destroy_edge_test.go +++ b/terraform/transform_destroy_edge_test.go @@ -29,7 +29,7 @@ func TestDestroyEdgeTransformer_basic(t *testing.T) { &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"B","test_string":"x"}`), - Dependencies: []addrs.ConfigResource{mustResourceAddr("test_object.A")}, + Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("test_object.A")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`), ) @@ -73,7 +73,7 @@ func TestDestroyEdgeTransformer_multi(t *testing.T) { &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"B","test_string":"x"}`), - Dependencies: []addrs.ConfigResource{mustResourceAddr("test_object.A")}, + Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("test_object.A")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`), ) @@ -83,8 +83,8 @@ func TestDestroyEdgeTransformer_multi(t *testing.T) { Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"C","test_string":"x"}`), Dependencies: []addrs.ConfigResource{ - mustResourceAddr("test_object.A"), - mustResourceAddr("test_object.B"), + mustConfigResourceAddr("test_object.A"), + mustConfigResourceAddr("test_object.B"), }, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`), @@ -139,7 +139,7 @@ func TestDestroyEdgeTransformer_module(t *testing.T) { &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"a"}`), - Dependencies: []addrs.ConfigResource{mustResourceAddr("module.child.test_object.b")}, + Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("module.child.test_object.b")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`), ) @@ -195,7 +195,7 @@ func TestDestroyEdgeTransformer_moduleOnly(t *testing.T) { Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"b","test_string":"x"}`), Dependencies: []addrs.ConfigResource{ - mustResourceAddr("module.child.test_object.a"), + mustConfigResourceAddr("module.child.test_object.a"), }, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`), @@ -206,8 +206,8 @@ func TestDestroyEdgeTransformer_moduleOnly(t *testing.T) { Status: states.ObjectReady, AttrsJSON: []byte(`{"id":"c","test_string":"x"}`), Dependencies: []addrs.ConfigResource{ - mustResourceAddr("module.child.test_object.a"), - mustResourceAddr("module.child.test_object.b"), + mustConfigResourceAddr("module.child.test_object.a"), + mustConfigResourceAddr("module.child.test_object.b"), }, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),