From 3433850c9c92efe3a8b575e7cc33c4bd5e0987c3 Mon Sep 17 00:00:00 2001 From: Jake Champlin Date: Thu, 6 Apr 2017 13:59:16 -0400 Subject: [PATCH] provider/opc: Add debug logging Adds debug logging, fixes a failing instance acceptance test, and updates vendored dep --- builtin/providers/opc/config.go | 24 +++++++++++++++++-- builtin/providers/opc/provider.go | 1 + .../providers/opc/resource_instance_test.go | 2 +- .../go-oracle-terraform/compute/client.go | 2 ++ .../go-oracle-terraform/compute/logging.go | 2 +- .../compute/storage_volumes.go | 1 + vendor/vendor.json | 6 ++--- 7 files changed, 31 insertions(+), 7 deletions(-) diff --git a/builtin/providers/opc/config.go b/builtin/providers/opc/config.go index 5c473e591..b25167fe9 100644 --- a/builtin/providers/opc/config.go +++ b/builtin/providers/opc/config.go @@ -2,11 +2,14 @@ package opc import ( "fmt" - "net/http" + "log" "net/url" + "strings" + "github.com/fsouza/go-dockerclient/external/github.com/hashicorp/go-cleanhttp" "github.com/hashicorp/go-oracle-terraform/compute" "github.com/hashicorp/go-oracle-terraform/opc" + "github.com/hashicorp/terraform/helper/logging" ) type Config struct { @@ -33,9 +36,26 @@ func (c *Config) Client() (*compute.Client, error) { Username: &c.User, Password: &c.Password, APIEndpoint: u, - HTTPClient: http.DefaultClient, + HTTPClient: cleanhttp.DefaultClient(), + } + + if logging.IsDebugOrHigher() { + config.LogLevel = opc.LogDebug + config.Logger = opcLogger{} } // TODO: http client wrapping / log level return compute.NewComputeClient(&config) } + +type opcLogger struct{} + +func (l opcLogger) Log(args ...interface{}) { + tokens := make([]string, 0, len(args)) + for _, arg := range args { + if token, ok := arg.(string); ok { + tokens = append(tokens, token) + } + } + log.Printf("[DEBUG] [go-oracle-terraform]: %s", strings.Join(tokens, " ")) +} diff --git a/builtin/providers/opc/provider.go b/builtin/providers/opc/provider.go index 579d5ac7b..ddde50d5a 100644 --- a/builtin/providers/opc/provider.go +++ b/builtin/providers/opc/provider.go @@ -36,6 +36,7 @@ func Provider() terraform.ResourceProvider { Description: "The HTTP endpoint for OPC API operations.", }, + // TODO Actually implement this "max_retry_timeout": { Type: schema.TypeInt, Optional: true, diff --git a/builtin/providers/opc/resource_instance_test.go b/builtin/providers/opc/resource_instance_test.go index 3c4e0ffe6..2cc61eb39 100644 --- a/builtin/providers/opc/resource_instance_test.go +++ b/builtin/providers/opc/resource_instance_test.go @@ -188,7 +188,7 @@ resource "opc_compute_instance" "test" { image_list = "/oracle/public/oel_6.7_apaas_16.4.5_1610211300" instance_attributes = <