puppetlabs / puppetlabs-terraform

Bolt Terraform plugin
Apache License 2.0
6 stars 18 forks source link

Resolve uri #18

Closed luckyraul closed 4 years ago

luckyraul commented 4 years ago

Describe the Bug

groups:
  - name: xxx_lb
    targets:
      - _plugin: terraform
        dir: ../xxx
        resource_type: aws_instance.lb
        target_mapping:
          uri: public_ip

When I run bolt inventory show --targets xxx-lb --debug --detail output: Command returned successfully {"target":"localhost","action":"task","object":"terraform::resolve_reference","status":"success","value":{"value":[{"uri":"xxx.xx.xx.xx"}]}}

Did not find config for xxx-lb in inventory

{
  "targets": [
    {
      "name": "xxx-lb",
      "uri": "xxx-lb",
      "alias": [

      ],

If I run plan

{"target":"xxx-lb","action":"task","object":null,"status":"failure","value":{"_error":{"kind":"puppetlabs.tasks/connect-error","msg":"Failed to connect to xxx-lb: getaddrinfo: nodename nor servname provided, or not known","details":{},"issue_code":"CONNECT_ERROR"}}}

Expected Behavior

A clear and concise description of what you expected to happen.

{
  "targets": [
    {
      "name": "xxx-lb",
      "uri": "xxx.xx.xx.xx",
      "alias": [

      ],
donoghuc commented 4 years ago

I would expect:

groups:
  - name: xxx_lb
    targets:
      - _plugin: terraform
        dir: ../xxx
        resource_type: aws_instance.lb
        target_mapping:
          uri: public_ip

To create a new target for each instance of aws_instance.lb.public_ip. If this is not currently working it seems like maybe there is an issue with resolving that data from the statefile. Can you try just running the resolve_reference task (see https://github.com/puppetlabs/puppetlabs-terraform/blob/master/tasks/resolve_reference.json for paramter details).? This might help you understand what is going on.

luckyraul commented 4 years ago

It is in my issue

{"target":"localhost","action":"task","object":"terraform::resolve_reference","status":"success","value":{"value":[{"uri":"xxx.xx.xx.xx"}]}}

This is a part of debug log, I've checked in the ruby code, the uri has a correct ip

donoghuc commented 4 years ago

Ah, i seee. OK your example is somewhat confusing.

With this command bolt inventory show --targets xxx-lb --debug --detail i think you have a typo, instead of looking for group xxx_lb its effectively creating a new target with name/uri xxx-lb. Can you confirm bolt inventory show --targets xxx_lb --debug --detail does not create new targets with name,uri found from statefile?

luckyraul commented 4 years ago

thanks, this was my issue. Works fine with xxx_lb