vagrant-aws-dns 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.ruby-version +2 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +21 -0
- data/README.md +64 -0
- data/Rakefile +2 -0
- data/lib/vagrant-aws-dns.rb +7 -0
- data/lib/vagrant-aws-dns/action/add_record.rb +19 -0
- data/lib/vagrant-aws-dns/action/base.rb +33 -0
- data/lib/vagrant-aws-dns/action/remove_record.rb +19 -0
- data/lib/vagrant-aws-dns/config.rb +31 -0
- data/lib/vagrant-aws-dns/plugin.rb +38 -0
- data/lib/vagrant-aws-dns/util/aws_util.rb +63 -0
- data/lib/vagrant-aws-dns/version.rb +5 -0
- data/vagrant-aws-dns.gemspec +26 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d803e83fcf98591c15b47bdd3be2dcea27de8328
|
4
|
+
data.tar.gz: 7f37e731eb9d21d5f9cacb2ae55c5cfaec4e124c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 30953b9b2964fd51cdbd0868a551d5b74f89b928c9bc1161fbb9b89d84811001e5373b040b5fa5fd4e492370a4dc74c12f09e1ba95a9f760f8ac5880961b6193
|
7
|
+
data.tar.gz: a614aca6162713bbb1b35ebb4706b557346a8add91ac17877c6973505dce8fffe399f697f82ec35f1bead03063f065d110cd01d7ec81eea08fb4144026b3b16c
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Nassim Kacha
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# vagrant-aws-dns
|
2
|
+
|
3
|
+
`vagrant-aws-dns` is a Vagrant plugin that allows you to set up route53 records.
|
4
|
+
|
5
|
+
## Behaviors
|
6
|
+
|
7
|
+
* Set route53 records on machine up.
|
8
|
+
* Remove associated route53 records on machine halt/destroy.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
$ vagrant plugin install vagrant-aws-dns
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
### Configuration example
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
Vagrant.configure("2") do |config|
|
20
|
+
config.vm.box = "dummy"
|
21
|
+
|
22
|
+
config.vm.provider :aws do |aws, override|
|
23
|
+
aws.access_key_id = "YOUR KEY"
|
24
|
+
aws.secret_access_key = "YOUR SECRET KEY"
|
25
|
+
aws.session_token = "SESSION TOKEN"
|
26
|
+
aws.keypair_name = "KEYPAIR NAME"
|
27
|
+
|
28
|
+
aws.ami = "ami-7747d01e"
|
29
|
+
|
30
|
+
override.ssh.username = "ubuntu"
|
31
|
+
override.ssh.private_key_path = "PATH TO YOUR PRIVATE KEY"
|
32
|
+
|
33
|
+
override.dns.hosted_zone_id = 'HOSTED ZONE ID'
|
34
|
+
override.dns.record_sets = [['subdomain1.domain.com', 'A', '4.3.2.1'], ['subdomain1.domain.com', 'A']]
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
### record_sets
|
39
|
+
|
40
|
+
`record_sets` is an array of record set that are also represented as arrays. Below are some examples:
|
41
|
+
|
42
|
+
* `['subdomain.domain.com', 'A']` - This will set a record of type `subdomain.domain.com. A <public_ip>`, the <public_ip> is auto detected.
|
43
|
+
* `['subdomain.domain.com', 'A', '4.3.2.1']` - This will set a record of type `subdomain.domain.com. A 4.3.2.1`.
|
44
|
+
* `['subdomain1.domain.com', 'CNAME', 'domain2.com']` - This will set a record of type `subdomain1.domain.com. CNAME domain2.com.`.
|
45
|
+
|
46
|
+
## FAQ
|
47
|
+
|
48
|
+
* Why this plugin is not named `vagrant-aws-route53` ?
|
49
|
+
> Unfortunately, that name was already taken by another plugin of the same kind.
|
50
|
+
* So why develop a new one?
|
51
|
+
> There are several reasons for this: use of new AWS SDK, support of multiple records, support of deleting records on machine halt
|
52
|
+
or destory.
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nasskach/vagrant-aws-dns.
|
57
|
+
|
58
|
+
## License
|
59
|
+
|
60
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
61
|
+
|
62
|
+
## Acknowledgments
|
63
|
+
|
64
|
+
I want to thank my employer `atHome Group S.A - REA Group` for giving me the opportunity to share this work with the open source community.
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module AwsDns
|
6
|
+
module Action
|
7
|
+
class AddRecord < Base
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
super env do |record, type, value|
|
11
|
+
@aws.add_record(@machine.config.dns.hosted_zone_id, record, type, value)
|
12
|
+
@machine.ui.info("Add dns record #{record} pointing to #{value}.")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
require_relative '../util/aws_util'
|
3
|
+
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module AwsDns
|
7
|
+
module Action
|
8
|
+
class Base
|
9
|
+
|
10
|
+
def initialize(app, env)
|
11
|
+
@app = app
|
12
|
+
@machine = env[:machine]
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
return @app.call(env) if @machine.config.dns.hosted_zone_id.nil? && @machine.config.dns.record_sets.nil?
|
17
|
+
|
18
|
+
@aws = AwsDns::Util::AwsUtil.new(@machine.provider_config.access_key_id,
|
19
|
+
@machine.provider_config.secret_access_key)
|
20
|
+
public_ip = @aws.get_public_ip(@machine.id)
|
21
|
+
|
22
|
+
@machine.config.dns.record_sets.each do |record_set|
|
23
|
+
record, type, value = record_set
|
24
|
+
yield record, type, value || public_ip if block_given?
|
25
|
+
end
|
26
|
+
|
27
|
+
@app.call(env)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module AwsDns
|
6
|
+
module Action
|
7
|
+
class RemoveRecord < Base
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
super env do |record, type, value|
|
11
|
+
@aws.remove_record(@machine.config.dns.hosted_zone_id, record, type, value)
|
12
|
+
@machine.ui.info("Removing dns record #{record}.")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module AwsDns
|
6
|
+
class Config < Vagrant.plugin('2', :config)
|
7
|
+
attr_accessor :hosted_zone_id
|
8
|
+
attr_accessor :record_sets
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@hosted_zone_id = UNSET_VALUE
|
12
|
+
@record_sets = UNSET_VALUE
|
13
|
+
end
|
14
|
+
|
15
|
+
def finalize!
|
16
|
+
@hosted_zone_id = nil if @hosted_zone_id == UNSET_VALUE
|
17
|
+
@record_sets = nil if @record_sets == UNSET_VALUE
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate(machine)
|
21
|
+
finalize!
|
22
|
+
|
23
|
+
errors = _detected_errors
|
24
|
+
errors << 'hosted_zone_id is required' if @hosted_zone_id.nil? && !@record_sets.nil?
|
25
|
+
errors << 'record_sets is required' if @record_sets.nil? && !hosted_zone_id.nil?
|
26
|
+
|
27
|
+
{ 'AwsDns' => errors }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module AwsDns
|
6
|
+
class Plugin < Vagrant.plugin('2')
|
7
|
+
name 'aws-dns'
|
8
|
+
|
9
|
+
description <<-DESC
|
10
|
+
A Vagrant plugin that allows you to setup route53 records.
|
11
|
+
DESC
|
12
|
+
|
13
|
+
config :dns do
|
14
|
+
require_relative 'config'
|
15
|
+
Config
|
16
|
+
end
|
17
|
+
|
18
|
+
action_hook :add_record, :machine_action_up do |hook|
|
19
|
+
require_relative 'action/add_record'
|
20
|
+
hook.after VagrantPlugins::AWS::Action::RunInstance, VagrantPlugins::AwsDns::Action::AddRecord
|
21
|
+
hook.after VagrantPlugins::AWS::Action::StartInstance, VagrantPlugins::AwsDns::Action::AddRecord
|
22
|
+
end
|
23
|
+
|
24
|
+
action_hook :remove_record, :machine_action_halt do |hook|
|
25
|
+
require_relative 'action/remove_record'
|
26
|
+
hook.after VagrantPlugins::AWS::Action::StopInstance, VagrantPlugins::AwsDns::Action::RemoveRecord
|
27
|
+
hook.after VagrantPlugins::AWS::Action::TerminateInstance, VagrantPlugins::AwsDns::Action::RemoveRecord
|
28
|
+
end
|
29
|
+
|
30
|
+
action_hook :remove_record, :machine_action_destroy do |hook|
|
31
|
+
require_relative 'action/remove_record'
|
32
|
+
hook.before VagrantPlugins::AWS::Action::StopInstance, VagrantPlugins::AwsDns::Action::RemoveRecord
|
33
|
+
hook.before VagrantPlugins::AWS::Action::TerminateInstance, VagrantPlugins::AwsDns::Action::RemoveRecord
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module AwsDns
|
6
|
+
module Util
|
7
|
+
class AwsUtil
|
8
|
+
|
9
|
+
attr_reader :ec2, :route53
|
10
|
+
|
11
|
+
def initialize(accesskey, secretkey)
|
12
|
+
credentials = Aws::Credentials.new(accesskey, secretkey)
|
13
|
+
@ec2 = Aws::EC2::Client.new(
|
14
|
+
region: 'eu-west-1',
|
15
|
+
credentials: credentials
|
16
|
+
)
|
17
|
+
@route53 = Aws::Route53::Client.new(
|
18
|
+
region: 'eu-west-1',
|
19
|
+
credentials: credentials
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_public_ip(instance_id)
|
24
|
+
@ec2.describe_instances({instance_ids: [instance_id]}).reservations[0].instances[0].public_ip_address
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_record(hosted_zone_id, record, type, value)
|
28
|
+
change_record(hosted_zone_id, record, type, value, 'UPSERT')
|
29
|
+
end
|
30
|
+
|
31
|
+
def remove_record(hosted_zone_id, record, type, value)
|
32
|
+
change_record(hosted_zone_id, record, type, value, 'DELETE')
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def change_record(hosted_zone_id, record, type, value, action='CREATE')
|
38
|
+
@route53.change_resource_record_sets({
|
39
|
+
hosted_zone_id: hosted_zone_id, # required
|
40
|
+
change_batch: {
|
41
|
+
changes: [
|
42
|
+
{
|
43
|
+
action: action, # required, accepts CREATE, DELETE, UPSERT
|
44
|
+
resource_record_set: {
|
45
|
+
name: record, # required
|
46
|
+
type: type, # required, accepts SOA, A, TXT, NS, CNAME, MX, PTR, SRV, SPF, AAAA
|
47
|
+
ttl: 1,
|
48
|
+
resource_records: [
|
49
|
+
{
|
50
|
+
value: value # required
|
51
|
+
}
|
52
|
+
]
|
53
|
+
}
|
54
|
+
}
|
55
|
+
]
|
56
|
+
}
|
57
|
+
})
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vagrant-aws-dns/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "vagrant-aws-dns"
|
8
|
+
spec.version = Vagrant::AwsDns::VERSION
|
9
|
+
spec.authors = ["Nassim Kacha"]
|
10
|
+
spec.email = ["nassim.kacha@rea-group.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A Vagrant plugin that allows you to set up route53 records.}
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "https://github.com/nasskach/vagrant-aws-dns"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency 'aws-sdk', '~> 2.2.8'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-aws-dns
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nassim Kacha
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.2.8
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.2.8
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: A Vagrant plugin that allows you to set up route53 records.
|
56
|
+
email:
|
57
|
+
- nassim.kacha@rea-group.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".ruby-version"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/vagrant-aws-dns.rb
|
69
|
+
- lib/vagrant-aws-dns/action/add_record.rb
|
70
|
+
- lib/vagrant-aws-dns/action/base.rb
|
71
|
+
- lib/vagrant-aws-dns/action/remove_record.rb
|
72
|
+
- lib/vagrant-aws-dns/config.rb
|
73
|
+
- lib/vagrant-aws-dns/plugin.rb
|
74
|
+
- lib/vagrant-aws-dns/util/aws_util.rb
|
75
|
+
- lib/vagrant-aws-dns/version.rb
|
76
|
+
- vagrant-aws-dns.gemspec
|
77
|
+
homepage: https://github.com/nasskach/vagrant-aws-dns
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.5.1
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: A Vagrant plugin that allows you to set up route53 records.
|
101
|
+
test_files: []
|