prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  GCP: GoogleCloudSqlDatabasePublicallyAccessible raises AttributeError
  # Description
  
  A SQL database instance declared like this crashes the check for publically-accessible instances:
  
  ```hcl
  resource "google_sql_database_instance" "sql_instance" {
    name   = "${var.gcp-project}-db-dev"
    region = "${var.region}"
    settings {
      tier = "${var.db_machine_type}"
      ip_configuration {
                  ipv4_enabled = true
                  authorized_networks {
                  name = "${var.gcp-project}-sql-network"
                  value = google_compute_address.ip_address-dev.address
                  }
    }
   }
  }
  ```
  
  ## Crash Log
  
  ```
  ERROR:checkov.terraform.checks.resource.gcp.GoogleCloudSqlDatabasePublicallyAccessible:Failed to run check: Ensure that Cloud SQL database Instances are not open to the world for configuration: {'name': ['${var.gcp-project}-db-dev'], 'region': ['us-central1'], 'settings': [{'tier': ['${var.db_machine_type}'], 'ip_configuration': [{'ipv4_enabled': [True], 'authorized_networks': [{'name': ['${var.gcp-project}-sql-network'], 'value': ['${google_compute_address.ip_address-dev.address}']}]}]}]} at file: /bcs/modules/aws/prod/cloud-sql.tf
  ```
  
  <details>
  
  ```
  Traceback (most recent call last):
    File "/usr/local/bin/checkov", line 5, in <module>
      run()
    File "/usr/local/lib/python3.8/site-packages/checkov/main.py", line 80, in run
      scan_reports = runner_registry.run(root_folder=root_folder, external_checks_dir=args.external_checks_dir,
    File "/usr/local/lib/python3.8/site-packages/checkov/common/runners/runner_registry.py", line 23, in run
      scan_report = runner.run(root_folder, external_checks_dir=external_checks_dir, files=files,
    File "/usr/local/lib/python3.8/site-packages/checkov/terraform/runner.py", line 48, in run
      self.check_tf_definition(report, root_folder,runner_filter)
    File "/usr/local/lib/python3.8/site-packages/checkov/terraform/runner.py", line 88, in check_tf_definition
      self.run_block(definition[block_type], definitions_context, full_file_path, report, scanned_file,
    File "/usr/local/lib/python3.8/site-packages/checkov/terraform/runner.py", line 110, in run_block
      results = registry.scan(scanned_file, entity, skipped_checks,runner_filter)
    File "/usr/local/lib/python3.8/site-packages/checkov/common/checks/base_check_registry.py", line 64, in scan
      result = self.run_check(check, entity_configuration, entity_name, entity_type, scanned_file, skip_info)
    File "/usr/local/lib/python3.8/site-packages/checkov/common/checks/base_check_registry.py", line 70, in run_check
      result = check.run(scanned_file=scanned_file, entity_configuration=entity_configuration,
    File "/usr/local/lib/python3.8/site-packages/checkov/common/checks/base_check.py", line 44, in run
      raise e
    File "/usr/local/lib/python3.8/site-packages/checkov/common/checks/base_check.py", line 33, in run
      check_result['result'] = self.scan_entity_conf(entity_configuration)
    File "/usr/local/lib/python3.8/site-packages/checkov/terraform/checks/resource/base_resource_check.py", line 20, in scan_entity_conf
      return self.scan_resource_conf(conf)
    File "/usr/local/lib/python3.8/site-packages/checkov/terraform/checks/resource/gcp/GoogleCloudSqlDatabasePublicallyAccessible.py", line 24, in scan_resource_conf
      if 'value' in authorized_network.keys():
  AttributeError: 'str' object has no attribute 'keys'
  ```
  
  </details>
  
  ## System Information
  
   - macOS 10.15.4
  - Python 3.8.2
   - 1.0.308
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `checkov/terraform/checks/resource/gcp/GoogleCloudSqlDatabasePublicallyAccessible.py`
  Content:
  ```
  1 from checkov.terraform.checks.resource.base_resource_check import BaseResourceCheck
  2 from checkov.common.models.enums import CheckResult, CheckCategories
  3 
  4 class GoogleCloudSqlDatabasePublicallyAccessible(BaseResourceCheck):
  5     def __init__(self):
  6         name = "Ensure that Cloud SQL database Instances are not open to the world"
  7         id = "CKV_GCP_11"
  8         supported_resources = ['google_sql_database_instance']
  9         categories = [CheckCategories.NETWORKING]
  10         super().__init__(name=name, id=id, categories=categories, supported_resources=supported_resources)
  11 
  12     def scan_resource_conf(self, conf):
  13         """
  14             Looks for google_sql_database_instance which is open to the world:
  15         :param conf: google_sql_database_instance configuration
  16         :return: <CheckResult>
  17         """
  18         authorized_networks_count = 0
  19         authorized_networks_passed = 0
  20         if 'settings' in conf and 'ip_configuration' in conf['settings'][0]:
  21             if 'authorized_networks' in conf['settings'][0]['ip_configuration'][0].keys():
  22                 authorized_networks_count = len(conf['settings'][0]['ip_configuration'][0]['authorized_networks'][0])
  23                 for authorized_network in conf['settings'][0]['ip_configuration'][0]['authorized_networks'][0]:
  24                     if 'value' in authorized_network.keys():
  25                         if "/0" not in authorized_network['value']:
  26                             authorized_networks_passed += 1
  27 
  28         if authorized_networks_passed == authorized_networks_count:
  29             return CheckResult.PASSED
  30         else: 
  31             return CheckResult.FAILED
  32 
  33 check = GoogleCloudSqlDatabasePublicallyAccessible()
  34
  ```
  
  Path: `checkov/kubernetes/parser/parser.py`
  Content:
  ```
  1 import logging
  2 from yaml import YAMLError
  3 
  4 from checkov.kubernetes.parser import k8_yaml, k8_json
  5 
  6 try:
  7     from json.decoder import JSONDecodeError
  8 except ImportError:
  9     JSONDecodeError = ValueError
  10 
  11 logger = logging.getLogger(__name__)
  12 
  13 
  14 def parse(filename):
  15     template = None
  16     template_lines = None
  17     try:
  18         if filename.endswith(".yaml") or filename.endswith(".yml"):
  19             (template, template_lines) = k8_yaml.load(filename)
  20         if filename.endswith(".json"):
  21             (template, template_lines) = k8_json.load(filename)
  22         if template:
  23             if isinstance(template,list):
  24                 for i in range(len(template)):
  25                     if isinstance(template[i],dict):
  26                         if (not 'apiVersion' in template[i].keys()) and (not 'kind' in template[i].keys()):
  27                             return
  28                     else:
  29                         return
  30             else:
  31                 return
  32         else:
  33             return
  34     except IOError as e:
  35         if e.errno == 2:
  36             logger.error('Template file not found: %s', filename)
  37             return
  38         elif e.errno == 21:
  39             logger.error('Template references a directory, not a file: %s',
  40                          filename)
  41             return
  42         elif e.errno == 13:
  43             logger.error('Permission denied when accessing template file: %s',
  44                          filename)
  45             return
  46     except UnicodeDecodeError as err:
  47         logger.error('Cannot read file contents: %s', filename)
  48         return
  49     except YAMLError as err:
  50         return
  51 
  52     return template, template_lines
  53
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/checkov/kubernetes/parser/parser.py b/checkov/kubernetes/parser/parser.py
  --- a/checkov/kubernetes/parser/parser.py
  +++ b/checkov/kubernetes/parser/parser.py
  @@ -20,10 +20,10 @@
           if filename.endswith(".json"):
               (template, template_lines) = k8_json.load(filename)
           if template:
  -            if isinstance(template,list):
  +            if isinstance(template, list):
                   for i in range(len(template)):
  -                    if isinstance(template[i],dict):
  -                        if (not 'apiVersion' in template[i].keys()) and (not 'kind' in template[i].keys()):
  +                    if isinstance(template[i], dict):
  +                        if not ('apiVersion' in template[i].keys() and 'kind' in template[i].keys()):
                               return
                       else:
                           return
  diff --git a/checkov/terraform/checks/resource/gcp/GoogleCloudSqlDatabasePublicallyAccessible.py b/checkov/terraform/checks/resource/gcp/GoogleCloudSqlDatabasePublicallyAccessible.py
  --- a/checkov/terraform/checks/resource/gcp/GoogleCloudSqlDatabasePublicallyAccessible.py
  +++ b/checkov/terraform/checks/resource/gcp/GoogleCloudSqlDatabasePublicallyAccessible.py
  @@ -21,6 +21,8 @@
               if 'authorized_networks' in conf['settings'][0]['ip_configuration'][0].keys():
                   authorized_networks_count = len(conf['settings'][0]['ip_configuration'][0]['authorized_networks'][0])
                   for authorized_network in conf['settings'][0]['ip_configuration'][0]['authorized_networks'][0]:
  +                    if isinstance(authorized_network, str):
  +                        return CheckResult.UNKNOWN
                       if 'value' in authorized_network.keys():
                           if "/0" not in authorized_network['value']:
                               authorized_networks_passed += 1
  @@ -30,4 +32,5 @@
           else: 
               return CheckResult.FAILED
   
  +
   check = GoogleCloudSqlDatabasePublicallyAccessible()
  
verification_info: {"golden_diff": "diff --git a/checkov/kubernetes/parser/parser.py b/checkov/kubernetes/parser/parser.py\n--- a/checkov/kubernetes/parser/parser.py\n+++ b/checkov/kubernetes/parser/parser.py\n@@ -20,10 +20,10 @@\n         if filename.endswith(\".json\"):\n             (template, template_lines) = k8_json.load(filename)\n         if template:\n-            if isinstance(template,list):\n+            if isinstance(template, list):\n                 for i in range(len(template)):\n-                    if isinstance(template[i],dict):\n-                        if (not 'apiVersion' in template[i].keys()) and (not 'kind' in template[i].keys()):\n+                    if isinstance(template[i], dict):\n+                        if not ('apiVersion' in template[i].keys() and 'kind' in template[i].keys()):\n                             return\n                     else:\n                         return\ndiff --git a/checkov/terraform/checks/resource/gcp/GoogleCloudSqlDatabasePublicallyAccessible.py b/checkov/terraform/checks/resource/gcp/GoogleCloudSqlDatabasePublicallyAccessible.py\n--- a/checkov/terraform/checks/resource/gcp/GoogleCloudSqlDatabasePublicallyAccessible.py\n+++ b/checkov/terraform/checks/resource/gcp/GoogleCloudSqlDatabasePublicallyAccessible.py\n@@ -21,6 +21,8 @@\n             if 'authorized_networks' in conf['settings'][0]['ip_configuration'][0].keys():\n                 authorized_networks_count = len(conf['settings'][0]['ip_configuration'][0]['authorized_networks'][0])\n                 for authorized_network in conf['settings'][0]['ip_configuration'][0]['authorized_networks'][0]:\n+                    if isinstance(authorized_network, str):\n+                        return CheckResult.UNKNOWN\n                     if 'value' in authorized_network.keys():\n                         if \"/0\" not in authorized_network['value']:\n                             authorized_networks_passed += 1\n@@ -30,4 +32,5 @@\n         else: \n             return CheckResult.FAILED\n \n+\n check = GoogleCloudSqlDatabasePublicallyAccessible()\n", "issue": "GCP: GoogleCloudSqlDatabasePublicallyAccessible raises AttributeError\n# Description\r\n\r\nA SQL database instance declared like this crashes the check for publically-accessible instances:\r\n\r\n```hcl\r\nresource \"google_sql_database_instance\" \"sql_instance\" {\r\n  name   = \"${var.gcp-project}-db-dev\"\r\n  region = \"${var.region}\"\r\n  settings {\r\n    tier = \"${var.db_machine_type}\"\r\n    ip_configuration {\r\n                ipv4_enabled = true\r\n                authorized_networks {\r\n                name = \"${var.gcp-project}-sql-network\"\r\n                value = google_compute_address.ip_address-dev.address\r\n                }\r\n  }\r\n }\r\n}\r\n```\r\n\r\n## Crash Log\r\n\r\n```\r\nERROR:checkov.terraform.checks.resource.gcp.GoogleCloudSqlDatabasePublicallyAccessible:Failed to run check: Ensure that Cloud SQL database Instances are not open to the world for configuration: {'name': ['${var.gcp-project}-db-dev'], 'region': ['us-central1'], 'settings': [{'tier': ['${var.db_machine_type}'], 'ip_configuration': [{'ipv4_enabled': [True], 'authorized_networks': [{'name': ['${var.gcp-project}-sql-network'], 'value': ['${google_compute_address.ip_address-dev.address}']}]}]}]} at file: /bcs/modules/aws/prod/cloud-sql.tf\r\n```\r\n\r\n<details>\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"/usr/local/bin/checkov\", line 5, in <module>\r\n    run()\r\n  File \"/usr/local/lib/python3.8/site-packages/checkov/main.py\", line 80, in run\r\n    scan_reports = runner_registry.run(root_folder=root_folder, external_checks_dir=args.external_checks_dir,\r\n  File \"/usr/local/lib/python3.8/site-packages/checkov/common/runners/runner_registry.py\", line 23, in run\r\n    scan_report = runner.run(root_folder, external_checks_dir=external_checks_dir, files=files,\r\n  File \"/usr/local/lib/python3.8/site-packages/checkov/terraform/runner.py\", line 48, in run\r\n    self.check_tf_definition(report, root_folder,runner_filter)\r\n  File \"/usr/local/lib/python3.8/site-packages/checkov/terraform/runner.py\", line 88, in check_tf_definition\r\n    self.run_block(definition[block_type], definitions_context, full_file_path, report, scanned_file,\r\n  File \"/usr/local/lib/python3.8/site-packages/checkov/terraform/runner.py\", line 110, in run_block\r\n    results = registry.scan(scanned_file, entity, skipped_checks,runner_filter)\r\n  File \"/usr/local/lib/python3.8/site-packages/checkov/common/checks/base_check_registry.py\", line 64, in scan\r\n    result = self.run_check(check, entity_configuration, entity_name, entity_type, scanned_file, skip_info)\r\n  File \"/usr/local/lib/python3.8/site-packages/checkov/common/checks/base_check_registry.py\", line 70, in run_check\r\n    result = check.run(scanned_file=scanned_file, entity_configuration=entity_configuration,\r\n  File \"/usr/local/lib/python3.8/site-packages/checkov/common/checks/base_check.py\", line 44, in run\r\n    raise e\r\n  File \"/usr/local/lib/python3.8/site-packages/checkov/common/checks/base_check.py\", line 33, in run\r\n    check_result['result'] = self.scan_entity_conf(entity_configuration)\r\n  File \"/usr/local/lib/python3.8/site-packages/checkov/terraform/checks/resource/base_resource_check.py\", line 20, in scan_entity_conf\r\n    return self.scan_resource_conf(conf)\r\n  File \"/usr/local/lib/python3.8/site-packages/checkov/terraform/checks/resource/gcp/GoogleCloudSqlDatabasePublicallyAccessible.py\", line 24, in scan_resource_conf\r\n    if 'value' in authorized_network.keys():\r\nAttributeError: 'str' object has no attribute 'keys'\r\n```\r\n\r\n</details>\r\n\r\n## System Information\r\n\r\n - macOS 10.15.4\r\n- Python 3.8.2\r\n - 1.0.308\r\n\n", "before_files": [{"content": "from checkov.terraform.checks.resource.base_resource_check import BaseResourceCheck\nfrom checkov.common.models.enums import CheckResult, CheckCategories\n\nclass GoogleCloudSqlDatabasePublicallyAccessible(BaseResourceCheck):\n    def __init__(self):\n        name = \"Ensure that Cloud SQL database Instances are not open to the world\"\n        id = \"CKV_GCP_11\"\n        supported_resources = ['google_sql_database_instance']\n        categories = [CheckCategories.NETWORKING]\n        super().__init__(name=name, id=id, categories=categories, supported_resources=supported_resources)\n\n    def scan_resource_conf(self, conf):\n        \"\"\"\n            Looks for google_sql_database_instance which is open to the world:\n        :param conf: google_sql_database_instance configuration\n        :return: <CheckResult>\n        \"\"\"\n        authorized_networks_count = 0\n        authorized_networks_passed = 0\n        if 'settings' in conf and 'ip_configuration' in conf['settings'][0]:\n            if 'authorized_networks' in conf['settings'][0]['ip_configuration'][0].keys():\n                authorized_networks_count = len(conf['settings'][0]['ip_configuration'][0]['authorized_networks'][0])\n                for authorized_network in conf['settings'][0]['ip_configuration'][0]['authorized_networks'][0]:\n                    if 'value' in authorized_network.keys():\n                        if \"/0\" not in authorized_network['value']:\n                            authorized_networks_passed += 1\n\n        if authorized_networks_passed == authorized_networks_count:\n            return CheckResult.PASSED\n        else: \n            return CheckResult.FAILED\n\ncheck = GoogleCloudSqlDatabasePublicallyAccessible()\n", "path": "checkov/terraform/checks/resource/gcp/GoogleCloudSqlDatabasePublicallyAccessible.py"}, {"content": "import logging\nfrom yaml import YAMLError\n\nfrom checkov.kubernetes.parser import k8_yaml, k8_json\n\ntry:\n    from json.decoder import JSONDecodeError\nexcept ImportError:\n    JSONDecodeError = ValueError\n\nlogger = logging.getLogger(__name__)\n\n\ndef parse(filename):\n    template = None\n    template_lines = None\n    try:\n        if filename.endswith(\".yaml\") or filename.endswith(\".yml\"):\n            (template, template_lines) = k8_yaml.load(filename)\n        if filename.endswith(\".json\"):\n            (template, template_lines) = k8_json.load(filename)\n        if template:\n            if isinstance(template,list):\n                for i in range(len(template)):\n                    if isinstance(template[i],dict):\n                        if (not 'apiVersion' in template[i].keys()) and (not 'kind' in template[i].keys()):\n                            return\n                    else:\n                        return\n            else:\n                return\n        else:\n            return\n    except IOError as e:\n        if e.errno == 2:\n            logger.error('Template file not found: %s', filename)\n            return\n        elif e.errno == 21:\n            logger.error('Template references a directory, not a file: %s',\n                         filename)\n            return\n        elif e.errno == 13:\n            logger.error('Permission denied when accessing template file: %s',\n                         filename)\n            return\n    except UnicodeDecodeError as err:\n        logger.error('Cannot read file contents: %s', filename)\n        return\n    except YAMLError as err:\n        return\n\n    return template, template_lines\n", "path": "checkov/kubernetes/parser/parser.py"}], "after_files": [{"content": "from checkov.terraform.checks.resource.base_resource_check import BaseResourceCheck\nfrom checkov.common.models.enums import CheckResult, CheckCategories\n\nclass GoogleCloudSqlDatabasePublicallyAccessible(BaseResourceCheck):\n    def __init__(self):\n        name = \"Ensure that Cloud SQL database Instances are not open to the world\"\n        id = \"CKV_GCP_11\"\n        supported_resources = ['google_sql_database_instance']\n        categories = [CheckCategories.NETWORKING]\n        super().__init__(name=name, id=id, categories=categories, supported_resources=supported_resources)\n\n    def scan_resource_conf(self, conf):\n        \"\"\"\n            Looks for google_sql_database_instance which is open to the world:\n        :param conf: google_sql_database_instance configuration\n        :return: <CheckResult>\n        \"\"\"\n        authorized_networks_count = 0\n        authorized_networks_passed = 0\n        if 'settings' in conf and 'ip_configuration' in conf['settings'][0]:\n            if 'authorized_networks' in conf['settings'][0]['ip_configuration'][0].keys():\n                authorized_networks_count = len(conf['settings'][0]['ip_configuration'][0]['authorized_networks'][0])\n                for authorized_network in conf['settings'][0]['ip_configuration'][0]['authorized_networks'][0]:\n                    if isinstance(authorized_network, str):\n                        return CheckResult.UNKNOWN\n                    if 'value' in authorized_network.keys():\n                        if \"/0\" not in authorized_network['value']:\n                            authorized_networks_passed += 1\n\n        if authorized_networks_passed == authorized_networks_count:\n            return CheckResult.PASSED\n        else: \n            return CheckResult.FAILED\n\n\ncheck = GoogleCloudSqlDatabasePublicallyAccessible()\n", "path": "checkov/terraform/checks/resource/gcp/GoogleCloudSqlDatabasePublicallyAccessible.py"}, {"content": "import logging\nfrom yaml import YAMLError\n\nfrom checkov.kubernetes.parser import k8_yaml, k8_json\n\ntry:\n    from json.decoder import JSONDecodeError\nexcept ImportError:\n    JSONDecodeError = ValueError\n\nlogger = logging.getLogger(__name__)\n\n\ndef parse(filename):\n    template = None\n    template_lines = None\n    try:\n        if filename.endswith(\".yaml\") or filename.endswith(\".yml\"):\n            (template, template_lines) = k8_yaml.load(filename)\n        if filename.endswith(\".json\"):\n            (template, template_lines) = k8_json.load(filename)\n        if template:\n            if isinstance(template, list):\n                for i in range(len(template)):\n                    if isinstance(template[i], dict):\n                        if not ('apiVersion' in template[i].keys() and 'kind' in template[i].keys()):\n                            return\n                    else:\n                        return\n            else:\n                return\n        else:\n            return\n    except IOError as e:\n        if e.errno == 2:\n            logger.error('Template file not found: %s', filename)\n            return\n        elif e.errno == 21:\n            logger.error('Template references a directory, not a file: %s',\n                         filename)\n            return\n        elif e.errno == 13:\n            logger.error('Permission denied when accessing template file: %s',\n                         filename)\n            return\n    except UnicodeDecodeError as err:\n        logger.error('Cannot read file contents: %s', filename)\n        return\n    except YAMLError as err:\n        return\n\n    return template, template_lines\n", "path": "checkov/kubernetes/parser/parser.py"}]}