Closed luktomaszewski closed 11 months ago
Hi @lomasz, Thanks for reaching out. Could you please provide some more information here, please? Namely:
terraform-local
you are running?Thank you for your help.
Additionally, what do you mean by?
in a Python script designed to parse local Terraform (*.tf) files.
Additionally, what do you mean by?
in a Python script designed to parse local Terraform (*.tf) files.
parse_tf_files()
Hi @lomasz, Thanks for reaching out. Could you please provide some more information here, please? Namely:
- What version of
terraform-local
you are running?Could you please provide the steps to reproduce the above error? As I was unable to on a system with the following versions:
- python: 3.11.5
- terraform: 1.6.4
- terraform-local: 0.16.0
- python-hcl2: 4.3.2
What version of terraform-local you are running?
0.16.0.
I've tried to reproduce on my second machine (both Macbook M1) with the same setup and there this error doesn't occur. 😕
Ok, no problem. Please let me know if you could reproduce the issue and we'll look into it. For the meantime I close this ticket.
I have successfully pinpointed the problem. It stems from a conflict between Python packages. Specifically, the issue was caused by having two distinct hcl2
parsers installed via pip, both sharing the same name. On my system, the bc-python-hcl2
package is installed alongside the checkov
tool.
pip list | grep hcl
--------------------------
bc-python-hcl2 0.4.1
python-hcl2 4.3.2
pip show bc-python-hcl2
--------------------------
Name: bc-python-hcl2
Version: 0.4.1
Summary: A parser for HCL2
Home-page: https://github.com/bridgecrewio/python-hcl2
Author: bridgecrew
Author-email: meet@bridgecrew.io
License: MIT
Location: /opt/homebrew/lib/python3.11/site-packages
Requires: lark
Required-by: checkov
I've encountered an issue with the
parse_tf_files
function in a Python script designed to parse local Terraform (*.tf) files. The function uses thehcl2
library to load and parse the Terraform configuration files. However, the parsed output for certain keys (such as bucket and key in the s3 backend configuration) is returned as lists instead of single string values. This behavior causes problems in subsequent parts of the script, where these values are expected to be strings.Version:
after
configs.update(backend_config)
tflocal#L211get_or_create_bucket(configs["bucket"])
expectsstring
as input tflocal#L308providers.tf
: