<string>:1: SyntaxWarning: list indices must be integers or slices, not str; perhaps you missed a comma?
See original GitHub issueDescribe the bug We get the syntax error above when running checkov against certain directories:
I’ve narrowed this down to being caused by .auto.tfvars, this is the example config:
iam_bindings.tf
resource "google_project_iam_member" "gcp_devs" {
for_each = toset(var.gcp_devs_bindings["roles"])
role = each.value
member = var.gcp_devs_bindings["member"]
}
variable "gcp_devs_bindings" {}
iam_bindings.auto.tfvars
gcp_devs_bindings = {
member = "group:gcp-devs@loveholidays.com",
roles = [
"roles/viewer",
"roles/bigquery.admin",
"roles/cloudscheduler.admin",
"roles/container.clusterAdmin",
"roles/run.admin",
"roles/storagetransfer.user",
"roles/automl.admin",
"roles/cloudsql.admin",
"roles/cloudtasks.admin",
"roles/composer.admin",
"roles/compute.admin",
"roles/cloudscheduler.jobRunner",
"roles/serviceusage.apiKeysAdmin",
]
}
If I replace the auto.tfvars file with locals, the error goes away.
To Reproduce Steps to reproduce the behavior:
- Run checkov against the above code.
Expected behavior No error, or more concise where the error is coming from.
Desktop (please complete the following information):
- OS: os X
- Checkov Version 2.0.77
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Why does Python log a SyntaxWarning saying “list indices ...
example.py:3: SyntaxWarning: list indices must be integers or slices, not tuple; perhaps you missed a comma? ["egg", "spam"].
Read more >TypeError: list indices must be integers or slices, not str
First, array_length should be an integer and not a string: array_length = len(array_dates). Second, your for loop should be constructed ...
Read more >TypeError: list indices must be integers or slices ... - STechies
This position is defined by an index. These indexes are always defined using integers. You might declare a variable that has the index...
Read more >TypeError: list indices must be integers or slices, not str
This error occurs when using a string for list indexing instead of indices or slices. For a better understanding of list indexing, see...
Read more >TypeError: list indices must be integers or slices, not str
The Python "TypeError: list indices must be integers or slices, not str" occurs when we use a string instead of an integer to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @dwilliams782 @zachpetersen the issue is verified to be at Python versions 3.8+ I will create a PR that suppress the warning and the issue will be resolved
fixed. thanks @tronxd