Skip to content

Instantly share code, notes, and snippets.

@gregohardy
Created March 12, 2019 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregohardy/41fe10ea97a4f846d2385d994eb5f83d to your computer and use it in GitHub Desktop.
Save gregohardy/41fe10ea97a4f846d2385d994eb5f83d to your computer and use it in GitHub Desktop.
Deferred puppet function
require 'aws-sdk-ec2'
Puppet::Functions.create_function(:'amazon_aws::get_vpc') do
dispatch :up do
param 'String', :vpc_name
end
def up(vpc_name)
client = Aws::EC2::Client.new(region: 'us-west-2')
vpc_id = ""
client.describe_vpcs.each do |response|
response.vpcs.each do |vpc|
name = vpc.tags.find { |x| x.key == 'Name' } unless vpc.tags.nil?
vpc_id = vpc.vpc_id if !name.nil? and name.value == vpc_name
end
end
vpc_id
end
end
@gregohardy
Copy link
Author

/etc/puppetlabs/code/modules/amazon_aws/lib/puppet/functions/amazon_aws/get_vpc.rb

@gregohardy
Copy link
Author

$vpc_name = "ghdefvpc"
$vpc_get = Deferred("amazon_aws::get_vpc", [$vpc_name])

aws_vpc { $vpc_name:
ensure => present,
name => $vpc_name,
cidr_block => "10.182.0.0/16",
}

aws_security_group { 'ghdefsg':
name => 'ghdefsg',
group_name => 'ghdefsg',
description => 'big desc',
vpc_id => $vpc_get,
ensure => present
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment