forked from puppetlabs/bolt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(puppetlabsGH-1365) Add resolve_references plan function
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
Showing
3 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
bolt-modules/boltlib/lib/puppet/functions/resolve_references.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
9 changes: 9 additions & 0 deletions
9
bolt-modules/boltlib/spec/functions/resolve_references_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters