Created
March 12, 2019 19:59
-
-
Save gregohardy/41fe10ea97a4f846d2385d994eb5f83d to your computer and use it in GitHub Desktop.
Deferred puppet function
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
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 |
$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
/etc/puppetlabs/code/modules/amazon_aws/lib/puppet/functions/amazon_aws/get_vpc.rb