diff --git a/controller/driver_factory_test.go b/controller/driver_factory_test.go index a9abdc8a6..5a8acb14f 100644 --- a/controller/driver_factory_test.go +++ b/controller/driver_factory_test.go @@ -356,7 +356,7 @@ func TestNewDriverTask(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - tc.conf.Finalize() + _ = tc.conf.Finalize() var providerConfigs []driver.TerraformProviderBlock if tc.conf != nil && tc.conf.TerraformProviders != nil { diff --git a/driver/task.go b/driver/task.go index 55f7c3e84..efdac3077 100644 --- a/driver/task.go +++ b/driver/task.go @@ -22,6 +22,8 @@ const ( RunOptionInspect = "inspect" ) +var logger = logging.Global().Named(logSystemName) + // PatchTask holds the information to patch update a task. It will only include // fields that we support updating at this time type PatchTask struct { @@ -67,7 +69,6 @@ type Task struct { condition config.ConditionConfig moduleInputs config.ModuleInputConfigs workingDir string - logger logging.Logger // Enterprise deprecatedTFVersion string @@ -138,7 +139,6 @@ func NewTask(conf TaskConfig) (*Task, error) { condition: conf.Condition, moduleInputs: conf.ModuleInputs, workingDir: conf.WorkingDir, - logger: logging.Global().Named(logSystemName), // Enterprise deprecatedTFVersion: conf.DeprecatedTFVersion, @@ -225,7 +225,7 @@ func (t *Task) Env() map[string]string { return env } -// ProviderNames returns the list of providers that the task has configured +// Providers returns the list of providers that the task has configured func (t *Task) Providers() TerraformProviderBlocks { t.mu.RLock() defer t.mu.RUnlock() @@ -372,7 +372,7 @@ func (t *Task) configureRootModuleInput(input *tftmpl.RootModuleInputData) error } templates = append(templates, template) - t.logger.Trace("services list template configured", "template_type", + logger.Trace("services list template configured", "template_type", fmt.Sprintf("%T", template)) } @@ -419,7 +419,7 @@ func (t *Task) configureRootModuleInput(input *tftmpl.RootModuleInputData) error if condition != nil { templates = append(templates, condition) - t.logger.Trace("condition block template configured", "template_type", + logger.Trace("condition block template configured", "template_type", fmt.Sprintf("%T", condition)) } @@ -464,9 +464,10 @@ func (t *Task) configureRootModuleInput(input *tftmpl.RootModuleInputData) error // store the newly created template's type for logging tmplTypes[ix] = fmt.Sprintf("%T", moduleInputs[ix]) } + if len(moduleInputs) > 0 { templates = append(templates, moduleInputs...) - t.logger.Trace("module_input block(s) template configured", + logger.Trace("module_input block(s) template configured", "template_types", strings.Join(tmplTypes, ", ")) } diff --git a/driver/task_test.go b/driver/task_test.go index 11cbe2c1c..fafeb0d9c 100644 --- a/driver/task_test.go +++ b/driver/task_test.go @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/consul-terraform-sync/client" "github.com/hashicorp/consul-terraform-sync/config" - "github.com/hashicorp/consul-terraform-sync/logging" mocks "github.com/hashicorp/consul-terraform-sync/mocks/client" "github.com/hashicorp/consul-terraform-sync/templates/hcltmpl" "github.com/hashicorp/consul-terraform-sync/templates/tftmpl" @@ -595,8 +594,6 @@ func TestTask_configureRootModuleInput(t *testing.T) { for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { - tc.task.logger = logging.NewNullLogger() - input := &tftmpl.RootModuleInputData{} err := tc.task.configureRootModuleInput(input) assert.NoError(t, err) diff --git a/driver/terraform_test.go b/driver/terraform_test.go index cf7fb3c21..f9acb1e30 100644 --- a/driver/terraform_test.go +++ b/driver/terraform_test.go @@ -90,7 +90,7 @@ func TestRenderTemplate(t *testing.T) { tmpl.On("Render", mock.Anything).Return(hcat.RenderResult{}, tc.renderErr).Once() tf := &Terraform{ - task: &Task{name: "RenderTemplateTest", enabled: true, logger: logging.NewNullLogger()}, + task: &Task{name: "RenderTemplateTest", enabled: true}, resolver: r, template: tmpl, watcher: new(mocksTmpl.Watcher), @@ -199,7 +199,7 @@ func TestApplyTask(t *testing.T) { c.On("Apply", ctx).Return(tc.applyReturn).Once() tf := &Terraform{ - task: &Task{name: "ApplyTaskTest", enabled: true, logger: logging.NewNullLogger()}, + task: &Task{name: "ApplyTaskTest", enabled: true}, client: c, postApply: tc.postApply, logger: logging.NewNullLogger(), @@ -316,8 +316,7 @@ func TestUpdateTask(t *testing.T) { w.On("Register", mock.Anything).Return(nil).Once() w.On("Clients").Return(nil).Once() tf := &Terraform{ - task: &Task{name: "test_task", enabled: tc.orig.Enabled, workingDir: tc.dirName, - logger: logging.NewNullLogger()}, + task: &Task{name: "test_task", enabled: tc.orig.Enabled, workingDir: tc.dirName}, client: c, resolver: r, watcher: w, @@ -425,8 +424,7 @@ func TestUpdateTask(t *testing.T) { w.On("Clients").Return(nil).Once() tf := &Terraform{ - task: &Task{name: "test_task", enabled: false, workingDir: tc.dirName, - logger: logging.NewNullLogger()}, + task: &Task{name: "test_task", enabled: false, workingDir: tc.dirName}, client: c, resolver: r, watcher: w, @@ -510,13 +508,11 @@ func TestUpdateTask_Inspect(t *testing.T) { // set some fields on task tc.name = "task_a" - tc.task.logger = logging.NewNullLogger() tc.task.workingDir = workingDir copyTask := &Task{ name: tc.task.Name(), enabled: tc.task.IsEnabled(), - logger: tc.task.logger, workingDir: tc.task.workingDir, } @@ -547,7 +543,6 @@ func TestSetBufferPeriod(t *testing.T) { Min: 2 * time.Second, Max: 5 * time.Second, }, - logger: logging.NewNullLogger(), }, }, { @@ -556,7 +551,6 @@ func TestSetBufferPeriod(t *testing.T) { &Task{ enabled: false, name: "disabled_task", - logger: logging.NewNullLogger(), }, }, { @@ -565,7 +559,6 @@ func TestSetBufferPeriod(t *testing.T) { &Task{ enabled: true, name: "no_buf_period_task", - logger: logging.NewNullLogger(), }, }, { @@ -574,7 +567,6 @@ func TestSetBufferPeriod(t *testing.T) { &Task{ enabled: true, name: "task_a", - logger: logging.NewNullLogger(), }, }, } @@ -733,8 +725,7 @@ func TestDisabledTask(t *testing.T) { defer deleteTemp() tf := &Terraform{ - task: &Task{name: "disabled_task", enabled: false, - workingDir: dirName, logger: logging.NewNullLogger()}, + task: &Task{name: "disabled_task", enabled: false, workingDir: dirName}, client: c, fileReader: func(string) ([]byte, error) { return []byte{}, nil }, watcher: w, @@ -819,7 +810,7 @@ func TestInitTask(t *testing.T) { w.On("Register", mock.Anything).Return(nil).Once() tf := &Terraform{ - task: &Task{name: "InitTaskTest", enabled: true, workingDir: dirName, logger: logging.NewNullLogger(), module: tc.module}, + task: &Task{name: "InitTaskTest", enabled: true, workingDir: dirName, module: tc.module}, client: c, fileReader: func(string) ([]byte, error) { return []byte{}, nil }, watcher: w, diff --git a/go.mod b/go.mod index 7d58b31af..8d2753716 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,6 @@ require ( github.com/agext/levenshtein v1.2.3 // indirect github.com/aws/aws-sdk-go v1.37.19 // indirect github.com/deepmap/oapi-codegen v1.11.0 - github.com/fatih/color v1.10.0 // indirect github.com/getkin/kin-openapi v0.94.0 github.com/go-chi/chi/v5 v5.0.7 github.com/go-test/deep v1.0.7 // indirect @@ -21,7 +20,7 @@ require ( github.com/hashicorp/go-bexpr v0.1.4 github.com/hashicorp/go-checkpoint v0.5.0 github.com/hashicorp/go-getter v1.6.1 - github.com/hashicorp/go-hclog v0.16.2 + github.com/hashicorp/go-hclog v1.2.1 github.com/hashicorp/go-retryablehttp v0.7.0 // indirect github.com/hashicorp/go-rootcerts v1.0.2 github.com/hashicorp/go-syslog v1.0.0 @@ -47,14 +46,10 @@ require ( github.com/pkg/errors v0.9.1 github.com/posener/complete v1.2.3 github.com/stretchr/objx v0.3.0 // indirect - github.com/stretchr/testify v1.7.1 + github.com/stretchr/testify v1.7.2 github.com/ulikunitz/xz v0.5.10 // indirect github.com/zclconf/go-cty v1.10.0 go.opencensus.io v0.22.6 // indirect golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93 // indirect google.golang.org/genproto v0.0.0-20210222212404-3e1e516060db // indirect - - // v3.0 has a CVE. Force dependencies github.com/deepmap/oapi-codegen to - // use latest version of go-yaml - gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 2ee962e6e..ea158afcd 100644 --- a/go.sum +++ b/go.sum @@ -128,8 +128,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/evanphx/json-patch/v5 v5.5.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= -github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= -github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= +github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= +github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= @@ -292,8 +292,9 @@ github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrj github.com/hashicorp/go-hclog v0.12.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= github.com/hashicorp/go-hclog v0.12.2/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= -github.com/hashicorp/go-hclog v0.16.2 h1:K4ev2ib4LdQETX5cSZBG0DVLk1jwGqSPXBjdah3veNs= github.com/hashicorp/go-hclog v0.16.2/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= +github.com/hashicorp/go-hclog v1.2.1 h1:YQsLlGDJgwhXFpucSPyVbCBviQtjlHv3jLTlp8YmtEw= +github.com/hashicorp/go-hclog v1.2.1/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-immutable-radix v1.2.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc= @@ -458,7 +459,7 @@ github.com/matryer/moq v0.2.7/go.mod h1:kITsx543GOENm48TUAQyJ9+SAvFSr7iGQXPoth/V github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= @@ -575,8 +576,9 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= +github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M= @@ -806,6 +808,7 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220513210249-45d2b4557a2a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220517195934-5e4e11fc645e h1:w36l2Uw3dRan1K3TyXriXvY+6T56GNmlKGcqiQUJDfM= golang.org/x/sys v0.0.0-20220517195934-5e4e11fc645e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=