Skip to content

Commit

Permalink
(puppetlabsGH-1365) Add resolve_references plan function
Browse files Browse the repository at this point in the history
This adds support for a `resolve_references` plan function that accepts
a hash of target data, resolves all references in the hash, and returns
the resolved target data.
  • Loading branch information
beechtom committed Nov 1, 2019
1 parent 224123d commit 2aa7a19
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
38 changes: 38 additions & 0 deletions bolt-modules/boltlib/lib/puppet/functions/resolve_references.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

require 'bolt/error'

# Evaulates all _plugin references in a hash and returns the resolved reference data.
Puppet::Functions.create_function(:resolve_references) do
# Resolve references.
# @param references A hash of reference data to resolve.
# @return A hash of resolved reference data.
# @example Resolve a hash of reference data
# $references = {
# "targets" => [
# "_plugin" => "terraform",
# "dir" => "path/to/terraform/project",
# "resource_type" => "aws_instance.web",
# "uri" => "public_ip"
# ]
# }
#
# resolve_references($references)
dispatch :resolve_references do
param 'Hash[String[1], Any]', :references
return_type 'Hash[String[1], Any]'
end

def resolve_references(references)
unless Puppet[:tasks]
raise Puppet::ParseErrorWithIssue
.from_issue_and_stack(Bolt::PAL::Issues::PLAN_OPERATION_NOT_SUPPORTED_WHEN_COMPILING, action: 'resolve_references')
end

references = references.merge('name' => 'all') unless references['name']
inventory = Puppet.lookup(:bolt_inventory)
group = Bolt::Inventory::Group2.new(references, inventory.plugins)

group.resolve_references(references)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'resolve_references' do
it 'resolves data' do
# TODO
end
end
1 change: 0 additions & 1 deletion lib/bolt/inventory/group2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def resolve_references(data)
reference?(value) ? resolve_references(resolve_single_reference(value)) : value
end
end
private :resolve_references

# Iteratively resolves "top-level" references until the result no longer
# has top-level references. A top-level reference is one which is not
Expand Down

0 comments on commit 2aa7a19

Please sign in to comment.