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): gcp postgresql default values #3457

Merged
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 @@ -34,13 +34,13 @@ def scan_resource_conf(self, conf: dict[str, list[Any]]) -> CheckResult:
else: # treating use cases of the following database_flags parsing (list of dictionaries with arrays): 'database_flags': [{'name': ['<key>'], 'value': ['<value>']},{'name': ['<key>'], 'value': ['<value>']}]
flags = [{key: flag[key][0] for key in flag} for flag in flags]
for flag in flags:
if (flag['name'] == 'log_checkpoints') and (flag['value'] == 'off'):
if (flag['name'] == 'log_checkpoints') and (flag['value'] == 'on'): # Must be explicitly set for check to pass
self.evaluated_keys = ['database_version/[0]/POSTGRES',
f'{evaluated_keys_prefix}/[{flags.index(flag)}]/name',
f'{evaluated_keys_prefix}/[{flags.index(flag)}]/value']
return CheckResult.FAILED
return CheckResult.PASSED
self.evaluated_keys = ['database_version/[0]/POSTGRES', 'settings/[0]/database_flags']
return CheckResult.PASSED
return CheckResult.FAILED
return CheckResult.UNKNOWN


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ def scan_resource_conf(self, conf):
else: # treating use cases of the following database_flags parsing (list of dictionaries with arrays): 'database_flags': [{'name': ['<key>'], 'value': ['<value>']},{'name': ['<key>'], 'value': ['<value>']}]
flags = [{key: flag[key][0] for key in flag} for flag in flags]
for flag in flags:
if (flag['name'] == 'log_connections') and (flag['value'] == 'off'):
if (flag['name'] == 'log_connections') and (flag['value'] == 'on'): # Must be explicitly set for check to pass
self.evaluated_keys = ['database_version/[0]/POSTGRES',
f'{evaluated_keys_prefix}/[{flags.index(flag)}]/name',
f'{evaluated_keys_prefix}/[{flags.index(flag)}]/value']
return CheckResult.FAILED
return CheckResult.PASSED
self.evaluated_keys = ['database_version/[0]/POSTGRES', 'settings/[0]/database_flags']

return CheckResult.PASSED
return CheckResult.FAILED
return CheckResult.UNKNOWN


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ def scan_resource_conf(self, conf):
# [{'name': ['<key>'], 'value': ['<value>']},{'name': ['<key>'], 'value': ['<value>']}]
flags = [{key: flag[key][0] for key in flag} for flag in flags]
for flag in flags:
if (flag['name'] == 'log_disconnections') and (flag['value'] == 'off'):
if (flag['name'] == 'log_disconnections') and (flag['value'] == 'on'): # Must be explicitly set for check to pass
self.evaluated_keys = ['database_version/[0]/POSTGRES',
f'{evaluated_keys_prefix}/[{flags.index(flag)}]/name',
f'{evaluated_keys_prefix}/[{flags.index(flag)}]/value']
return CheckResult.FAILED
return CheckResult.PASSED
self.evaluated_keys = ['database_version/[0]/POSTGRES', 'settings/[0]/database_flags']

return CheckResult.PASSED
return CheckResult.FAILED
return CheckResult.UNKNOWN


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ def scan_resource_conf(self, conf):
# [{'name': ['<key>'], 'value': ['<value>']},{'name': ['<key>'], 'value': ['<value>']}]
flags = [{key: flag[key][0] for key in flag} for flag in flags]
for flag in flags:
if (flag['name'] == 'log_lock_waits') and (flag['value'] == 'off'):
if (flag['name'] == 'log_lock_waits') and (flag['value'] == 'on'): # Must be explicitly set for check to pass
self.evaluated_keys = ['database_version/[0]/POSTGRES',
f'{evaluated_keys_prefix}/[{flags.index(flag)}]/name',
f'{evaluated_keys_prefix}/[{flags.index(flag)}]/value']
return CheckResult.FAILED
return CheckResult.PASSED
self.evaluated_keys = ['database_version/[0]/POSTGRES', 'settings/[0]/database_flags']

return CheckResult.PASSED
return CheckResult.FAILED
return CheckResult.UNKNOWN


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,49 +41,7 @@ resource "google_sql_database_instance" "fail" {
}
}

resource "google_sql_database_instance" "pass3" {
database_version = "POSTGRES_12"
name = "general-pos121"
project = "gcp-bridgecrew-deployment"
region = "us-central1"
settings {
activation_policy = "ALWAYS"
availability_type = "ZONAL"
database_flags {
name = "log_checkpoints"
value = "off"
}
database_flags {
name = "log_connections"
value = "on"
}
database_flags {
name = "log_disconnections"
value = "on"
}
database_flags {
name = "log_min_messages"
value = "debug6"
}
database_flags {
name = "log_lock_waits"
value = "on"
}
database_flags {
name = "log_temp_files"
value = "10"
}
database_flags {
name = "log_min_duration_statement"
value = "1"
}
pricing_plan = "PER_USE"

tier = "db-custom-1-3840"
}
}

resource "google_sql_database_instance" "pass2" {
resource "google_sql_database_instance" "fail2" {
database_version = "POSTGRES_14"
name = "general-pos121"
project = "gcp-bridgecrew-deployment"
Expand All @@ -99,10 +57,6 @@ resource "google_sql_database_instance" "pass2" {
name = "log_connections"
value = "off"
}
database_flags {
name = "log_disconnections"
value = "on"
}
database_flags {
name = "log_min_messages"
value = "debug6"
Expand Down Expand Up @@ -134,6 +88,10 @@ resource "google_sql_database_instance" "pass" {
settings {
activation_policy = "ALWAYS"
availability_type = "ZONAL"
database_flags {
name = "log_disconnections"
value = "on"
}
database_flags {
name = "log_min_messages"
value = "debug6"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ resource "google_sql_database_instance" "fail" {
}
}

resource "google_sql_database_instance" "pass2" {
resource "google_sql_database_instance" "fail2" {
database_version = "POSTGRES_12"
name = "general-pos121"
project = "gcp-bridgecrew-deployment"
Expand All @@ -65,10 +65,6 @@ resource "google_sql_database_instance" "pass2" {
name = "log_min_messages"
value = "debug6"
}
database_flags {
name = "log_lock_waits"
value = "on"
}
database_flags {
name = "log_temp_files"
value = "10"
Expand All @@ -91,6 +87,10 @@ resource "google_sql_database_instance" "pass" {
settings {
activation_policy = "ALWAYS"
availability_type = "ZONAL"
database_flags {
name = "log_lock_waits"
value = "on"
}
database_flags {
name = "log_min_messages"
value = "debug6"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,14 @@ resource "google_sql_database_instance" "fail" {
}


resource "google_sql_database_instance" "pass2" {
resource "google_sql_database_instance" "fail2" {
database_version = "POSTGRES_12"
name = "general-pos121"
project = "gcp-bridgecrew-deployment"
region = "us-central1"
settings {
activation_policy = "ALWAYS"
availability_type = "ZONAL"
database_flags {
name = "log_checkpoints"
value = "on"
}
database_flags {
name = "log_connections"
value = "on"
Expand Down Expand Up @@ -92,6 +88,10 @@ resource "google_sql_database_instance" "pass" {
settings {
activation_policy = "ALWAYS"
availability_type = "ZONAL"
database_flags {
name = "log_checkpoints"
value = "on"
}
database_flags {
name = "log_disconnections"
value = "on"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ resource "google_sql_database_instance" "fail" {
}


resource "google_sql_database_instance" "pass2" {
resource "google_sql_database_instance" "fail2" {
database_version = "POSTGRES_12"
name = "general-pos121"
project = "gcp-bridgecrew-deployment"
Expand All @@ -55,10 +55,6 @@ resource "google_sql_database_instance" "pass2" {
name = "log_checkpoints"
value = "off"
}
database_flags {
name = "log_connections"
value = "on"
}
database_flags {
name = "log_disconnections"
value = "on"
Expand Down Expand Up @@ -92,6 +88,10 @@ resource "google_sql_database_instance" "pass" {
settings {
activation_policy = "ALWAYS"
availability_type = "ZONAL"
database_flags {
name = "log_connections"
value = "on"
}
database_flags {
name = "log_disconnections"
value = "on"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ def test(self):

passing_resources = {
"google_sql_database_instance.pass",
"google_sql_database_instance.pass2",
}

failing_resources = {
"google_sql_database_instance.fail",
"google_sql_database_instance.fail2",
}

passed_check_resources = {c.resource for c in report.passed_checks}
failed_check_resources = {c.resource for c in report.failed_checks}

self.assertEqual(summary["passed"], 2)
self.assertEqual(summary["failed"], 1)
self.assertEqual(summary["passed"], 1)
self.assertEqual(summary["failed"], 2)
self.assertEqual(summary["skipped"], 0)
self.assertEqual(summary["parsing_errors"], 0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ def test(self):

passing_resources = {
"google_sql_database_instance.pass",
"google_sql_database_instance.pass2",
}

failing_resources = {
"google_sql_database_instance.fail",
"google_sql_database_instance.fail2",
}

passed_check_resources = {c.resource for c in report.passed_checks}
failed_check_resources = {c.resource for c in report.failed_checks}

self.assertEqual(summary["passed"], 2)
self.assertEqual(summary["failed"], 1)
self.assertEqual(summary["passed"], 1)
self.assertEqual(summary["failed"], 2)
self.assertEqual(summary["skipped"], 0)
self.assertEqual(summary["parsing_errors"], 0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@ def test(self):

passing_resources = {
"google_sql_database_instance.pass",
"google_sql_database_instance.pass2",
"google_sql_database_instance.pass3",
}

failing_resources = {
"google_sql_database_instance.fail",
"google_sql_database_instance.fail2",
}

passed_check_resources = {c.resource for c in report.passed_checks}
failed_check_resources = {c.resource for c in report.failed_checks}

self.assertEqual(summary["passed"], 3)
self.assertEqual(summary["failed"], 1)
self.assertEqual(summary["passed"], 1)
self.assertEqual(summary["failed"], 2)
self.assertEqual(summary["skipped"], 0)
self.assertEqual(summary["parsing_errors"], 0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ def test(self):

passing_resources = {
"google_sql_database_instance.pass",
"google_sql_database_instance.pass2",
}

failing_resources = {
"google_sql_database_instance.fail",
"google_sql_database_instance.fail2",
}

passed_check_resources = {c.resource for c in report.passed_checks}
failed_check_resources = {c.resource for c in report.failed_checks}

self.assertEqual(summary["passed"], 2)
self.assertEqual(summary["failed"], 1)
self.assertEqual(summary["passed"], 1)
self.assertEqual(summary["failed"], 2)
self.assertEqual(summary["skipped"], 0)
self.assertEqual(summary["parsing_errors"], 0)

Expand Down