-
Notifications
You must be signed in to change notification settings - Fork 232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
helper/resource: Add TF_ACC_LOG
, TF_LOG_CORE
, and TF_LOG_PROVIDER
environment variable handling for Terraform versions 0.15 and later
#993
Conversation
…erraform during acceptance testing on versions 0.15 and later Reference: hashicorp/terraform-exec#291 Reference: #992 This allows the acceptance testing framework to appropriately set the `TF_LOG` environment variable via `terraform-exec`, if Terraform is version 0.15 or later. Otherwise, defaults to `TRACE` similar to before when `TF_ACC_LOG_PATH` or `TF_LOG_PATH_MASK` environment variables are set.
TF_LOG
environment variable passthrough to Terraform during acceptance testing on versions 0.15 and laterTF_ACC_LOG
, TF_LOG_CORE
, and TF_LOG_PROVIDER
environment variable handling for Terraform versions 0.15 and later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some typos, LGTM
Co-authored-by: Ivan De Marino <[email protected]>
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
Closes #992
This enables provider developers to have full control over Terraform CLI logging environment variables with the acceptance testing framework in
helper/resource
.In Terraform CLI 0.15 and later, the logging environment variables work as the following:
TF_LOG
TF_LOG_CORE
(but notTF_LOG_PROVIDER
) if set.TF_LOG_CORE
TF_LOG
is set.TF_LOG_PROVIDER
To execute Terraform CLI during acceptance testing, it uses
terraform-exec
for all interactions.terraform-exec
has certain environment variable handling rules associated with it, to prevent issues with reading stdout/stderr output from calling Terraform CLI since it needs to be able to parse that information. It was recently updated to support settingTF_LOG
,TF_LOG_CORE
, andTF_LOG_PROVIDER
environment variables when calling Terraform, in addition to the prior support for settingTF_LOG_PATH
, which defaults to always settingTF_LOG
toTRACE
if unset.This enhancement allows the acceptance testing framework to accept the
TF_ACC_LOG
environment variable to appropriately set theTF_LOG
environment variable interraform-exec
, if Terraform is version 0.15 or later. We could not change the behavior of the existingTF_LOG
environment variable as it would cause undesirable side effects with the existing testing framework handling for the Go standard librarylog
package. TheTF_ACC_LOG
naming follows the convention ofTF_ACC_LOG_PATH
settingTF_LOG_PATH
. TheTF_LOG
value defaults toTRACE
, similar to before, whenTF_ACC_LOG_PATH
orTF_LOG_PATH_MASK
environment variables are set.This also enables the passthrough of
TF_LOG_CORE
andTF_LOG_PROVIDER
environment variables toterraform-exec
. This is required becauseterraform-exec
will otherwise defaultTF_LOG
toTRACE
ifTF_LOG_PATH
is used, meaning that without this, provider developers could not disable Terraform core logging. This enhancement opts to not prefix the variables withTF_ACC_
as there's no prior behaviors to protect and the differing environment variable names for acceptance testing is already confusing enough for everyone. They could still be prefixed for consistency withTF_ACC_LOG
though, if desired.To summarize the state of logging environment variable with the acceptance testing framework after this change:
TF_ACC_LOG
TF_LOG
environment variableTF_ACC_LOG_PATH
TF_LOG_PATH
environment variable and where terraform-plugin-log SDK/provider loggers will write logsTF_LOG
log
package log level; Any level enables terraform-plugin-log SDK/provider loggers atTRACE
currently (they have to be tuned down individually at the moment)TF_LOG_CORE
TF_LOG_CORE
environment variableTF_LOG_PATH_MASK
TF_ACC_LOG_PATH
, but replaces a%s
placeholder in the value with individual test names ((testing.T).Name()
)TF_LOG_PROVIDER
TF_LOG_PROVIDER
environment variable