Module creates users for Cloud SQL instance, add permissions and exports users to GCP Secret Manager.
Only PSQL is supported.
module "database_users" {
source = "git::ssh://[email protected]/AckeeCZ/terraform-gcp-cloud-sql-user.git"
users = {
"ackee.fella" : {
permissions : ["DELETE", "SELECT", "INSERT", "REFERENCES", "TRIGGER", "TRUNCATE", "UPDATE"]
seq_permissions : ["USAGE", "UPDATE", "SELECT"]
seq_objects : [
"audits_id_seq",
"countries_id_seq",
"discounts_id_seq",
"ga_callbacks_id_seq",
"invoices_id_seq",
"languages_id_seq",
"merchants_id_seq",
"mf_callbacks_id_seq",
"shops_id_seq"
]
}
"reader-sa" : {
permissions : ["SELECT"]
create_sa : true
}
"[email protected]" : {
permissions : ["SELECT"]
type : "CLOUD_IAM_USER"
}
}
database = local.postgres_database_name
postgres_instance_name = local.instance_name
project = var.project
}See example folder for more details.
Users variable is a map of users. Each user has following attributes:
permissions- list of permissions for objectsseq_permissions- list of permissions for sequencesseq_objects- list of sequences objectscreate_sa- create service account for usertype- type of user, default isBUILT_IN, other isCLOUD_IAM_USERspecial- use special characters for the passwordoverride_special- override special characters for the passwordrole- role for the user, default is the key in theusersmap
No requirements.
| Name | Version |
|---|---|
| n/a | |
| postgresql | n/a |
| random | n/a |
No modules.
| Name | Type |
|---|---|
| google_project_iam_member.assign_cloudsql_client | resource |
| google_project_iam_member.test | resource |
| google_project_iam_member.test_cloudsql_client | resource |
| google_secret_manager_secret.database_credentials | resource |
| google_secret_manager_secret_version.database_credentials | resource |
| google_service_account.sa | resource |
| google_service_account_key.sa_key | resource |
| google_sql_user.user | resource |
| postgresql_default_privileges.permissions | resource |
| postgresql_default_privileges.seq_permissions | resource |
| postgresql_grant.permissions | resource |
| postgresql_grant.seq_permissions | resource |
| random_password.password | resource |
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| database | Database name used for permission setup | string |
n/a | yes |
| expose_password | Expose password to Terraform output | bool |
false |
no |
| owner | If set, default privileges will be set for users | string |
"" |
no |
| postgres_instance_name | Cloud SQL instance name | string |
n/a | yes |
| project | Project ID | string |
n/a | yes |
| save_credentials | Save credentials to GCP Secret Manager | bool |
true |
no |
| users | Map of users and their attributes, key is the user login | map |
{} |
no |
| Name | Description |
|---|---|
| passwords | Passwords generated |