puppetlabs-aws
puppetlabs-aws copied to clipboard
WIP: Route53 utility functions
This PR adds two utility functions
- ec2_return_private_ip_addresses(region, [instance_name_regex], [subnet_id])
- ec2_return_private_cnames(region, [instance_name_regex], [subnet_id])
The functions return an array matching the critera containing either ip addresses or cnames depending on the function called.
For example if you have the below instances:
| Instance Name | Region | Private IP Address | CName |
|---|---|---|---|
| web-1 | ap-southeast-2 | 172.31.18.103 | ip-172-31-18-103.ap-southeast-2.compute.internal |
| web-2 | ap-southeast-2 | 172.31.18.104 | ip-172-31-18-104.ap-southeast-2.compute.internal |
| web-3 | ap-southeast-2 | 172.31.18.105 | ip-172-31-18-105.ap-southeast-2.compute.internal |
| web-4 | ap-southeast-2 | 172.31.18.106 | ip-172-31-18-106.ap-southeast-2.compute.internal |
| db-1 | ap-southeast-2 | 172.31.18.107 | ip-172-31-18-107.ap-southeast-2.compute.internal |
| db-2 | ap-southeast-2 | 172.31.18.108 | ip-172-31-18-108.ap-southeast-2.compute.internal |
13:36 - root@atom: infrastructure/aws-testing
$ puppet apply --modulepath ~/dev/puppet-modules-development -e '$val = ec2_return_private_ip_addresses("ap-southeast-2", "web*", "") notice($val)'
Notice: Scope(Class[main]): 172.31.18.103 172.31.18.104 172.31.18.105 172.31.18.106
Notice: Compiled catalog for atom.local in environment production in 0.43 seconds
Notice: Finished catalog run in 0.03 seconds
I would envisage it working like:
route53_zone { 'sample.internal.':
ensure => 'present',
}
route53_a_record { 'puppetmaster.sample.internal.':
ensure => 'present',
ttl => '3000',
values => ec2_return_private_ip_addresses("ap-southeast-2", "puppetmaster*", ""),
zone => 'sample.internal.',
}
route53_a_record { 'db.sample.internal.':
ensure => 'present',
ttl => '3000',
values => ec2_return_private_ip_addresses("ap-southeast-2", "db*", ""),
zone => 'sample.internal.',
}
route53_a_record { 'www.sample.internal.':
ensure => 'present',
ttl => '3000',
values => ec2_return_private_ip_addresses("ap-southeast-2", "web*", ""),
zone => 'sample.internal.',
}
Work still to be done:
- move duplicate code into a function in a module
- write tests and documentation
Thoughts?
My initial impulse is that these records should be created either on the nodes themselves, as exported resources created on the node for which the record is needed and realized on an instance with permissions to update route 53, or using puppetdbquery to select the appropriate facts about those instances from puppetdb.
Would that meet your needs?
Hmm, I may not be the best representative for your suggested proposal. At the moment I am just playing with the module to see how I could potentially use it, ie by using puppet apply (I dont have a puppetmaster or puppetdb setup).
Also I could see certain instances where I would use puppet to spin up or down instances without having the puppet agent installed on the new instance.
Thoughts?
@pjfoley, do you have any plans to pick this up again? Thanks!