Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support moved block syntax from Terraform 1.1 #225

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion linter/terraform_v12.go
Expand Up @@ -35,13 +35,14 @@ var (
"resource",
"terraform",
"variable",
"moved",
}

blockLabelSyntax = map[string][]string{
"TypeAndName": []string{"data", "resource"},
"TypeOnly": []string{"provider"},
"NameOnly": []string{"module", "output", "variable"},
"NoTypeNoName": []string{"locals", "terraform"},
"NoTypeNoName": []string{"locals", "terraform", "moved"},
}
)

Expand Down
7 changes: 7 additions & 0 deletions linter/terraform_v12_test.go
Expand Up @@ -524,3 +524,10 @@ func TestTerraform12FileFunctionReferenceFileAbsoultePath(t *testing.T) {
os.RemoveAll(tempResourceDir)
os.RemoveAll(tempReferenceDir)
}

func TestSyntaxMoved(t *testing.T) {
// Allow parsing Terraform 1.1 syntax with `moved` block
// with a v0.12 parser
loadResources12ToTest(t, "./testdata/resources/moved.tf")
}

4 changes: 4 additions & 0 deletions linter/testdata/resources/moved.tf
@@ -0,0 +1,4 @@
moved {
from = "from"
to = "to"
}
9 changes: 9 additions & 0 deletions linter/tf12parser/parser_test.go
Expand Up @@ -61,6 +61,11 @@ resource "aws_instance" "first" {
environment = lookup(var.default_tags,"environment","dev")
}
}

moved {
from = "x"
to = "y"
}
`)

blocks, err := parser.ParseDirectory(filepath.Dir(path))
Expand Down Expand Up @@ -122,6 +127,10 @@ resource "aws_instance" "first" {
assert.Equal(t, "the-cats-mother", dataBlocks[0].Labels()[1])

assert.Equal(t, "boots", dataBlocks[0].GetAttribute("name").Value().AsString())

// moved
movedBlocks := blocks.OfType("moved")
require.Len(t, movedBlocks, 1)
}

func Test_Modules(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions linter/tf12parser/schema.go
Expand Up @@ -19,6 +19,9 @@ var terraformSchema = &hcl.BodySchema{
{
Type: "locals",
},
{
Type: "moved",
},
{
Type: "output",
LabelNames: []string{"name"},
Expand Down