puppetlabs/bolt

Dynamically create targets with options

Closed this issue · 1 comments

Use Case

I want to target containers I create within a plan and differentiate my target's name and uri. Since apply blocks get trusted.certname from the target name, I don't want it to be my container's name. Currently, this is possible for statically defined targets in the inventory.yaml, but the get_target function only lets you generate new targets by uri.

Describe the Solution You Would Like

get_target should take a second, optional parameter, for specifying config options for the target.

plan example {
  run_command('podman run --name my-container-name ...')

  $container_target = get_target('my-trusted-app', uri => 'podman://my-container-name', config => {...})
  OR
  $container_target = get_target('podman://my-container-name', name => 'my-trusted-app', config => {...})

  apply($container_target) {
    notice($trusted['certname']) # my-trusted-app
  }
}

Describe Alternatives You've Considered

Targets could be pre-specified in the inventory, but then my plan loses its generic functionality.

Well, there's only a passing reference to it in https://www.puppet.com/docs/bolt/latest/bolt_types_reference#target, but this use case is already supported with Target.new like:

$target = Target.new(name => 'my-trusted-app', uri => 'podman://my-container-name')