dd2tf 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/exe/dd2tf +42 -9
- data/lib/dd2tf.rb +9 -2
- data/lib/dd2tf/import/base.rb +33 -0
- data/lib/dd2tf/import/downtime.rb +21 -0
- data/lib/dd2tf/import/monitor.rb +22 -0
- data/lib/dd2tf/import/timeboard.rb +22 -0
- data/lib/dd2tf/import/user.rb +23 -0
- data/lib/dd2tf/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c037ac78d253678306c6024b8392a6a367effb18
|
4
|
+
data.tar.gz: 2568060ea2c6110d5ca454d1885a53424bd891bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65df4757d1d84981fa4ef22fcc107ac9d4e4c2f2a81d6e8c706bb83146c0d4de02d7efb756d35dded379d2e9e7eda1e420dd7707ef471f315bfdb0da0e6011a2
|
7
|
+
data.tar.gz: 3d9914aa01411f71adb40e61964e46459801765277941f0df54e4655ac3963e7e3f11b3654321ed51a0bec70de8f15e41ca3a4098b8fbe7a55bc22e39315fbbd
|
data/exe/dd2tf
CHANGED
@@ -5,11 +5,52 @@ require 'thor'
|
|
5
5
|
require 'dogapi'
|
6
6
|
|
7
7
|
module Dd2tf
|
8
|
+
module Util
|
9
|
+
def initialize(*args, &block)
|
10
|
+
super
|
11
|
+
client
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def client
|
17
|
+
return @client unless @client.nil?
|
18
|
+
config = Config.new(options[:dd_api_key], options[:dd_app_key])
|
19
|
+
@client ||= ::Dogapi::Client.new(config.api_key, config.app_key)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Print < Thor
|
24
|
+
include Util
|
25
|
+
|
26
|
+
desc "user", "ipmort user resource to tfstate"
|
27
|
+
def user
|
28
|
+
puts ::Dd2tf::Import::User.new(client).print
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "downtime", "ipmort downtime resource to tfstate"
|
32
|
+
def downtime
|
33
|
+
puts ::Dd2tf::Import::Downtime.new(client).print
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "monitor", "ipmort monitor resource to tfstate"
|
37
|
+
def monitor
|
38
|
+
puts ::Dd2tf::Import::Monitor.new(client).print
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "timeboard", "ipmort timeboard resource to tfstate"
|
42
|
+
def timeboard
|
43
|
+
puts ::Dd2tf::Import::Timeboard.new(client).print
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
8
47
|
class Cli < Thor
|
9
|
-
include
|
48
|
+
include Util
|
10
49
|
|
11
50
|
class_option :dd_api_key, type: :string
|
12
51
|
class_option :dd_app_key, type: :string
|
52
|
+
desc "print [resource]", "Print import resource command from remote to tfstate."
|
53
|
+
subcommand 'print', Print
|
13
54
|
|
14
55
|
desc "puts monitor configuration as terraform config", "puts monitor config"
|
15
56
|
def monitor
|
@@ -25,14 +66,6 @@ module Dd2tf
|
|
25
66
|
def user
|
26
67
|
puts User.new(client).output
|
27
68
|
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def client
|
32
|
-
return @client unless @client.nil?
|
33
|
-
config = Config.new(options[:dd_api_key], options[:dd_app_key])
|
34
|
-
@client ||= ::Dogapi::Client.new(config.api_key, config.app_key)
|
35
|
-
end
|
36
69
|
end
|
37
70
|
end
|
38
71
|
|
data/lib/dd2tf.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
require "dd2tf/version"
|
2
|
+
require "dd2tf/config"
|
3
|
+
|
2
4
|
require "dd2tf/base"
|
5
|
+
require "dd2tf/user"
|
3
6
|
require "dd2tf/monitor"
|
4
7
|
require "dd2tf/timeboard"
|
5
|
-
|
6
|
-
require "dd2tf/
|
8
|
+
|
9
|
+
require "dd2tf/import/base"
|
10
|
+
require "dd2tf/import/user"
|
11
|
+
require "dd2tf/import/monitor"
|
12
|
+
require "dd2tf/import/timeboard"
|
13
|
+
require "dd2tf/import/downtime"
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/core_ext'
|
3
|
+
|
4
|
+
module Dd2tf
|
5
|
+
module Import
|
6
|
+
class Base
|
7
|
+
attr_reader :resources
|
8
|
+
class NotImplementedError < StandardError; end
|
9
|
+
UNALLOWED_RESOURCE_TITLE_REGEXP = /\(|\)|'|\.|\[|\]|:/
|
10
|
+
|
11
|
+
def initialize(client)
|
12
|
+
@client = client
|
13
|
+
end
|
14
|
+
|
15
|
+
def print
|
16
|
+
resources.each do |resource|
|
17
|
+
puts "terraform import #{resource_type}.#{resource[:resource_name]} #{resource[:resource_id]}"
|
18
|
+
end
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def resources
|
25
|
+
raise NotImplementedError
|
26
|
+
end
|
27
|
+
|
28
|
+
def resource_type
|
29
|
+
raise NotImplementedError
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Dd2tf
|
2
|
+
module Import
|
3
|
+
class Downtime < Base
|
4
|
+
def resource_type
|
5
|
+
"datadog_downtime"
|
6
|
+
end
|
7
|
+
|
8
|
+
def resources
|
9
|
+
resources = []
|
10
|
+
downtimes = @client.get_all_downtimes[1]
|
11
|
+
|
12
|
+
downtimes.each do |downtime|
|
13
|
+
downtime_name = downtime["id"]
|
14
|
+
resource_id = downtime["id"]
|
15
|
+
resources << { resource_id: resource_id, resource_name: downtime_name }
|
16
|
+
end
|
17
|
+
resources
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Dd2tf
|
2
|
+
module Import
|
3
|
+
class Monitor < Base
|
4
|
+
def resource_type
|
5
|
+
"datadog_monitor"
|
6
|
+
end
|
7
|
+
|
8
|
+
def resources
|
9
|
+
resources = []
|
10
|
+
monitors = @client.get_all_monitors[1]
|
11
|
+
|
12
|
+
monitors.each do |monitor|
|
13
|
+
monitor_name = monitor["name"].underscore.gsub(" ", "_").gsub(UNALLOWED_RESOURCE_TITLE_REGEXP, '')
|
14
|
+
resource_id = monitor["id"]
|
15
|
+
resources << { resource_id: resource_id, resource_name: monitor_name }
|
16
|
+
end
|
17
|
+
|
18
|
+
resources
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Dd2tf
|
2
|
+
module Import
|
3
|
+
class Timeboard < Base
|
4
|
+
def resource_type
|
5
|
+
"datadog_timeboard"
|
6
|
+
end
|
7
|
+
|
8
|
+
def resources
|
9
|
+
resources = []
|
10
|
+
boards = @client.get_dashboards[1]["dashes"]
|
11
|
+
|
12
|
+
boards.each do |board|
|
13
|
+
board_name = board["title"].underscore.gsub(" ", "_").gsub(UNALLOWED_RESOURCE_TITLE_REGEXP, '')
|
14
|
+
resource_id = board["id"]
|
15
|
+
resources << { resource_id: resource_id, resource_name: board_name }
|
16
|
+
end
|
17
|
+
|
18
|
+
resources
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Dd2tf
|
2
|
+
module Import
|
3
|
+
class User < Base
|
4
|
+
def resource_type
|
5
|
+
"datadog_user"
|
6
|
+
end
|
7
|
+
|
8
|
+
def resources
|
9
|
+
resources = []
|
10
|
+
users = @client.get_all_users[1]["users"]
|
11
|
+
|
12
|
+
users.each do |user|
|
13
|
+
user_name = user["name"].to_s.underscore.gsub(" ", "_").gsub(UNALLOWED_RESOURCE_TITLE_REGEXP, '')
|
14
|
+
# resource_id is the email address
|
15
|
+
# see: https://www.terraform.io/docs/providers/datadog/r/user.html#import
|
16
|
+
resource_id = user["email"]
|
17
|
+
resources << { resource_id: resource_id, resource_name: user_name }
|
18
|
+
end
|
19
|
+
resources
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/dd2tf/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dd2tf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- reizist
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dogapi
|
@@ -116,6 +116,11 @@ files:
|
|
116
116
|
- lib/dd2tf.rb
|
117
117
|
- lib/dd2tf/base.rb
|
118
118
|
- lib/dd2tf/config.rb
|
119
|
+
- lib/dd2tf/import/base.rb
|
120
|
+
- lib/dd2tf/import/downtime.rb
|
121
|
+
- lib/dd2tf/import/monitor.rb
|
122
|
+
- lib/dd2tf/import/timeboard.rb
|
123
|
+
- lib/dd2tf/import/user.rb
|
119
124
|
- lib/dd2tf/monitor.rb
|
120
125
|
- lib/dd2tf/timeboard.rb
|
121
126
|
- lib/dd2tf/user.rb
|