Skip to content

Commit

Permalink
Merge branch 'release/7.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
disaster37 committed Nov 14, 2019
2 parents fe494e5 + da45e7d commit 7c3ee15
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 9 deletions.
6 changes: 5 additions & 1 deletion fixtures/index-pattern.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ module github.com/disaster37/terraform-provider-kibana/v7
go 1.12

require (
github.com/disaster37/go-kibana-rest/v7 v7.4.2
github.com/disaster37/go-kibana-rest/v7 v7.4.2-2
github.com/hashicorp/terraform-plugin-sdk v1.1.1
github.com/mitchellh/gox v1.0.1
github.com/pkg/errors v0.8.1
github.com/sirupsen/logrus v1.4.2
github.com/x-cray/logrus-prefixed-formatter v0.5.2
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ github.com/disaster37/go-kibana-rest v0.0.0-20191014132112-c16bbbfcc362 h1:xFx41
github.com/disaster37/go-kibana-rest v0.0.0-20191014132112-c16bbbfcc362/go.mod h1:Xr2USECnlSBPSPlW40ufJx2Ou8gw0+EsYWa4gSVSYLU=
github.com/disaster37/go-kibana-rest/v7 v7.0.0-20191107130548-1c56270ba834 h1:bD43wSIrhCrR7VxwSHjCIDxcTVwXKx0eHHktS1zCcR4=
github.com/disaster37/go-kibana-rest/v7 v7.0.0-20191107130548-1c56270ba834/go.mod h1:Z87HQt6dkf7SvYqJinKPELp9HOPz15odL9ozK6iAXXI=
github.com/disaster37/go-kibana-rest/v7 v7.4.2-2 h1:rB8+FoQaa1zpTpsz4xpfP1+doR1ATmMKt7EWTltdxuc=
github.com/disaster37/go-kibana-rest/v7 v7.4.2-2/go.mod h1:Z87HQt6dkf7SvYqJinKPELp9HOPz15odL9ozK6iAXXI=
github.com/disaster37/go-kibana-rest/v7 v7.4.2 h1:ZD/qMxvfwoQlHTMbU2po9BuamTNQXTM/ZxmJVQpzK/4=
github.com/disaster37/go-kibana-rest/v7 v7.4.2/go.mod h1:Z87HQt6dkf7SvYqJinKPELp9HOPz15odL9ozK6iAXXI=
github.com/disaster37/terraform-provider-kibana v0.0.0-20191011125519-b57968904215 h1:+NezComO7Ky50C8qsDlSFZu/BgHvTLM/rBK3Zj3EE58=
Expand Down Expand Up @@ -104,6 +106,7 @@ github.com/hashicorp/go-safetemp v1.0.0 h1:2HR189eFNrjHQyENnQMMpCiBAsRxzbTMIgBhE
github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoDHxNAB65b+Rj1I=
github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.0.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.2.0 h1:3vNe/fWF5CBgRIguda1meWhsZHy3m8gCJ5wx+dIzX/E=
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
Expand Down Expand Up @@ -134,6 +137,7 @@ github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5i
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/keybase/go-crypto v0.0.0-20161004153544-93f5b35093ba/go.mod h1:ghbZscTyKdM07+Fw3KSi0hcJm+AlEUWj8QLlPtijN/M=
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/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down Expand Up @@ -174,6 +178,10 @@ github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eI
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4=
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
github.com/mitchellh/gox v1.0.1 h1:x0jD3dcHk9a9xPSDN6YEL4xL6Qz0dvNYm8yZqui5chI=
github.com/mitchellh/gox v1.0.1/go.mod h1:ED6BioOGXMswlXa2zxfh/xdd5QhwYliBFn9V18Ap4z4=
github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY=
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
Expand Down
58 changes: 58 additions & 0 deletions kb/diff_suppress_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kb
import (
"encoding/json"
"reflect"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
Expand All @@ -18,3 +19,60 @@ func suppressEquivalentJSON(k, old, new string, d *schema.ResourceData) bool {
}
return reflect.DeepEqual(oldObj, newObj)
}

// suppressEquivalentNDJSON permit to compare ndjson string
func suppressEquivalentNDJSON(k, old, new string, d *schema.ResourceData) bool {

// NDJSON mean sthat each line correspond to JSON struct
oldSlice := strings.Split(old, "\n")
newSlice := strings.Split(new, "\n")
oldObjSlice := make([]map[string]interface{}, len(oldSlice))
newObjSlice := make([]map[string]interface{}, len(newSlice))
if len(oldSlice) != len(newSlice) {
return false
}

// Convert string line to JSON
for i, oldJSON := range oldSlice {
jsonObj := make(map[string]interface{})
if err := json.Unmarshal([]byte(oldJSON), &jsonObj); err != nil {
return false
}

delete(jsonObj, "version")
delete(jsonObj, "updated_at")

oldObjSlice[i] = jsonObj
}
for i, newJSON := range newSlice {
jsonObj := make(map[string]interface{})
if err := json.Unmarshal([]byte(newJSON), &jsonObj); err != nil {
return false
}
delete(jsonObj, "version")
delete(jsonObj, "updated_at")

newObjSlice[i] = jsonObj
}

// Compare json obj
for _, oldJSON := range oldObjSlice {
isFound := false
for _, newJSON := range newObjSlice {
if oldJSON["id"].(string) == newJSON["id"].(string) {
if reflect.DeepEqual(oldJSON, newJSON) == false {
return false
}
isFound = true
break
}
}

if isFound == false {
return false
}
}

return true

}
11 changes: 11 additions & 0 deletions kb/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ func Provider() terraform.ResourceProvider {
Default: 10,
Description: "Wait time in second before retry connexion",
},
"debug": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Enable debug log level in provider",
},
},

ResourcesMap: map[string]*schema.Resource{
Expand All @@ -87,6 +93,11 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
password := d.Get("password").(string)
retry := d.Get("retry").(int)
waitBeforeRetry := d.Get("wait_before_retry").(int)
debug := d.Get("debug").(bool)

if debug {
log.SetLevel(log.DebugLevel)
}

// Checks is valid URL
if _, err := url.Parse(URL); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions kb/resource_kibana_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func resourceKibanaObject() *schema.Resource {
"data": {
Type: schema.TypeString,
Required: true,
DiffSuppressFunc: suppressEquivalentJSON,
DiffSuppressFunc: suppressEquivalentNDJSON,
},
"export_types": {
Type: schema.TypeSet,
Expand Down Expand Up @@ -115,10 +115,10 @@ func resourceKibanaObjectRead(d *schema.ResourceData, meta interface{}) error {
return nil
}

log.Debugf("Export object %s successfully:\n%+v", id, data)
log.Debugf("Export object %s successfully:\n%+v", id, string(data))

d.Set("name", id)
d.Set("data", data)
d.Set("data", string(data))
d.Set("space", space)
d.Set("export_types", exportTypes)
d.Set("export_objects", exportObjects)
Expand Down
5 changes: 1 addition & 4 deletions kb/resource_kibana_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ resource "kibana_object" "test" {
name = "terraform-test"
data = "${file("../fixtures/index-pattern.json")}"
deep_reference = "true"
export_objects {
id = "logstash-log-*"
type = "index-pattern"
}
export_types = ["index-pattern"]
}
`
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ func main() {
plugin.Serve(&plugin.ServeOpts{
ProviderFunc: kb.Provider,
})

}

0 comments on commit 7c3ee15

Please sign in to comment.