dd2tf 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c037ac78d253678306c6024b8392a6a367effb18
4
- data.tar.gz: 2568060ea2c6110d5ca454d1885a53424bd891bf
3
+ metadata.gz: a8a2f18e1bde472cb2cc32ed1297334f74647ca5
4
+ data.tar.gz: b74172a38ce877b6c8ddc6ef1a08021e7b2dd241
5
5
  SHA512:
6
- metadata.gz: 65df4757d1d84981fa4ef22fcc107ac9d4e4c2f2a81d6e8c706bb83146c0d4de02d7efb756d35dded379d2e9e7eda1e420dd7707ef471f315bfdb0da0e6011a2
7
- data.tar.gz: 3d9914aa01411f71adb40e61964e46459801765277941f0df54e4655ac3963e7e3f11b3654321ed51a0bec70de8f15e41ca3a4098b8fbe7a55bc22e39315fbbd
6
+ metadata.gz: d4ba7d722f27b99fed6ca38d96da4f04086de9c3fe8018c6daeb5431ebf1716076e61b30a8695bf3d5577cd7c02adf9ff390aad225ec96c9f843b8bc438e06b2
7
+ data.tar.gz: 3334c6dbf87aeb4eb2cf2ceb03bda267dc29b5ffedbf7f8ecc577ebaf6497cefd475f34e080f520b90223de79d2de21c68f58b26891d3dc3525905fe3e73085c
data/exe/dd2tf CHANGED
@@ -5,52 +5,11 @@ 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
-
47
8
  class Cli < Thor
48
- include Util
9
+ include Thor::Actions
49
10
 
50
11
  class_option :dd_api_key, type: :string
51
12
  class_option :dd_app_key, type: :string
52
- desc "print [resource]", "Print import resource command from remote to tfstate."
53
- subcommand 'print', Print
54
13
 
55
14
  desc "puts monitor configuration as terraform config", "puts monitor config"
56
15
  def monitor
@@ -66,6 +25,14 @@ module Dd2tf
66
25
  def user
67
26
  puts User.new(client).output
68
27
  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
69
36
  end
70
37
  end
71
38
 
@@ -1,13 +1,6 @@
1
1
  require "dd2tf/version"
2
- require "dd2tf/config"
3
-
4
2
  require "dd2tf/base"
5
- require "dd2tf/user"
6
3
  require "dd2tf/monitor"
7
4
  require "dd2tf/timeboard"
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"
5
+ require "dd2tf/user"
6
+ require "dd2tf/config"
@@ -1,3 +1,3 @@
1
1
  module Dd2tf
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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.1
4
+ version: 0.1.2
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-07 00:00:00.000000000 Z
11
+ date: 2017-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dogapi
@@ -116,11 +116,6 @@ 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
124
119
  - lib/dd2tf/monitor.rb
125
120
  - lib/dd2tf/timeboard.rb
126
121
  - lib/dd2tf/user.rb
@@ -1,33 +0,0 @@
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
@@ -1,21 +0,0 @@
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
@@ -1,22 +0,0 @@
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
@@ -1,22 +0,0 @@
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
@@ -1,23 +0,0 @@
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