Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Postgres Terraform Module

Requirements

Name Version
terraform >=0.13.2
google >=5
kubernetes ~> 2.0
random >=3.6.2

Providers

Name Version
google >=5
kubernetes ~> 2.0
random >=3.6.2

Modules

No modules.

Resources

Name Type
google_secret_manager_secret.db_secret resource
google_secret_manager_secret.db_secret_additional resource
google_secret_manager_secret_version.db_secret_version_additional_database_credentials resource
google_secret_manager_secret_version.db_secret_version_main_database_credentials resource
google_sql_database.main resource
google_sql_database_instance.main resource
google_sql_user.additional_users resource
google_sql_user.main resource
kubernetes_config_map.main_psql_connection resource
kubernetes_secret.additional_database_credentials resource
kubernetes_secret.main_database_credentials resource
random_integer.additional_users_password_length resource
random_integer.password_length resource
random_password.additional_users_password resource
random_password.password resource

Inputs

Name Description Type Default Required
databases Names of databases to create. list(string) n/a yes
init Entur init module output. https://github.com/entur/terraform-google-init. Used to determine application name, application project, labels, and resource names.
object({
app = object({
id = string
name = string
owner = string
project_id = string
})
networks = object({
project_id = string
vpc_id = string
})
environment = string
labels = map(string)
is_production = bool
})
n/a yes
add_additional_secret_manager_credentials Set to false to not store additional database credentials in secret manager bool true no
add_main_secret_manager_credentials Set to false to not store main database credentials in secret manager bool true no
additional_users A list of user-names in addition to the main user that should be created.
map(object({
username = string
create_kubernetes_secret = bool
}))
{} no
authorized_networks Values for authorized_networks, list of objects with name and simple strings of IPs or CIDRs. Ex: {name: supermachine, value: 35.90.103.132/30} or {name: rogersmachine, value: 35.90.103.132}
list(object({
value = string
name = string
}))
[] no
availability_type Whether to enable high availability with automatic failover over multiple zones ('REGIONAL') vs. single zone ('ZONAL'). string null no
backup_start_time Start time in UTC for daily backup job in the format HH:MM. This is the start time of a 4 hour time window. string "00:00" no
create_kubernetes_resources Optionally disables creating k8s resources -psql-connection and -psql-credentials. Can be used to avoid overwriting existing resources on database creation. bool true no
database_flags Override default CloudSQL configuration by specifying database-flags. Note that some flags require installing extensions. (see https://cloud.google.com/sql/docs/postgres/extensions#installing-an-extension).
map(object({
name = string
value = string
}))
{} no
database_version The PostgreSQL version (see https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance#database_version). string "POSTGRES_14" no
deletion_protection Whether or not to allow Terraform to destroy the instance. bool null no
disable_offsite_backup Disable offsite backup for this instance. Offsite backup is only applied to production environments. bool false no
disk_autoresize Whether to enable auto-resizing of the storage disk. bool true no
disk_autoresize_limit The maximum size an auto-resized disk can reach. Default is 500 for production, 50 for non-production. number null no
disk_size The storage disk size of the instance. Default is 10 (GB). Only takes effect if disk_autoresize is set to 'false'. number 10 no
enable_backup Whether to enable daily backup of databases. bool true no
enable_private_network Whether to enable private network connectivity for the Cloud SQL instance. Immutable after it has been enabled. bool false no
generation The generation (aka serial no.) of the instance. Starts at 1, ends at 999. Will be padded with leading zeros. number 1 no
instance_edition Override the default instance edition (ENTERPRISE or ENTERPRISE_PLUS). string "ENTERPRISE" no
machine_size Map of the database instance CPU count (cpu) and memory sizes in MB (memory). Optionally, set a tier override (tier). See README.md for examples. map(any) null no
maintenance_window The day of the week (1-7), and hour of the day (0-24) in UTC to perform database instance maintenance. This is the start time of the one hour maintinance window.
object({
day = number
hour = number
})
{
"day": 2,
"hour": 0
}
no
point_in_time_recovery_enabled Whether to enable PITR on database instance. Requires enable_backup to be true. bool true no
query_insights_config Advanced config for Query Insights.
object({
query_string_length = number
record_application_tags = bool
record_client_address = bool
})
{
"query_string_length": 1024,
"record_application_tags": false,
"record_client_address": false
}
no
query_insights_enabled Whether to enable query insights (7 day retention). bool false no
region The region the instance will sit in. string "europe-west1" no
retain_backups_on_delete When this parameter is set to true, Cloud SQL retains backups of the instance even after the instance is deleted. bool true no
retained_backups The number of backups to retain. Default is 30 for production, 7 for non-production. number null no
secret_key_prefix Key prefix of secret. Ex. {secret_key_prefix: PSQL_} would give keys PSQL_USER, PSQL_PASSWORD and so on string "PG" no
transaction_log_retention_days How long transaction logs are stored (1-7). number 7 no
user_name The username of the default application user. Defaults to the app ID. string null no

Outputs

Name Description
additional_users Map containing the username and password for any additional users.
databases Databases created on this instance.
init The output of the consumed init module.
instance The database instance output, as described in https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance.
kubernetes_namespace Name of the Kubernetes namespace where config maps and secrets are deployed.
user Map containing the username and password of the default application user.