Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit be44786

Browse files
authored
Update: enable OS_DEBUG (terraform-provider-openstack#1246)
* Update: enable debug logging in the provider - when TF_LOG is debug/trace (and OS_DEBUG is not set) - enable this by default (person probably wants it) Resolves: terraform-provider-openstack#1203 * Chore: update github.com/gophercloud/utils
1 parent c73df4e commit be44786

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

openstack/provider.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package openstack
22

33
import (
44
"context"
5+
"os"
56

67
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging"
79
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
810
"github.com/hashicorp/terraform-plugin-sdk/v2/meta"
911

@@ -245,6 +247,13 @@ func Provider() *schema.Provider {
245247
Default: false,
246248
Description: descriptions["disable_no_cache_header"],
247249
},
250+
251+
"enable_logging": {
252+
Type: schema.TypeBool,
253+
Optional: true,
254+
Default: false,
255+
Description: descriptions["enable_logging"],
256+
},
248257
},
249258

250259
DataSourcesMap: map[string]*schema.Resource{
@@ -487,10 +496,22 @@ func init() {
487496
"automatically, if the initial auth token get expired. Defaults to `true`",
488497

489498
"max_retries": "How many times HTTP connection should be retried until giving up.",
499+
500+
"enable_logging": "Outputs very verbose logs with all calls made to and responses from OpenStack",
490501
}
491502
}
492503

493504
func configureProvider(d *schema.ResourceData, terraformVersion string) (interface{}, diag.Diagnostics) {
505+
enableLogging := d.Get("enable_logging").(bool)
506+
if !enableLogging {
507+
// enforce logging (similar to OS_DEBUG) when TF_LOG is 'DEBUG' or 'TRACE'
508+
if logLevel := logging.LogLevel(); logLevel != "" && os.Getenv("OS_DEBUG") == "" {
509+
if logLevel == "DEBUG" || logLevel == "TRACE" {
510+
enableLogging = true
511+
}
512+
}
513+
}
514+
494515
config := Config{
495516
auth.Config{
496517
CACertFile: d.Get("cacert_file").(string),
@@ -526,6 +547,7 @@ func configureProvider(d *schema.ResourceData, terraformVersion string) (interfa
526547
TerraformVersion: terraformVersion,
527548
SDKVersion: meta.SDKVersionString(),
528549
MutexKV: mutexkv.NewMutexKV(),
550+
EnableLogger: enableLogging,
529551
},
530552
}
531553

0 commit comments

Comments
 (0)