From d7596e9202f4b20215b0ee5a30a903177d7d9e51 Mon Sep 17 00:00:00 2001 From: Anna Tikhonova Date: Wed, 5 Feb 2020 12:18:54 +0300 Subject: [PATCH] Fix resource parser for Terraform 0.12 for_each syntax (#133) --- resource.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resource.go b/resource.go index 2908fee..b29b5e2 100644 --- a/resource.go +++ b/resource.go @@ -42,7 +42,7 @@ func init() { // - type.[module_]name (no `count` attribute; contains module name if we're not in the root module) // - type.[module_]name.0 (if resource has `count` attribute) // - "data." prefix should not parse and be ignored by caller (does not represent a host) - nameParser = regexp.MustCompile(`^([\w\-]+)\.([\w\-]+)(?:\.(\d+))?$`) + nameParser = regexp.MustCompile(`^([\w\-]+)\.([\w\-]+)(?:\.(\d+|[\S+]+))?$`) } type Resource struct { @@ -77,7 +77,7 @@ func NewResource(keyName string, state resourceState) (*Resource, error) { // isn't the case. c, err = strconv.Atoi(m[3]) if err != nil { - return nil, err + m[2] = fmt.Sprintf("%s.%s", m[2], m[3]) } }