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

field name conflicts during lookups #294

Closed
ryane opened this issue Sep 22, 2016 · 3 comments
Closed

field name conflicts during lookups #294

ryane opened this issue Sep 22, 2016 · 3 comments
Labels
Milestone

Comments

@ryane
Copy link
Contributor

ryane commented Sep 22, 2016

Doing lookups across multiple resources that share a field name results in error like:

error calling lookup: multiple potential matches for Destination

Repro below:

samples/fieldNameCollision.hcl:

param "filename" {
  default = "hello.txt"
}

file.content "hello" {
  destination = "{{param `filename`}}"
  content = "hello"
}

file.mode "hello-mode" {
  destination = "{{param `filename`}}"
  mode = 0777
}

file.content "hello-log" {
  destination = "{{param `filename`}}.log"
  content = <<EOF
wrote         {{lookup `file.content.hello.destination`}}
with mode {{lookup `file.mode.hello-mode.mode`}}
  EOF
}
$ ./converge plan --local samples/fieldNameCollision.hcl
2016-09-22T08:45:22-04:00 |INFO| serving        addr=:47740 component=rpc
2016-09-22T08:45:22-04:00 |WARN| skipping module verification   component=client
root/file.content.hello-log got a non-unresolvable error: template: content:2:12: executing "content" at <lookup `file.mode.he...>: error calling lookup: multiple potential matches for Destination2016-09-22T08:45:22-04:00 |ERROR| could not render    component=rpc error=template: content:2:12: executing "content" at <lookup `file.mode.he...>: error calling lookup: multiple potential matches for Destination location=samples/fieldNameCollision.hcl runID=28149e45-08dc-4df3-9822-e2134523e527
2016-09-22T08:45:22-04:00 |FATAL| could not get responses       component=client error=error getting status response: rpc error: code = 2 desc = rendering samples/fieldNameCollision.hcl: template: content:2:12: executing "content" at <lookup `file.mode.he...>: error calling lookup: multiple potential matches for Destination file=samples/fieldNameCollision.hcl
@ryane ryane added the bug label Sep 22, 2016
@ryane
Copy link
Contributor Author

ryane commented Sep 22, 2016

Interestingly, I am not getting a collision when using file.directory even though it also shares a field named Destination. Maybe related to the different implementation of file.directory described in issue #292?

samples/fieldNameNoCollision.hcl:

param "filename" {
  default = "hello.txt"
}

file.directory "tmp-dir" {
  destination = "/tmp/hello"
  create_all = true
}

file.content "hello" {
  destination = "{{param `filename`}}"
  content = "hello"
}

file.mode "hello-mode" {
  destination = "{{param `filename`}}"
  mode = 0777
}

file.content "hello-log" {
  destination = "{{param `filename`}}.log"
  content = <<EOF
wrote     {{lookup `file.content.hello.destination`}}
in dir    {{lookup `file.directory.tmp-dir.destination`}}
  EOF
}
$ ./converge plan --local samples/fieldNameNoCollision.hcl
2016-09-22T09:01:04-04:00 |INFO| serving        addr=:47740 component=rpc
2016-09-22T09:01:04-04:00 |WARN| skipping module verification   component=client
2016-09-22T09:01:04-04:00 |INFO| got status     component=client file=samples/fieldNameNoCollision.hcl id=root/param.filename run=STARTED stage=PLAN
2016-09-22T09:01:04-04:00 |INFO| got status     component=client file=samples/fieldNameNoCollision.hcl id=root/file.directory.tmp-dir run=STARTED stage=PLAN
2016-09-22T09:01:04-04:00 |INFO| got status     component=client file=samples/fieldNameNoCollision.hcl id=root/file.content.hello run=STARTED stage=PLAN
2016-09-22T09:01:04-04:00 |INFO| got status     component=client file=samples/fieldNameNoCollision.hcl id=root/file.mode.hello-mode run=STARTED stage=PLAN
2016-09-22T09:01:04-04:00 |INFO| got status     component=client file=samples/fieldNameNoCollision.hcl id=root/file.content.hello-log run=STARTED stage=PLAN
2016-09-22T09:01:04-04:00 |INFO| got status     component=client file=samples/fieldNameNoCollision.hcl id=root run=STARTED stage=PLAN

root/file.directory.tmp-dir:
        Messages:
        Has Changes: yes
        Changes:
                /tmp/hello: "<absent>" => "<present>"

root/file.content.hello:
        Messages:
                hello.txt: File is missing
        Has Changes: yes
        Changes:
                hello.txt: "<file-missing>" => "hello"

root/file.mode.hello-mode:
        Messages:
                "hello.txt" does not exist
        Has Changes: yes
        Changes:
                hello.txt: "----------" => "-rwxrwxrwx"

root/file.content.hello-log:
        Messages:
                hello.txt.log: File is missing
        Has Changes: yes
        Changes:
                hello.txt.log:
                before:
                        <file-missing>
                after:
                        wrote     hello.txt
                        in dir    /tmp/hello


Summary: 0 errors, 4 changes

@rebeccaskinner
Copy link
Contributor

I'll look into it a bit this afternoon but I suspect that you're exactly right- because we can't pull the fields out of an interface there are no fields to actually collide.

@ryane
Copy link
Contributor Author

ryane commented Sep 22, 2016

fixed by #301

@ryane ryane closed this as completed Sep 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants