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

Handle resources that have object/hash-like keys due to use of for_each #159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ func init() {
// Formats:
// - 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)
// - type.[module_]name["key"] (if resource has `key` attribute)
// - type.[module_]name.resource_name
// - "data." prefix should not parse and be ignored by caller (does not represent a host)
nameParser = regexp.MustCompile(`^([\w\-]+)\.([\w\-]+)(?:\.(\d+|[\S+]+))?$`)
nameParser = regexp.MustCompile(`^([\w_-]+)\.((?:[\w_-]+(\["[^"]+"\])?))(?:\.?(\d+|[\S+]+))?$`)
}

type Resource struct {
Expand Down Expand Up @@ -76,7 +77,7 @@ func NewResource(keyName string, state resourceState) (*Resource, error) {
m := nameParser.FindStringSubmatch(keyName)

// This should not happen unless our regex changes.
if len(m) != 4 {
if len(m) != 4 && len(m) != 5 {
return nil, fmt.Errorf("couldn't parse resource keyName: %s", keyName)
}

Expand Down