From b5f1738e177d925b960460ef32be269eda6fadba Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 9 Dec 2016 12:35:23 -0500 Subject: [PATCH 1/3] config: allow IDs to start with numbers --- config/config.go | 2 +- config/loader_test.go | 14 -------------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/config/config.go b/config/config.go index da39051c1..c7e4f351d 100644 --- a/config/config.go +++ b/config/config.go @@ -18,7 +18,7 @@ import ( // NameRegexp is the regular expression that all names (modules, providers, // resources, etc.) must follow. -var NameRegexp = regexp.MustCompile(`(?i)\A[A-Z_][A-Z0-9\-\_]*\z`) +var NameRegexp = regexp.MustCompile(`(?i)\A[A-Z0-9_][A-Z0-9\-\_]*\z`) // Config is the configuration that comes from loading a collection // of Terraform templates. diff --git a/config/loader_test.go b/config/loader_test.go index 7dae362cd..f7fad33c0 100644 --- a/config/loader_test.go +++ b/config/loader_test.go @@ -447,20 +447,6 @@ func TestLoadFile_variables(t *testing.T) { } } -func TestLoadFile_varInt(t *testing.T) { - _, err := LoadFile(filepath.Join(fixtureDir, "var_int.tf")) - if err == nil { - t.Fatal("should have error") - } -} - -func TestLoadFile_varIntBare(t *testing.T) { - _, err := LoadFile(filepath.Join(fixtureDir, "var_int_bare.tf")) - if err == nil { - t.Fatal("should have error") - } -} - func TestLoadDir_basic(t *testing.T) { dir := filepath.Join(fixtureDir, "dir-basic") c, err := LoadDir(dir) From cd1cd1cb7d76234df816d53f5a2fbfbce95107a6 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 9 Dec 2016 12:40:34 -0500 Subject: [PATCH 2/3] vendor: update HIL --- .../github.com/hashicorp/hil/parser/parser.go | 21 +------------------ .../hashicorp/hil/scanner/scanner.go | 19 +++++++++++++++++ vendor/vendor.json | 20 +++++++++--------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/vendor/github.com/hashicorp/hil/parser/parser.go b/vendor/github.com/hashicorp/hil/parser/parser.go index d7a461323..376f1c49d 100644 --- a/vendor/github.com/hashicorp/hil/parser/parser.go +++ b/vendor/github.com/hashicorp/hil/parser/parser.go @@ -2,7 +2,6 @@ package parser import ( "strconv" - "strings" "unicode/utf8" "github.com/hashicorp/hil/ast" @@ -483,26 +482,8 @@ func (p *parser) ParseScopeInteraction() (ast.Node, error) { }, nil } - varParts := []string{first.Content} - for p.peeker.Peek().Type == scanner.PERIOD { - p.peeker.Read() // eat period - - // Read the next item, since variable access in HIL is composed - // of many things. For example: "var.0.bar" is the entire var access. - partTok := p.peeker.Read() - switch partTok.Type { - case scanner.IDENTIFIER: - case scanner.STAR: - case scanner.INTEGER: - default: - return nil, ExpectationError("identifier", partTok) - } - - varParts = append(varParts, partTok.Content) - } - varName := strings.Join(varParts, ".") varNode := &ast.VariableAccess{ - Name: varName, + Name: first.Content, Posx: startPos, } diff --git a/vendor/github.com/hashicorp/hil/scanner/scanner.go b/vendor/github.com/hashicorp/hil/scanner/scanner.go index e448f13bf..bab86c67a 100644 --- a/vendor/github.com/hashicorp/hil/scanner/scanner.go +++ b/vendor/github.com/hashicorp/hil/scanner/scanner.go @@ -479,12 +479,31 @@ func scanIdentifier(s string) (string, int) { nextRune, size := utf8.DecodeRuneInString(s[byteLen:]) if !(nextRune == '_' || nextRune == '-' || + nextRune == '.' || + nextRune == '*' || unicode.IsNumber(nextRune) || unicode.IsLetter(nextRune) || unicode.IsMark(nextRune)) { break } + // If we reach a star, it must be between periods to be part + // of the same identifier. + if nextRune == '*' && s[byteLen-1] != '.' { + break + } + + // If our previous character was a star, then the current must + // be period. Otherwise, undo that and exit. + if byteLen > 0 && s[byteLen-1] == '*' && nextRune != '.' { + byteLen-- + if s[byteLen-1] == '.' { + byteLen-- + } + + break + } + byteLen = byteLen + size runeLen = runeLen + 1 } diff --git a/vendor/vendor.json b/vendor/vendor.json index 6dadc7a0a..a6277563f 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -1588,26 +1588,26 @@ { "checksumSHA1": "xONRNgLDc5OqCUmyDN3iBRKmKB0=", "path": "github.com/hashicorp/hil", - "revision": "bf046eec69cc383b7f32c47990336409601c8116", - "revisionTime": "2016-12-04T02:32:26Z" + "revision": "60db937199ba6f67251aa038cec18ce36a951312", + "revisionTime": "2016-12-09T17:20:46Z" }, { "checksumSHA1": "oZ2a2x9qyHqvqJdv/Du3LGeaFdA=", "path": "github.com/hashicorp/hil/ast", - "revision": "bf046eec69cc383b7f32c47990336409601c8116", - "revisionTime": "2016-12-04T02:32:26Z" + "revision": "60db937199ba6f67251aa038cec18ce36a951312", + "revisionTime": "2016-12-09T17:20:46Z" }, { - "checksumSHA1": "p/zZysJW/AaPXXPCI20nM2arPnw=", + "checksumSHA1": "P5PZ3k7SmqWmxgJ8Q0gLzeNpGhE=", "path": "github.com/hashicorp/hil/parser", - "revision": "bf046eec69cc383b7f32c47990336409601c8116", - "revisionTime": "2016-12-04T02:32:26Z" + "revision": "60db937199ba6f67251aa038cec18ce36a951312", + "revisionTime": "2016-12-09T17:20:46Z" }, { - "checksumSHA1": "FlzgVCYqnODad4pKujXhSaGcrIo=", + "checksumSHA1": "DC1k5kOua4oFqmo+JRt0YzfP44o=", "path": "github.com/hashicorp/hil/scanner", - "revision": "bf046eec69cc383b7f32c47990336409601c8116", - "revisionTime": "2016-12-04T02:32:26Z" + "revision": "60db937199ba6f67251aa038cec18ce36a951312", + "revisionTime": "2016-12-09T17:20:46Z" }, { "path": "github.com/hashicorp/logutils", From 148b8a12eae4f1054571ac18ecee0fc554703f7f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 9 Dec 2016 12:42:18 -0500 Subject: [PATCH 3/3] website: remove BC from upgrade guide --- .../source/upgrade-guides/0-8.html.markdown | 40 ------------------- 1 file changed, 40 deletions(-) diff --git a/website/source/upgrade-guides/0-8.html.markdown b/website/source/upgrade-guides/0-8.html.markdown index 3c16af6d5..c856718d9 100644 --- a/website/source/upgrade-guides/0-8.html.markdown +++ b/website/source/upgrade-guides/0-8.html.markdown @@ -57,46 +57,6 @@ EOF **Action:** Use heredocs or escape sequences when you have a string with newlines. -## Names Cannot Start with Integers or Hyphens - -Names of variables, resources, modules, etc. may no longer start with -numbers or hyphens. These will now fail at the validation step. - -This change was necessary to remove ambiguities from parsing the -interpolations. Most languages do not allow identifiers starting with -these characters with good reason. We now follow that as well. - -An example of a configuration that no longer works: - -``` -variable "1x1" {} -``` - -This must now be changed to start with a letter or underscore: - -``` -variable "foo-1x1" {} -variable "_1x1" {} -``` - -And so on... - -If you're changing resource names, this can cause Terraform to consider it -a new resource and plan to destroy it. To work around these scenarios, -please use the `terraform state mv` command: - -``` -terraform state mv aws_instance.1x1 aws_instance.foo-1x1 -``` - -The `terraform state mv` command creates a backup for each operation, -but to be safe you can still back up your state prior to doing these -changes. - -**Action:** Rename variable, resources, modules, providers, outputs that -start with a number or hyphen. If you rename a resource or module, use -`terraform state mv` to fix the state. - ## Math Order of Operations Math operations now follow standard mathematical order of operations.