Skip to content

Commit 9d92c3f

Browse files
committed
reduce logging
1 parent dfc658e commit 9d92c3f

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

provisioner/terraform/tfparse/tfextract.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,11 @@ const maxFileSizeBytes = 10 * (10 << 20) // 10 MB
3333
// WorkspaceTags extracts tags from coder_workspace_tags data sources defined in module.
3434
// Note that this only returns the lexical values of the data source, and does not
3535
// evaluate variables and such. To do this, see evalProvisionerTags below.
36-
func WorkspaceTags(ctx context.Context, logger slog.Logger, module *tfconfig.Module) (map[string]string, error) {
36+
func WorkspaceTags(ctx context.Context, module *tfconfig.Module) (map[string]string, error) {
3737
workspaceTags := map[string]string{}
3838

3939
for _, dataResource := range module.DataResources {
4040
if dataResource.Type != "coder_workspace_tags" {
41-
logger.Debug(ctx, "skip resource as it is not a coder_workspace_tags", "resource_name", dataResource.Name, "resource_type", dataResource.Type)
4241
continue
4342
}
4443

@@ -47,7 +46,6 @@ func WorkspaceTags(ctx context.Context, logger slog.Logger, module *tfconfig.Mod
4746
parser := hclparse.NewParser()
4847

4948
if !strings.HasSuffix(dataResource.Pos.Filename, ".tf") {
50-
logger.Debug(ctx, "only .tf files can be parsed", "filename", dataResource.Pos.Filename)
5149
continue
5250
}
5351
// We know in which HCL file is the data resource defined.
@@ -101,8 +99,6 @@ func WorkspaceTags(ctx context.Context, logger slog.Logger, module *tfconfig.Mod
10199
return nil, xerrors.Errorf("can't preview the resource file: %v", err)
102100
}
103101

104-
logger.Info(ctx, "workspace tag found", "key", key, "value", value)
105-
106102
if _, ok := workspaceTags[key]; ok {
107103
return nil, xerrors.Errorf(`workspace tag %q is defined multiple times`, key)
108104
}
@@ -135,14 +131,14 @@ func WorkspaceTagDefaultsFromFile(ctx context.Context, logger slog.Logger, file
135131

136132
// This only gets us the expressions. We need to evaluate them.
137133
// Example: var.region -> "us"
138-
tags, err = WorkspaceTags(ctx, logger, module)
134+
tags, err = WorkspaceTags(ctx, module)
139135
if err != nil {
140136
return nil, xerrors.Errorf("extract workspace tags: %w", err)
141137
}
142138

143-
// To evalute the expressions, we need to load the default values for
139+
// To evaluate the expressions, we need to load the default values for
144140
// variables and parameters.
145-
varsDefaults, paramsDefaults, err := loadDefaults(ctx, logger, module)
141+
varsDefaults, paramsDefaults, err := loadDefaults(module)
146142
if err != nil {
147143
return nil, xerrors.Errorf("load defaults: %w", err)
148144
}
@@ -162,6 +158,8 @@ func WorkspaceTagDefaultsFromFile(ctx context.Context, logger slog.Logger, file
162158
}
163159
return nil, xerrors.Errorf("provisioner tag %q evaluated to an empty value, please set a default value", k)
164160
}
161+
logger.Info(ctx, "found workspace tags", slog.F("tags", evalTags))
162+
165163
return evalTags, nil
166164
}
167165

@@ -209,7 +207,7 @@ func loadModuleFromFile(file []byte, mimetype string) (module *tfconfig.Module,
209207

210208
// loadDefaults inspects the given module and returns the default values for
211209
// all variables and coder_parameter data sources referenced there.
212-
func loadDefaults(ctx context.Context, logger slog.Logger, module *tfconfig.Module) (varsDefaults map[string]string, paramsDefaults map[string]string, err error) {
210+
func loadDefaults(module *tfconfig.Module) (varsDefaults map[string]string, paramsDefaults map[string]string, err error) {
213211
// iterate through module.Variables to get the default values for all
214212
// variables.
215213
varsDefaults = make(map[string]string)
@@ -226,15 +224,14 @@ func loadDefaults(ctx context.Context, logger slog.Logger, module *tfconfig.Modu
226224
paramsDefaults = make(map[string]string)
227225
for _, dataResource := range module.DataResources {
228226
if dataResource.Type != "coder_parameter" {
229-
logger.Debug(ctx, "skip resource as it is not a coder_parameter", "resource_name", dataResource.Name, "resource_type", dataResource.Type)
227+
continue
230228
}
231229

232230
var file *hcl.File
233231
var diags hcl.Diagnostics
234232
parser := hclparse.NewParser()
235233

236234
if !strings.HasSuffix(dataResource.Pos.Filename, ".tf") {
237-
logger.Debug(ctx, "only .tf files can be parsed", "filename", dataResource.Pos.Filename)
238235
continue
239236
}
240237

0 commit comments

Comments
 (0)