Skip to content

Commit

Permalink
feat: DEVOP-4544| Remove the deprecated attributes from terraform-gcp…
Browse files Browse the repository at this point in the history
…-sql component module (#45)
  • Loading branch information
bibek4699 authored Jul 9, 2024
1 parent 2e73d11 commit b88a263
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 39 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.91.0 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases
rev: v1.92.0 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases
hooks:
- id: terraform_fmt
- id: terraform_docs
Expand All @@ -24,7 +24,7 @@ repos:
- id: terraform_checkov
exclude: (test/|examples/)
- repo: https://github.com/gitguardian/ggshield
rev: v1.28.0 # Update to latest version by running `pre-commit autoupdate`
rev: v1.29.0 # Update to latest version by running `pre-commit autoupdate`
hooks:
- id: ggshield
language: python
Expand Down
2 changes: 1 addition & 1 deletion examples/create_mysql_instance_with_private_ip/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module "test_sql_database_instance_private_ip" {
settings_backup_configuration_enabled = var.settings_backup_configuration_enabled
settings_ip_configuration_ipv4_enabled = false
settings_ip_configuration_private_network = module.google_compute_network_private_network.id
settings_ip_configuration_require_ssl = var.settings_ip_configuration_require_ssl
settings_ip_configuration_ssl_mode = var.settings_ip_configuration_ssl_mode
settings_tier = var.settings_tier
deletion_protection = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ variable "settings_backup_configuration_binary_log_enabled" {
default = true
}

variable "settings_ip_configuration_require_ssl" {
description = "(Optional) Whether SSL connections over IP are enforced or not."
type = bool
default = true
variable "settings_ip_configuration_ssl_mode" {
description = " (Optional) Specify how SSL connection should be enforced in DB connections."
type = string
default = "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ settings_disk_size = 10
settings_disk_type = "PD_SSD"
settings_backup_configuration_enabled = true
settings_backup_configuration_binary_log_enabled = true
settings_ip_configuration_require_ssl = true
2 changes: 1 addition & 1 deletion examples/create_mysql_instance_with_public_ip/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module "test_sql_database_instance" {
settings_backup_configuration_enabled = var.settings_backup_configuration_enabled
settings_ip_configuration_ipv4_enabled = var.settings_ip_configuration_ipv4_enabled
settings_ip_configuration_private_network = var.settings_ip_configuration_private_network
settings_ip_configuration_require_ssl = var.settings_ip_configuration_require_ssl
settings_ip_configuration_ssl_mode = var.settings_ip_configuration_ssl_mode
settings_tier = var.settings_tier
deletion_protection = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ variable "settings_backup_configuration_binary_log_enabled" {
default = true
}

variable "settings_ip_configuration_require_ssl" {
description = "(Optional) Whether SSL connections over IP are enforced or not."
type = bool
default = true
variable "settings_ip_configuration_ssl_mode" {
description = " (Optional) Specify how SSL connection should be enforced in DB connections."
type = string
default = "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
}

variable "settings_ip_configuration_ipv4_enabled" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ settings_disk_size = 10
settings_disk_type = "PD_SSD"
settings_backup_configuration_enabled = true
settings_backup_configuration_binary_log_enabled = true
settings_ip_configuration_require_ssl = true
settings_ip_configuration_ipv4_enabled = true
settings_ip_configuration_private_network = ""
2 changes: 1 addition & 1 deletion examples/mysql_instance_with_read_replica/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module "sql_database_instance" {
settings_ip_configuration_private_network = module.google_compute_network_private_network.id

#checkov:skip=CKV_GCP_6:Ensure all Cloud SQL database instance requires all incoming connections to use SSL"
settings_ip_configuration_require_ssl = false
settings_ip_configuration_ssl_mode = "ALLOW_UNENCRYPTED_AND_ENCRYPTED"

settings_availability_type = var.settings_availability_type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ variable "settings_backup_configuration_binary_log_enabled" {
default = true
}

variable "settings_ip_configuration_require_ssl" {
description = "(Optional) Whether SSL connections over IP are enforced or not."
type = bool
default = true
variable "settings_ip_configuration_ssl_mode" {
description = " (Optional) Specify how SSL connection should be enforced in DB connections."
type = string
default = "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ settings_disk_size = 10
settings_disk_type = "PD_SSD"
settings_backup_configuration_enabled = true
settings_backup_configuration_binary_log_enabled = true
settings_ip_configuration_require_ssl = false
2 changes: 1 addition & 1 deletion examples/postgres_instance_with_read_replica/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module "sql_database_instance" {
settings_ip_configuration_private_network = module.google_compute_network_private_network.id

#checkov:skip=CKV_GCP_6:Ensure all Cloud SQL database instance requires all incoming connections to use SSL"
settings_ip_configuration_require_ssl = false
settings_ip_configuration_ssl_mode = "ALLOW_UNENCRYPTED_AND_ENCRYPTED"

settings_availability_type = var.settings_availability_type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ variable "settings_backup_configuration_binary_log_enabled" {
default = true
}

variable "settings_ip_configuration_require_ssl" {
description = "(Optional) Whether SSL connections over IP are enforced or not."
type = bool
default = true
variable "settings_ip_configuration_ssl_mode" {
description = " (Optional) Specify how SSL connection should be enforced in DB connections."
type = string
default = "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ settings_disk_size = 10
settings_disk_type = "PD_SSD"
settings_backup_configuration_enabled = true
settings_backup_configuration_binary_log_enabled = true
settings_ip_configuration_require_ssl = false
2 changes: 1 addition & 1 deletion modules/google_service_networking_connection/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ variable "reserved_peering_ranges" {
}

variable "deletion_policy" {
description = "(Optional) The deletion policy for the peering. One of 'DELETE' or 'ABANDON'. Defaults to 'DELETE'."
description = "(Optional) The deletion policy for the service networking connection. Setting to ABANDON allows the resource to be abandoned rather than deleted. This will enable a successful terraform destroy when destroying CloudSQL instances. Use with care as it can lead to dangling resources."
type = string
default = ""
}
18 changes: 10 additions & 8 deletions modules/google_sql_database_instance/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ locals {
#tfsec:ignore:google-sql-pg-log-lock-waits
#tfsec:ignore:google-sql-pg-log-disconnections
#tfsec:ignore:google-sql-pg-log-checkpoints
#tfsec:ignore:google-sql-encrypt-in-transit-data
resource "google_sql_database_instance" "instance" {
# This is a component module - these setting will be overridden from the embedding module/repo.
#checkov:skip=CKV_GCP_51:Ensure PostgreSQL database 'log_checkpoints' flag is set to 'on'
Expand All @@ -54,7 +55,8 @@ resource "google_sql_database_instance" "instance" {
#checkov:skip=CKV_GCP_111:Ensure GCP PostgreSQL logs SQL statements 'pgaudit.log' flag is set to 'all'
#checkov:skip=CKV2_GCP_20:Ensure MySQL DB instance has point-in-time recovery backup configured
#checkov:skip=CKV2_GCP_13:Ensure PostgreSQL database flag 'log_duration' is set to 'on'
#checkov:skip=CKV_GCP_79: "Ensure SQL database is using latest Major version"
#checkov:skip=CKV_GCP_79:Ensure SQL database is using latest Major version
#checkov:skip=CKV_GCP_6:Ensure all Cloud SQL database instance requires all incoming connections to use SSL

database_version = var.database_version

Expand Down Expand Up @@ -88,10 +90,10 @@ resource "google_sql_database_instance" "instance" {

ip_configuration {
#tfsec:ignore:google-sql-encrypt-in-transit-data
require_ssl = var.settings_ip_configuration_require_ssl
ssl_mode = var.settings_ip_configuration_ssl_mode

#checkov:skip=CKV_GCP_60:Ensure Cloud SQL database does not have public IP - default value is false
#tfsec:ignore:google-sql-no-public-access
#tfsec:ignore:google-sql-no-public-access:Ensure Cloud SQL database does not have public IP
ipv4_enabled = var.settings_ip_configuration_ipv4_enabled

private_network = var.settings_ip_configuration_private_network
Expand Down Expand Up @@ -153,7 +155,8 @@ resource "google_sql_database_instance" "read_replica" {
#checkov:skip=CKV_GCP_111:Ensure GCP PostgreSQL logs SQL statements 'pgaudit.log' flag is set to 'all'
#checkov:skip=CKV2_GCP_20:Ensure MySQL DB instance has point-in-time recovery backup configured
#checkov:skip=CKV2_GCP_13:Ensure PostgreSQL database flag 'log_duration' is set to 'on'
#checkov:skip=CKV_GCP_79: "Ensure SQL database is using latest Major version"
#checkov:skip=CKV_GCP_79:Ensure SQL database is using latest Major version
#checkov:skip=CKV_GCP_6:Ensure all Cloud SQL database instance requires all incoming connections to use SSL

depends_on = [
google_sql_database_instance.instance
Expand Down Expand Up @@ -182,17 +185,16 @@ resource "google_sql_database_instance" "read_replica" {
disk_autoresize_limit = var.settings_disk_autoresize_limit

backup_configuration {
#tfsec:ignore:google-sql-enable-backup:read replica no need to backup
enabled = false
binary_log_enabled = false
}

ip_configuration {
#tfsec:ignore:google-sql-encrypt-in-transit-data:because default value is true
require_ssl = var.settings_ip_configuration_require_ssl
#tfsec:ignore:google-sql-encrypt-in-transit-data
ssl_mode = var.settings_ip_configuration_ssl_mode

#checkov:skip=CKV_GCP_60:Ensure Cloud SQL database does not have public IP - default value is false
#tfsec:ignore:google-sql-no-public-access
#tfsec:ignore:google-sql-no-public-access: "Ensure Cloud SQL database does not have public IP"
ipv4_enabled = var.read_replica_settings_ip_configuration_ipv4_enabled

private_network = var.settings_ip_configuration_private_network
Expand Down
12 changes: 8 additions & 4 deletions modules/google_sql_database_instance/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,14 @@ variable "settings_backup_configuration_backup_retention_settings_retained_backu
default = 7
}

variable "settings_ip_configuration_require_ssl" {
description = "(Optional) Whether SSL connections over IP are enforced or not."
type = bool
default = true
variable "settings_ip_configuration_ssl_mode" {
description = "(Optional) Specify how SSL connection should be enforced in DB connections. Supported values are `ALLOW_UNENCRYPTED_AND_ENCRYPTED`, `ENCRYPTED_ONLY`, `TRUSTED_CLIENT_CERTIFICATE_REQUIRED`."
type = string
default = "ALLOW_UNENCRYPTED_AND_ENCRYPTED"
validation {
condition = can(regex("ALLOW_UNENCRYPTED_AND_ENCRYPTED|ENCRYPTED_ONLY|TRUSTED_CLIENT_CERTIFICATE_REQUIRED", var.settings_ip_configuration_ssl_mode))
error_message = "Support only `ALLOW_UNENCRYPTED_AND_ENCRYPTED`, `ENCRYPTED_ONLY`, `TRUSTED_CLIENT_CERTIFICATE_REQUIRED`."
}
}

variable "settings_ip_configuration_ipv4_enabled" {
Expand Down

0 comments on commit b88a263

Please sign in to comment.