Skip to content

Commit

Permalink
Upgrade some libs (#13)
Browse files Browse the repository at this point in the history
* Upgrade to sdk 2

Signed-off-by: disaster37 <[email protected]>

* Fix bad import

Signed-off-by: disaster37 <[email protected]>

* Fix test on provider

Signed-off-by: disaster37 <[email protected]>

* try to fix kibana_role

Signed-off-by: disaster37 <[email protected]>

* Try to fix test

Signed-off-by: disaster37 <[email protected]>

* Try to fix

Signed-off-by: disaster37 <[email protected]>

* try fix

Signed-off-by: disaster37 <[email protected]>

* try fix

Signed-off-by: disaster37 <[email protected]>

* try to display logs

Signed-off-by: disaster37 <[email protected]>

* try to add trace

Signed-off-by: disaster37 <[email protected]>

* Try to display trace

Signed-off-by: disaster37 <[email protected]>

* fix

Signed-off-by: disaster37 <[email protected]>

* add trace

Signed-off-by: disaster37 <[email protected]>

* try fix

Signed-off-by: disaster37 <[email protected]>

* Try to fix

Signed-off-by: disaster37 <[email protected]>

* Fix error

Signed-off-by: disaster37 <[email protected]>

* Fix schema set for kibana_role

Signed-off-by: disaster37 <[email protected]>

* try to fix

Signed-off-by: disaster37 <[email protected]>

* fix

Signed-off-by: disaster37 <[email protected]>

* fix

Signed-off-by: disaster37 <[email protected]>

* fix

Signed-off-by: disaster37 <[email protected]>

* fix

Signed-off-by: disaster37 <[email protected]>

* fix

Signed-off-by: disaster37 <[email protected]>

* fix

Signed-off-by: disaster37 <[email protected]>

* fix

Signed-off-by: disaster37 <[email protected]>

* Fix test

Signed-off-by: disaster37 <[email protected]>

* fix test

Signed-off-by: disaster37 <[email protected]>

* fix

Signed-off-by: disaster37 <[email protected]>

* fix path

Signed-off-by: disaster37 <[email protected]>

* test

Signed-off-by: disaster37 <[email protected]>

* test

Signed-off-by: disaster37 <[email protected]>

* test

Signed-off-by: disaster37 <[email protected]>

* test

Signed-off-by: disaster37 <[email protected]>

* test

Signed-off-by: disaster37 <[email protected]>

* test

Signed-off-by: disaster37 <[email protected]>

* Fix

Signed-off-by: disaster37 <[email protected]>
  • Loading branch information
disaster37 authored Aug 25, 2021
1 parent 67008d2 commit bc90521
Show file tree
Hide file tree
Showing 21 changed files with 720 additions and 337 deletions.
10 changes: 3 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ orbs:
jobs:
test:
docker:
- image: circleci/golang:1.12
- image: circleci/golang:1.16
environment:
- GO111MODULE: "on"
- KIBANA_URL: "http://kb:5601"
- KIBANA_USERNAME: "elastic"
- KIBANA_PASSWORD: "changeme"
Expand Down Expand Up @@ -40,18 +39,15 @@ jobs:
flags: unittest
build:
docker:
- image: circleci/golang:1.12
environment:
- GO111MODULE: "on"
- image: circleci/golang:1.16
working_directory: /go/src/github.com/disaster37/terraform-provider-kibana
steps:
- checkout
- run: make build
release:
docker:
- image: circleci/golang:1.12
- image: circleci/golang:1.16
environment:
- GO111MODULE: "on"
- GITHUB_TOKEN: $GITHUB_TOKEN
- CIRCLE_PROJECT_USERNAME: $CIRCLE_PROJECT_USERNAME
- CIRCLE_PROJECT_REPONAME: $CIRCLE_PROJECT_REPONAME
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.14
go-version: 1.16
-
name: Import GPG key
id: import_gpg
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@

dist/

coverage.txt
coverage.txt
terraform-provider-kibana
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test: fmtcheck
go test $(TEST) -timeout=30s -parallel=4

testacc: fmt fmtcheck
KIBANA_URL=${KIBANA_URL} KIBANA_USERNAME=${KIBANA_USERNAME} KIBANA_PASSWORD=${KIBANA_PASSWORD} TF_ACC=1 go test $(TEST) -v -count 1 -parallel 1 -race -coverprofile=coverage.txt -covermode=atomic $(TESTARGS) -timeout 120m
KIBANA_URL=${KIBANA_URL} KIBANA_USERNAME=${KIBANA_USERNAME} KIBANA_PASSWORD=${KIBANA_PASSWORD} TF_ACC=1 TF_LOG_PROVIDER=DEBUG go test $(TEST) -v -count 1 -parallel 1 -race -coverprofile=coverage.txt -covermode=atomic $(TESTARGS) -timeout 120m

fmt:
@echo "==> Fixing source code with gofmt..."
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module github.com/disaster37/terraform-provider-kibana/v7

go 1.12
go 1.16

require (
github.com/disaster37/go-kibana-rest/v7 v7.5.1-2
github.com/hashicorp/terraform-plugin-sdk v1.7.0
github.com/mitchellh/gox v1.0.1
github.com/pkg/errors v0.8.1
github.com/sirupsen/logrus v1.4.2
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.0
github.com/pkg/errors v0.9.1
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 // indirect
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e // indirect
)
562 changes: 395 additions & 167 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion kb/diff_suppress_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"reflect"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

// suppressEquivalentJSON permit to compare json string
Expand Down
28 changes: 4 additions & 24 deletions kb/provider.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
package kb

import (
"log"
"net/url"
"os"
"time"

kibana "github.com/disaster37/go-kibana-rest/v7"
"github.com/disaster37/go-kibana-rest/v7/kbapi"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/t-tomalak/logrus-easy-formatter"
)

// Provider define kibana provider
func Provider() terraform.ResourceProvider {
func Provider() *schema.Provider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"url": {
Expand Down Expand Up @@ -63,12 +60,6 @@ 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 Down Expand Up @@ -96,17 +87,6 @@ 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)

log.SetFormatter(&easy.Formatter{
LogFormat: "[%lvl%] %msg%",
})
log.SetOutput(os.Stderr)
log.SetLevel(log.InfoLevel)

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

// Checks is valid URL
if _, err := url.Parse(URL); err != nil {
Expand Down Expand Up @@ -153,7 +133,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
}

version := kibanaStatus["version"].(map[string]interface{})["number"].(string)
log.Debugf("Server: %s", version)
log.Printf("[DEBUG] Server: %s", version)

if version < "8.0.0" && version >= "7.0.0" {
log.Printf("[INFO] Using Kibana 7")
Expand Down
19 changes: 6 additions & 13 deletions kb/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,34 @@ import (
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/sirupsen/logrus"
prefixed "github.com/x-cray/logrus-prefixed-formatter"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

var testAccProviders map[string]terraform.ResourceProvider
var testAccProviders map[string]*schema.Provider
var testAccProvider *schema.Provider

func init() {

// Init logger
logrus.SetFormatter(new(prefixed.TextFormatter))
logrus.SetLevel(logrus.InfoLevel)

// Init provider
testAccProvider = Provider().(*schema.Provider)
testAccProvider = Provider()
configureFunc := testAccProvider.ConfigureFunc
testAccProvider.ConfigureFunc = func(d *schema.ResourceData) (interface{}, error) {
return configureFunc(d)
}
testAccProviders = map[string]terraform.ResourceProvider{
testAccProviders = map[string]*schema.Provider{
"kibana": testAccProvider,
}

}

func TestProvider(t *testing.T) {
if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
if err := Provider().InternalValidate(); err != nil {
t.Fatalf("err: %s", err)
}
}

func TestProvider_impl(t *testing.T) {
var _ terraform.ResourceProvider = Provider()
var _ *schema.Provider = Provider()
}

func testAccPreCheck(t *testing.T) {
Expand Down
40 changes: 19 additions & 21 deletions kb/resource_kibana_copy_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
package kb

import (
"fmt"
"log"

kibana "github.com/disaster37/go-kibana-rest/v7"
"github.com/disaster37/go-kibana-rest/v7/kbapi"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
log "github.com/sirupsen/logrus"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

// Resource specification to handle kibana save object
Expand Down Expand Up @@ -87,7 +86,7 @@ func resourceKibanaCopyObjectCreate(d *schema.ResourceData, meta interface{}) er

d.SetId(name)

log.Infof("Copy objects %s successfully", name)
log.Printf("[INFO] Copy objects %s successfully", name)

return resourceKibanaCopyObjectRead(d, meta)
}
Expand All @@ -103,13 +102,13 @@ func resourceKibanaCopyObjectRead(d *schema.ResourceData, meta interface{}) erro
overwrite := d.Get("overwrite").(bool)
forceUpdate := d.Get("force_update").(bool)

log.Debugf("Resource id: %s", id)
log.Debugf("Source space: %s", sourceSpace)
log.Debugf("Target spaces: %+v", targetSpaces)
log.Debugf("Objects: %+v", objects)
log.Debugf("Include reference: %t", includeReference)
log.Debugf("Overwrite: %t", overwrite)
log.Debugf("force_update: %t", forceUpdate)
log.Printf("[DEBUG] Resource id: %s", id)
log.Printf("[DEBUG] Source space: %s", sourceSpace)
log.Printf("[DEBUG] Target spaces: %+v", targetSpaces)
log.Printf("[DEBUG] Objects: %+v", objects)
log.Printf("[DEBUG] Include reference: %t", includeReference)
log.Printf("[DEBUG] Overwrite: %t", overwrite)
log.Printf("[DEBUG] force_update: %t", forceUpdate)

// @ TODO
// A good when is to check if already exported object is the same that original space
Expand All @@ -124,7 +123,7 @@ func resourceKibanaCopyObjectRead(d *schema.ResourceData, meta interface{}) erro
d.Set("overwrite", overwrite)
d.Set("force_update", false)

log.Infof("Read resource %s successfully", id)
log.Printf("[INFO] Read resource %s successfully", id)

return nil
}
Expand All @@ -138,7 +137,7 @@ func resourceKibanaCopyObjectUpdate(d *schema.ResourceData, meta interface{}) er
return err
}

log.Infof("Updated resource %s successfully", id)
log.Printf("[INFO] Updated resource %s successfully", id)

return resourceKibanaCopyObjectRead(d, meta)
}
Expand All @@ -149,8 +148,7 @@ func resourceKibanaCopyObjectDelete(d *schema.ResourceData, meta interface{}) er

d.SetId("")

log.Infof("Delete object in not supported")
fmt.Printf("[INFO] Delete object in not supported - just removing from state")
log.Printf("[INFO] Delete object in not supported - just removing from state")
return nil

}
Expand Down Expand Up @@ -180,11 +178,11 @@ func copyObject(d *schema.ResourceData, meta interface{}) error {
includeReference := d.Get("include_reference").(bool)
overwrite := d.Get("overwrite").(bool)

log.Debugf("Source space: %s", sourceSpace)
log.Debugf("Target spaces: %+v", targetSpaces)
log.Debugf("Objects: %+v", objects)
log.Debugf("Include reference: %t", includeReference)
log.Debugf("Overwrite: %t", overwrite)
log.Printf("[DEBUG] Source space: %s", sourceSpace)
log.Printf("[DEBUG] Target spaces: %+v", targetSpaces)
log.Printf("[DEBUG] Objects: %+v", objects)
log.Printf("[DEBUG] Include reference: %t", includeReference)
log.Printf("[DEBUG] Overwrite: %t", overwrite)

client := meta.(*kibana.Client)

Expand All @@ -208,7 +206,7 @@ func copyObject(d *schema.ResourceData, meta interface{}) error {
return err
}

log.Debugf("Copy object for resource successfully: %s", name)
log.Printf("[DEBUG] Copy object for resource successfully: %s", name)

return nil
}
27 changes: 18 additions & 9 deletions kb/resource_kibana_copy_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package kb

import (
"fmt"
"log"
"testing"
"os"

kibana "github.com/disaster37/go-kibana-rest/v7"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)

func TestAccKibanaCopyObject(t *testing.T) {
Expand All @@ -21,7 +22,7 @@ func TestAccKibanaCopyObject(t *testing.T) {
CheckDestroy: testCheckKibanaCopyObjectDestroy,
Steps: []resource.TestStep{
{
Config: testKibanaCopyObject,
Config: getTestKibanaCopyObject(),
Check: resource.ComposeTestCheckFunc(
testCheckKibanaCopyObjectExists("kibana_copy_object.test"),
),
Expand Down Expand Up @@ -55,7 +56,6 @@ func testCheckKibanaCopyObjectExists(name string) resource.TestCheckFunc {
}

if len(data) == 0 {
panic(fmt.Sprintf("%+v", data))
return errors.Errorf("Object %s not found", rs.Primary.ID)
}

Expand All @@ -69,18 +69,25 @@ func testCheckKibanaCopyObjectDestroy(s *terraform.State) error {
continue
}

log.Debugf("We never delete kibana object")
log.Printf("We never delete kibana object")

}

return nil

}

var testKibanaCopyObject = `

func getTestKibanaCopyObject() string {
path, err := os.Getwd()
if err != nil {
panic(err)
}

return fmt.Sprintf(`
resource kibana_object "test" {
name = "terraform-test"
data = "${file("../fixtures/test.ndjson")}"
data = file("%s/../fixtures/test.ndjson")
deep_reference = "true"
export_types = ["index-pattern"]
}
Expand All @@ -100,4 +107,6 @@ resource kibana_copy_object "test" {
depends_on = [kibana_object.test, kibana_user_space.test]
}
`
`, path)

}
Loading

0 comments on commit bc90521

Please sign in to comment.