dd2tf 0.1.2 → 0.2.0
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/README.md +20 -12
- data/exe/dd2tf +69 -16
- data/lib/dd2tf.rb +8 -2
- data/lib/dd2tf/base.rb +1 -1
- data/lib/dd2tf/import/base.rb +32 -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/monitor.rb +1 -1
- data/lib/dd2tf/timeboard.rb +1 -1
- data/lib/dd2tf/user.rb +1 -1
- data/lib/dd2tf/version.rb +1 -1
- metadata +6 -2
- data/lib/dd2tf/config.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f66178c5394b541c9a77bf18f927e0799f260be9
|
4
|
+
data.tar.gz: 0216d45d2bcd15c29c5813ed0a9747a2498c664b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b749d8cbd33e140611b4e304985ef5b09ee09083bec226b47c02a8b8fdc3d788283837a65bade2726d19f8b6aa0660720fd956cfe5bc3a076b6f4aa809c0e48
|
7
|
+
data.tar.gz: 19be79a6b89322451f302890246924fe87ffb8bb03b40e89f9648c94f23be4097dd04283468ffddc18987f230ca2ad96a617443b8308d351aad35bbad2389a64
|
data/README.md
CHANGED
@@ -24,24 +24,24 @@ Or install it yourself as:
|
|
24
24
|
```
|
25
25
|
$ dd2tf help
|
26
26
|
Commands:
|
27
|
-
dd2tf help [COMMAND]
|
28
|
-
dd2tf
|
29
|
-
dd2tf
|
30
|
-
dd2tf puts user configuration as terraform config # puts user config
|
27
|
+
dd2tf help [COMMAND] # Describe available commands or one specific command
|
28
|
+
dd2tf print [resource] # Print resources importing command for outputting to tfstate. [resource] is one of the [monitor, timeboard, user, downtime]
|
29
|
+
dd2tf tf [resource] # Print resources config terrafom formatted. [resource] is one of the [monitor, timeboard, user]
|
31
30
|
|
32
31
|
Options:
|
33
|
-
|
34
|
-
|
32
|
+
--dd-api-key=DD_API_KEY
|
33
|
+
--dd-app-key=DD_APP_KEY
|
35
34
|
```
|
36
35
|
|
37
|
-
|
36
|
+
|
37
|
+
### Print resources config terraform formatted
|
38
38
|
|
39
39
|
```
|
40
|
-
$ dd2tf user --dd_api_key=xxx --dd-app_key=xxx
|
40
|
+
$ dd2tf tf user --dd_api_key=xxx --dd-app_key=xxx
|
41
41
|
resource "datadog_user" "reiji_kainuma" {
|
42
42
|
disabled = "false"
|
43
|
-
email = "reizist@
|
44
|
-
handle = "reizist@
|
43
|
+
email = "reizist@example.com"
|
44
|
+
handle = "reizist@example.com"
|
45
45
|
is_admin = "true"
|
46
46
|
name = "Reiji Kainuma"
|
47
47
|
role = ""
|
@@ -50,7 +50,7 @@ resource "datadog_user" "reiji_kainuma" {
|
|
50
50
|
```
|
51
51
|
|
52
52
|
```
|
53
|
-
$ dd2tf monitor --dd_api_key=xxx --dd-app_key=xxx
|
53
|
+
$ dd2tf tf monitor --dd_api_key=xxx --dd-app_key=xxx
|
54
54
|
resource "datadog_monitor" "auto_clock_in_sync_with_ntp" {
|
55
55
|
name = "[Auto] Clock in sync with NTP"
|
56
56
|
type = "service check"
|
@@ -70,7 +70,7 @@ Please read the [KB article](http://help.datadoghq.com/hc/en-us/articles/2042820
|
|
70
70
|
```
|
71
71
|
|
72
72
|
```
|
73
|
-
$ dd2tf timeboard --dd_api_key=xxx --dd-app_key=xxx
|
73
|
+
$ dd2tf tf timeboard --dd_api_key=xxx --dd-app_key=xxx
|
74
74
|
resource "datadog_timeboard" "presto_staging" {
|
75
75
|
title = "Presto(staging)"
|
76
76
|
description = "created by xxx"
|
@@ -95,6 +95,14 @@ resource "datadog_timeboard" "presto_staging" {
|
|
95
95
|
}
|
96
96
|
```
|
97
97
|
|
98
|
+
### Print import command for importing resources to tfstate
|
99
|
+
|
100
|
+
```
|
101
|
+
$ dd2tf print monitor --dd_api_key=xxx --dd-app_key=xxx
|
102
|
+
terraform import datadog_monitor.presto_insufficient_resource_error xxxxxxx
|
103
|
+
terraform import datadog_monitor.presto_queueing_is_very_high xxxxxxx
|
104
|
+
```
|
105
|
+
|
98
106
|
# Contributing
|
99
107
|
|
100
108
|
Bug reports and pull requests are welcome on GitHub at https://github.com/reizist/dd2tf. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
|
data/exe/dd2tf
CHANGED
@@ -5,34 +5,87 @@ require 'thor'
|
|
5
5
|
require 'dogapi'
|
6
6
|
|
7
7
|
module Dd2tf
|
8
|
-
class Cli < Thor
|
9
|
-
include Thor::Actions
|
10
8
|
|
11
|
-
|
12
|
-
|
9
|
+
module Util
|
10
|
+
def self.included klass
|
11
|
+
klass.class_eval do
|
12
|
+
class_option(:dd_api_key, desc: "api key")
|
13
|
+
class_option(:dd_app_key, desc: "app key")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def client
|
18
|
+
instance_variable_get_or_set("@client",
|
19
|
+
::Dogapi::Client.new(options[:dd_api_key], options[:dd_app_key]))
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def instance_variable_get_or_set(name, object)
|
25
|
+
instance_variable_get(name) || instance_variable_set(name, object)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Print < Thor
|
30
|
+
include Util
|
31
|
+
|
32
|
+
desc "user", "ipmort user resource to tfstate"
|
33
|
+
def user
|
34
|
+
puts ::Dd2tf::Import::User.new(client).print
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "downtime", "ipmort downtime resource to tfstate"
|
38
|
+
def downtime
|
39
|
+
puts ::Dd2tf::Import::Downtime.new(client).print
|
40
|
+
end
|
41
|
+
|
42
|
+
desc "monitor", "ipmort monitor resource to tfstate"
|
43
|
+
def monitor
|
44
|
+
puts ::Dd2tf::Import::Monitor.new(client).print
|
45
|
+
end
|
13
46
|
|
14
|
-
desc "
|
47
|
+
desc "timeboard", "ipmort timeboard resource to tfstate"
|
48
|
+
def timeboard
|
49
|
+
puts ::Dd2tf::Import::Timeboard.new(client).print
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class Tf < Thor
|
54
|
+
include Util
|
55
|
+
|
56
|
+
desc "monitor", "puts monitor config"
|
15
57
|
def monitor
|
16
|
-
puts Monitor.new(client).output
|
58
|
+
puts ::Dd2tf::Monitor.new(client).output
|
17
59
|
end
|
18
60
|
|
19
|
-
desc "
|
61
|
+
desc "timeboard", "puts timeboard config"
|
20
62
|
def timeboard
|
21
|
-
puts Timeboard.new(client).output
|
63
|
+
puts ::Dd2tf::Timeboard.new(client).output
|
22
64
|
end
|
23
65
|
|
24
|
-
desc "
|
66
|
+
desc "user", "puts user config"
|
25
67
|
def user
|
26
|
-
puts User.new(client).output
|
68
|
+
puts ::Dd2tf::User.new(client).output
|
27
69
|
end
|
70
|
+
end
|
28
71
|
|
29
|
-
|
72
|
+
class Cli < Thor
|
73
|
+
include Thor::Actions
|
74
|
+
include Util
|
75
|
+
|
76
|
+
class_option :dd_api_key, type: :string, required: true
|
77
|
+
class_option :dd_app_key, type: :string, required: true
|
78
|
+
|
79
|
+
desc "print [resource]",
|
80
|
+
"Print resources importing command for outputting to tfstate.
|
81
|
+
[resource] is one of the [monitor, timeboard, user, downtime]"
|
82
|
+
subcommand 'print', Print
|
83
|
+
|
84
|
+
desc "tf [resource]",
|
85
|
+
"Print resources config terrafom formatted.
|
86
|
+
[resource] is one of the [monitor, timeboard, user]"
|
87
|
+
subcommand 'tf', Tf
|
30
88
|
|
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
89
|
end
|
37
90
|
end
|
38
91
|
|
data/lib/dd2tf.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
require "dd2tf/version"
|
2
|
+
|
2
3
|
require "dd2tf/base"
|
4
|
+
require "dd2tf/user"
|
3
5
|
require "dd2tf/monitor"
|
4
6
|
require "dd2tf/timeboard"
|
5
|
-
|
6
|
-
require "dd2tf/
|
7
|
+
|
8
|
+
require "dd2tf/import/base"
|
9
|
+
require "dd2tf/import/user"
|
10
|
+
require "dd2tf/import/monitor"
|
11
|
+
require "dd2tf/import/timeboard"
|
12
|
+
require "dd2tf/import/downtime"
|
data/lib/dd2tf/base.rb
CHANGED
@@ -3,9 +3,9 @@ require 'active_support'
|
|
3
3
|
require 'active_support/core_ext'
|
4
4
|
|
5
5
|
module Dd2tf
|
6
|
+
UNALLOWED_RESOURCE_TITLE_REGEXP = /\(|\)|'|,|\.|\[|\]|:/
|
6
7
|
class Base
|
7
8
|
class NotImplementedError < StandardError; end
|
8
|
-
UNALLOWED_RESOURCE_TITLE_REGEXP = /\(|\)|'|\.|\[|\]|:/
|
9
9
|
|
10
10
|
def initialize(client)
|
11
11
|
@client = client
|
@@ -0,0 +1,32 @@
|
|
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
|
+
|
10
|
+
def initialize(client)
|
11
|
+
@client = client
|
12
|
+
end
|
13
|
+
|
14
|
+
def print
|
15
|
+
resources.each do |resource|
|
16
|
+
puts "terraform import #{resource_type}.#{resource[:resource_name]} #{resource[:resource_id]}"
|
17
|
+
end
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def resources
|
24
|
+
raise NotImplementedError
|
25
|
+
end
|
26
|
+
|
27
|
+
def resource_type
|
28
|
+
raise NotImplementedError
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
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(::Dd2tf::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(::Dd2tf::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(::Dd2tf::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/monitor.rb
CHANGED
@@ -6,7 +6,7 @@ module Dd2tf
|
|
6
6
|
|
7
7
|
results = []
|
8
8
|
monitors.each do |monitor|
|
9
|
-
monitor_name = monitor["name"].underscore.gsub(" ", "_").gsub(UNALLOWED_RESOURCE_TITLE_REGEXP, '')
|
9
|
+
monitor_name = monitor["name"].underscore.gsub(" ", "_").gsub(::Dd2tf::UNALLOWED_RESOURCE_TITLE_REGEXP, '')
|
10
10
|
renderer = renderer()
|
11
11
|
results << renderer.result(binding)
|
12
12
|
end
|
data/lib/dd2tf/timeboard.rb
CHANGED
@@ -5,7 +5,7 @@ module Dd2tf
|
|
5
5
|
board_ids = @client.get_dashboards[1]["dashes"].map{|board| board["id"]}
|
6
6
|
board_ids.each do |board_id|
|
7
7
|
board = @client.get_dashboard(board_id)[1]["dash"]
|
8
|
-
board_name = board["title"].underscore.gsub(' ', '_').gsub(UNALLOWED_RESOURCE_TITLE_REGEXP, '')
|
8
|
+
board_name = board["title"].underscore.gsub(' ', '_').gsub(::Dd2tf::UNALLOWED_RESOURCE_TITLE_REGEXP, '')
|
9
9
|
renderer = renderer()
|
10
10
|
results << renderer.result(binding)
|
11
11
|
end
|
data/lib/dd2tf/user.rb
CHANGED
@@ -6,7 +6,7 @@ module Dd2tf
|
|
6
6
|
|
7
7
|
results = []
|
8
8
|
users.each do |user|
|
9
|
-
user_name = user["name"].to_s.underscore.gsub(" ", "_").gsub(UNALLOWED_RESOURCE_TITLE_REGEXP, '')
|
9
|
+
user_name = user["name"].to_s.underscore.gsub(" ", "_").gsub(::Dd2tf::UNALLOWED_RESOURCE_TITLE_REGEXP, '')
|
10
10
|
renderer = renderer()
|
11
11
|
results << renderer.result(binding)
|
12
12
|
end
|
data/lib/dd2tf/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dd2tf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- reizist
|
@@ -115,7 +115,11 @@ files:
|
|
115
115
|
- exe/dd2tf
|
116
116
|
- lib/dd2tf.rb
|
117
117
|
- lib/dd2tf/base.rb
|
118
|
-
- lib/dd2tf/
|
118
|
+
- lib/dd2tf/import/base.rb
|
119
|
+
- lib/dd2tf/import/downtime.rb
|
120
|
+
- lib/dd2tf/import/monitor.rb
|
121
|
+
- lib/dd2tf/import/timeboard.rb
|
122
|
+
- lib/dd2tf/import/user.rb
|
119
123
|
- lib/dd2tf/monitor.rb
|
120
124
|
- lib/dd2tf/timeboard.rb
|
121
125
|
- lib/dd2tf/user.rb
|