terraform: rename mustReourceAddr to mustConfigResourceAddr and add mustAbsResourceAddr

there are too many things that can be called resource addrs and it can
be hard to find the must* I'm looking for, so I renamed one and added
another.
This commit is contained in:
Kristin Laemmert 2020-09-24 11:57:43 -04:00
parent f2f84003ee
commit 90655b98b0
6 changed files with 41 additions and 33 deletions

View File

@ -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,
},

View File

@ -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"]`),
)

View File

@ -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"]`),
)

View File

@ -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() {

View File

@ -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"]`),
)

View File

@ -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"]`),