From dc3ed6271c4111021b92ca9be39a9d6598d3c8a0 Mon Sep 17 00:00:00 2001 From: Katy Moe Date: Mon, 15 Nov 2021 10:42:08 +0000 Subject: [PATCH] add failing test for resource type mismatch --- internal/refactoring/move_validate_test.go | 18 ++++++++++++++++++ .../move-validate-zoo/move-validate-root.tf | 3 +++ 2 files changed, 21 insertions(+) diff --git a/internal/refactoring/move_validate_test.go b/internal/refactoring/move_validate_test.go index 986c1d5db..53bbbe6c2 100644 --- a/internal/refactoring/move_validate_test.go +++ b/internal/refactoring/move_validate_test.go @@ -386,6 +386,24 @@ Each resource can have moved from only one source resource.`, }, WantError: ``, // This is okay because the call itself is not considered to be inside the package it refers to }, + "resource type mismatch": { + Statements: []MoveStatement{ + makeTestMoveStmt(t, ``, + `test.nonexist1`, + `other.single`, + ), + }, + WantError: `Resource type mismatch: This statement declares a move from test.nonexist1 to other.single, which is a resource of a different type.`, + }, + "resource instance type mismatch": { + Statements: []MoveStatement{ + makeTestMoveStmt(t, ``, + `test.nonexist1[0]`, + `other.single`, + ), + }, + WantError: `Resource type mismatch: This statement declares a move from test.nonexist1[0] to other.single, which is a resource instance of a different type.`, + }, } for name, test := range tests { diff --git a/internal/refactoring/testdata/move-validate-zoo/move-validate-root.tf b/internal/refactoring/testdata/move-validate-zoo/move-validate-root.tf index 492d671db..3cc8504f9 100644 --- a/internal/refactoring/testdata/move-validate-zoo/move-validate-root.tf +++ b/internal/refactoring/testdata/move-validate-zoo/move-validate-root.tf @@ -41,6 +41,9 @@ resource "test" "for_each" { } } +resource "other" "single" { +} + module "fake_external" { # Our configuration fixture loader has a special case for a module call # named "fake_external" where it will mutate the source address after