Skip to content

Commit

Permalink
Fix for reported crash & improve debuggability of exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
alexott authored and nfx committed May 24, 2021
1 parent 19edc9a commit c085722
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
13 changes: 12 additions & 1 deletion common/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package common
import (
"log"
"os"
"strconv"
"strings"
"sync"

Expand All @@ -17,6 +18,14 @@ var (

// NewClientFromEnvironment makes very good client for testing purposes
func NewClientFromEnvironment() *DatabricksClient {
debugBytes, err := strconv.Atoi(os.Getenv("DATABRICKS_DEBUG_TRUNCATE_BYTES"))
if err != nil {
debugBytes = DefaultTruncateBytes
}
debugHeaders, err := strconv.ParseBool(os.Getenv("DATABRICKS_DEBUG_HEADERS"))
if err != nil {
debugHeaders = false
}
client := DatabricksClient{
Host: os.Getenv("DATABRICKS_HOST"),
Token: os.Getenv("DATABRICKS_TOKEN"),
Expand All @@ -35,8 +44,10 @@ func NewClientFromEnvironment() *DatabricksClient {
Environment: os.Getenv("ARM_ENVIRONMENT"),
},
RateLimitPerSecond: 10,
DebugTruncateBytes: debugBytes,
DebugHeaders: debugHeaders,
}
err := client.Configure()
err = client.Configure()
if err != nil {
panic(err)
}
Expand Down
10 changes: 8 additions & 2 deletions exporter/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type mount struct {

func newImportContext(c *common.DatabricksClient) *importContext {
p := provider.DatabricksProvider()
p.TerraformVersion = "importer"
p.TerraformVersion = "exporter"
p.SetMeta(c)
ctx := context.WithValue(context.Background(), common.Provider, p)
c.WithCommandExecutor(func(
Expand Down Expand Up @@ -277,7 +277,13 @@ func (ic *importContext) Find(r *resource, pick string) hcl.Traversal {
continue
}
for _, i := range sr.Instances {
if i.Attributes[r.Attribute].(string) == r.Value {
v := i.Attributes[r.Attribute]
if v == nil {
log.Printf("[WARN] Can't find instance attribute '%v' in resource: '%v' with name '%v', ID: '%v'",
r.Attribute, r.Resource, r.Name, r.ID)
continue
}
if v.(string) == r.Value {
if sr.Mode == "data" {
return hcl.Traversal{
hcl.TraverseRoot{Name: "data"},
Expand Down

0 comments on commit c085722

Please sign in to comment.