Skip to content
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

fix(terraform): fix gke resource name not string #3811

Merged
merged 1 commit into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ def scan_resource_conf(self, conf):
:param conf: google_compute_instance configuration
:return: <CheckResult>
"""
if 'name' in conf and conf['name'][0].startswith('gke-'):
self.evaluated_keys = ['name']
return CheckResult.PASSED

if 'name' in conf:
if not isinstance(conf['name'][0], str):
return CheckResult.UNKNOWN
if conf['name'][0].startswith('gke-'):
self.evaluated_keys = ['name']
return CheckResult.PASSED

if 'source_instance_template' in conf.keys() and 'service_account' not in conf.keys():
# if the source_instance_template value is there (indicating a google_compute_instance_from_template),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def get_excluded_key(self):
return "name"

def check_excluded_condition(self, value):
if not isinstance(value, str):
return False
return value.startswith('gke-')


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ def test_unknown(self):
resource_conf = hcl_res['resource'][0]['google_compute_instance_from_template']['default']
scan_result = check.scan_resource_conf(conf=resource_conf)
self.assertEqual(CheckResult.UNKNOWN, scan_result)

def test_unknown2(self):
hcl_res = hcl2.loads("""
resource "google_compute_instance_from_template" "default" {
name = {}
source_instance_template = google_compute_instance_template.tpl.id
}
""")
resource_conf = hcl_res['resource'][0]['google_compute_instance_from_template']['default']
scan_result = check.scan_resource_conf(conf=resource_conf)
self.assertEqual(CheckResult.UNKNOWN, scan_result)


if __name__ == '__main__':
Expand Down