Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to use go mod #29

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
71 changes: 0 additions & 71 deletions Gopkg.lock

This file was deleted.

42 changes: 0 additions & 42 deletions Gopkg.toml

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Build Status](https://travis-ci.org/amnk/dd2tf.svg?branch=master)](https://travis-ci.org/amnk/dd2tf)

A simple utility to convert DataDog dashboards and/or monitors to Terraform format.
A simple utility to convert DataDog dashboards and/or monitors to Terraform format.

Requires `DATADOG_API_KEY` and `DATADOG_APP_KEY` environment variables.

Expand All @@ -9,8 +9,8 @@ Useful, if you had all dashboards configured adhoc and now want to follow DevOps
# How to build
Just run (GOPATH and sometimes GOBIN have to be set):
```bash
dep ensure
go generate && go build
cd src
go build && ./dd2tf
```

# Examples
Expand Down
6 changes: 4 additions & 2 deletions dashboards.go → src/dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
package main

import (
"fmt"
"github.com/zorkian/go-datadog-api"
)

type Dashboard struct {
}

func (d Dashboard) getElement(client datadog.Client, id int) (interface{}, error) {
dash, err := client.GetDashboard(*datadog.Int(id))
func (d Dashboard) getElement(client datadog.Client, id interface{}) (interface{}, error) {
idStr := fmt.Sprintf("%v", id)
dash, err := client.GetDashboard(idStr)
return dash, err
}

Expand Down
File renamed without changes.
Binary file added src/dd2tf
Binary file not shown.
8 changes: 8 additions & 0 deletions src/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/amnk/dd2tf

require (
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/sirupsen/logrus v1.4.2
github.com/spf13/pflag v1.0.5
github.com/zorkian/go-datadog-api v2.27.0+incompatible
)
19 changes: 19 additions & 0 deletions src/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/zorkian/go-datadog-api v2.27.0+incompatible h1:n2O5e7F1xu2WuFyMcX1tYbOwkI/BbqanxnHFWa2nUZw=
github.com/zorkian/go-datadog-api v2.27.0+incompatible/go.mod h1:PkXwHX9CUQa/FpB9ZwAD45N1uhCW4MT/Wj7m36PbKss=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
12 changes: 6 additions & 6 deletions main.go → src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ var config = LocalConfig{
}

type DatadogElement interface {
getElement(client datadog.Client, i int) (interface{}, error)
getElement(client datadog.Client, i interface{}) (interface{}, error)
getAsset() string
getName() string
getAllElements(client datadog.Client) ([]Item, error)
}

type Item struct {
id int
id interface{}
d DatadogElement
}

Expand All @@ -60,13 +60,13 @@ func (i *Item) renderElement(item interface{}, config LocalConfig) {
file := fmt.Sprintf("%v-%v.tf", i.d.getName(), i.id)
f, err := os.OpenFile(file, os.O_RDWR|os.O_CREATE, 0755)
if err != nil {
log.Fatal(err)
// log.Fatal(err)
}
out := bufio.NewWriter(f)
t.Execute(out, item)
out.Flush()
if err := f.Close(); err != nil {
log.Fatal(err)
// log.Fatal(err)
}
} else {
t.Execute(os.Stdout, item)
Expand All @@ -79,15 +79,15 @@ func escapeCharacters(line string) string {
}

type SecondaryOptions struct {
ids []int
ids []string
files bool
all bool
debug bool
}

func NewSecondaryOptions(cmd *flag.FlagSet) *SecondaryOptions {
options := &SecondaryOptions{}
cmd.IntSliceVar(&options.ids, "ids", []int{}, "IDs of the elements to fetch.")
cmd.StringSliceVar(&options.ids, "ids", []string{}, "IDs of the elements to fetch.")
cmd.BoolVar(&options.all, "all", false, "Export all available elements.")
cmd.BoolVar(&options.files, "files", false, "Save each element into a separate file.")
cmd.BoolVar(&options.debug, "debug", false, "Enable debug output.")
Expand Down
4 changes: 2 additions & 2 deletions monitors.go → src/monitors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
type Monitor struct {
}

func (m Monitor) getElement(client datadog.Client, id int) (interface{}, error) {
mon, err := client.GetMonitor(id)
func (m Monitor) getElement(client datadog.Client, id interface{}) (interface{}, error) {
mon, err := client.GetMonitor(*datadog.Int(id.(int)))
return mon, err
}

Expand Down
6 changes: 4 additions & 2 deletions screenboards.go → src/screenboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
package main

import (
"fmt"
"github.com/zorkian/go-datadog-api"
)

type ScreenBoard struct {
}

func (s ScreenBoard) getElement(client datadog.Client, id int) (interface{}, error) {
elem, err := client.GetScreenboard(*datadog.Int(id))
func (s ScreenBoard) getElement(client datadog.Client, id interface{}) (interface{}, error) {
idStr := fmt.Sprintf("%v", id)
elem, err := client.GetScreenboard(*datadog.String(idStr))
return elem, err
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 0 additions & 22 deletions vendor/github.com/cenkalti/backoff/.gitignore

This file was deleted.

9 changes: 0 additions & 9 deletions vendor/github.com/cenkalti/backoff/.travis.yml

This file was deleted.

20 changes: 0 additions & 20 deletions vendor/github.com/cenkalti/backoff/LICENSE

This file was deleted.

30 changes: 0 additions & 30 deletions vendor/github.com/cenkalti/backoff/README.md

This file was deleted.

Loading