terraform test: run block names should be valid HCL identifiers (#34469)

* terraform test: run block names should be valid HCL identifiers

* fix test
pull/34569/head
Liam Cervante 2 years ago committed by GitHub
parent 6114ec4390
commit 3a75362cce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8,6 +8,7 @@ import (
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/hashicorp/hcl/v2/hclsyntax"
"github.com/hashicorp/terraform/internal/addrs"
"github.com/hashicorp/terraform/internal/getmodules"
@ -437,6 +438,16 @@ func decodeTestRunBlock(block *hcl.Block) (*TestRun, hcl.Diagnostics) {
NameDeclRange: block.LabelRanges[0],
DeclRange: block.DefRange,
}
if !hclsyntax.ValidIdentifier(r.Name) {
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Invalid run block name",
Detail: badIdentifierDetail,
Subject: r.NameDeclRange.Ptr(),
})
}
for _, block := range content.Blocks {
switch block.Type {
case "assert":

@ -11,7 +11,7 @@ provider "bar" {
run "default_should_be_fine" {}
run "bit_complicated_still_okay "{
run "bit_complicated_still_okay" {
providers = {
foo = foo

@ -0,0 +1,8 @@
resource "aws_instance" "web" {
ami = "ami-1234"
security_groups = [
"foo",
"bar",
]
}
Loading…
Cancel
Save