hashicorp / hashicorp/terraform-plugin-framework

SDK Framework logs are produced even if not requested

Open
#1,269 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
384
Forks
107
Avg merge
3m
Merged PRs (30d)
1

Description

### Module version
```
github.com/hashicorp/terraform-plugin-framework v1.17.0
```

### Relevant provider source code
```go
I don't think provider code is relevant here
```

### Terraform Configuration Files
```hcl
resource "fmc_access_control_policy" "acp3k" {
name = "ACP 3k"
default_action = "BLOCK"
categories = [
{ name = "cat_A", section = "mandatory" },
{ name = "cat_B", section = "mandatory" },
{ name = "cat_C", section = "mandatory" },
]
rules = [
{ name = "rule_cat_A0001", category_name = "cat_A", action = "ALLOW", source_network_literals = [{ value = "10.0.0.0/24" }], destination_network_literals = [{ value = "10.1.0.0/24" }], enabled = true, log_begin = true, log_end = false, send_events_to_fmc = true, send_syslog = false, variable_set_id = "8f34db96-d3e6-11ef-a0cd-f8151d16ec94", destination_port_literals = [{ port = "1688", protocol = "6", type = "PortLiteral" }] },
//... 2999 more maps like the one above ...
]
}
```

### Debug Output
```
❯ env | grep TF_

❯ terraform init
(... output omitted ...)

❯ command time sh -c 'terraform plan > /dev/null 2>&1'
583.53 real 618.89 user 9.93 sys

❯ TF_LOG_SDK_FRAMEWORK=OFF command time sh -c 'terraform plan > /dev/null 2>&1'
32.01 real 62.29 user 1.86 sys
```

### Expected Behavior
If TF_LOG* variables are not set, no logging should happen

### Actual Behavior
Despite TF_LOG_* variables are not set, the logging engine consumes quite a lot of CPU time
https://gist.githubusercontent.com/rchrabas/fb64d23a3af4984da71c21e765b35e88/raw/15e54f65b2b437dae55635a6b1cf6dcf17505166/pprof_trace_on.svg
Explicitly disabling logging by setting `TF_LOG_SDK_FRAMEWORK=OFF` restores expected behavior.

### My observations
I would expect early exit here: https://github.com/hashicorp/terraform-plugin-log/blob/f7758ee3e0e448601e58d6b2d5d4270f82dbb4cb/tfsdklog/subsystem.go#L110
but since `hclog.Trace` has numeric value of `1`, while `hclog.NoLevel` (which seems to be the default) has numeric value of `0`, then `wouldLog` (https://github.com/hashicorp/terraform-plugin-log/blob/f7758ee3e0e448601e58d6b2d5d4270f82dbb4cb/tfsdklog/levels.go#L78) says True and logs event.
This would also mean that all log levels are processed.

### Steps to Reproduce
1. Have empty state to exclude/limit communication with managed infrastructure
2. `terraform plan` resource with lots of elements inside

### References
N/A

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.