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: add depends on replicas for user creation #268

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
2 changes: 1 addition & 1 deletion examples/postgresql-public-iam/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module "postgresql-db" {
project_id = var.project_id
zone = "us-central1-c"
region = "us-central1"
tier = "db-f1-micro"
tier = "db-custom-2-13312"

deletion_protection = false

Expand Down
2 changes: 1 addition & 1 deletion examples/postgresql-public/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module "postgresql-db" {
project_id = var.project_id
zone = "us-central1-c"
region = "us-central1"
tier = "db-f1-micro"
tier = "db-custom-2-13312"

deletion_protection = false

Expand Down
38 changes: 23 additions & 15 deletions modules/mysql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -171,24 +171,32 @@ resource "random_id" "additional_passwords" {
}

resource "google_sql_user" "default" {
count = var.enable_default_user ? 1 : 0
name = var.user_name
project = var.project_id
instance = google_sql_database_instance.default.name
host = var.user_host
password = var.user_password == "" ? random_id.user-password.hex : var.user_password
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
count = var.enable_default_user ? 1 : 0
name = var.user_name
project = var.project_id
instance = google_sql_database_instance.default.name
host = var.user_host
password = var.user_password == "" ? random_id.user-password.hex : var.user_password
depends_on = [
null_resource.module_depends_on,
google_sql_database_instance.default,
google_sql_database_instance.replicas,
]
}

resource "google_sql_user" "additional_users" {
for_each = local.users
project = var.project_id
name = each.value.name
password = lookup(each.value, "password", random_id.user-password.hex)
host = lookup(each.value, "host", var.user_host)
instance = google_sql_database_instance.default.name
type = lookup(each.value, "type", "BUILT_IN")
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
for_each = local.users
project = var.project_id
name = each.value.name
password = lookup(each.value, "password", random_id.user-password.hex)
host = lookup(each.value, "host", var.user_host)
instance = google_sql_database_instance.default.name
type = lookup(each.value, "type", "BUILT_IN")
depends_on = [
null_resource.module_depends_on,
google_sql_database_instance.default,
google_sql_database_instance.replicas,
]
}

resource "null_resource" "module_depends_on" {
Expand Down
32 changes: 20 additions & 12 deletions modules/postgresql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,29 @@ resource "random_id" "additional_passwords" {
}

resource "google_sql_user" "default" {
count = var.enable_default_user ? 1 : 0
name = var.user_name
project = var.project_id
instance = google_sql_database_instance.default.name
password = var.user_password == "" ? random_id.user-password.hex : var.user_password
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
count = var.enable_default_user ? 1 : 0
name = var.user_name
project = var.project_id
instance = google_sql_database_instance.default.name
password = var.user_password == "" ? random_id.user-password.hex : var.user_password
depends_on = [
null_resource.module_depends_on,
google_sql_database_instance.default,
google_sql_database_instance.replicas,
]
}

resource "google_sql_user" "additional_users" {
for_each = local.users
project = var.project_id
name = each.value.name
password = coalesce(each.value["password"], random_id.additional_passwords[each.value.name].hex)
instance = google_sql_database_instance.default.name
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
for_each = local.users
project = var.project_id
name = each.value.name
password = coalesce(each.value["password"], random_id.additional_passwords[each.value.name].hex)
instance = google_sql_database_instance.default.name
depends_on = [
null_resource.module_depends_on,
google_sql_database_instance.default,
google_sql_database_instance.replicas,
]
}

resource "google_project_iam_member" "iam_binding" {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/postgresql-public-iam/controls/pg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
basename = attribute('name')
db_version = "POSTGRES_9_6"
region = "us-central1"
tier = "db-f1-micro"
tier = "db-custom-2-13312"
public_ip_address = attribute('public_ip_address')

activation_policy = "ALWAYS"
Expand Down
2 changes: 1 addition & 1 deletion test/integration/postgresql-public/controls/pg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
basename = attribute('name')
db_version = "POSTGRES_9_6"
region = "us-central1"
tier = "db-f1-micro"
tier = "db-custom-2-13312"
public_ip_address = attribute('public_ip_address')

activation_policy = "ALWAYS"
Expand Down