question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

<string>:1: SyntaxWarning: list indices must be integers or slices, not str; perhaps you missed a comma?

See original GitHub issue

Describe the bug We get the syntax error above when running checkov against certain directories:

image

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:

  1. 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:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
tronxdcommented, May 10, 2021

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

0reactions
schosterbarakcommented, May 10, 2021

fixed. thanks @tronxd

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found