-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
deprecate 0.11 syntax in docs (resources) #2574
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,31 +78,14 @@ resource "google_compute_instance" "apps" { | |
} | ||
} | ||
|
||
data "null_data_source" "auth_netw_postgres_allowed_1" { | ||
count = length(google_compute_instance.apps.*.self_link) | ||
|
||
inputs = { | ||
name = "apps-${count.index + 1}" | ||
value = element( | ||
google_compute_instance.apps.*.network_interface.0.access_config.0.nat_ip, | ||
count.index, | ||
) | ||
} | ||
} | ||
|
||
data "null_data_source" "auth_netw_postgres_allowed_2" { | ||
count = 2 | ||
|
||
inputs = { | ||
name = "onprem-${count.index + 1}" | ||
value = element(["192.168.1.2", "192.168.2.3"], count.index) | ||
} | ||
} | ||
|
||
resource "random_id" "db_name_suffix" { | ||
byte_length = 4 | ||
} | ||
|
||
locals { | ||
onprem = ["192.168.1.2", "192.168.2.3"] | ||
} | ||
|
||
resource "google_sql_database_instance" "postgres" { | ||
name = "postgres-instance-${random_id.db_name_suffix.hex}" | ||
database_version = "POSTGRES_9_6" | ||
|
@@ -111,20 +94,24 @@ resource "google_sql_database_instance" "postgres" { | |
tier = "db-f1-micro" | ||
|
||
ip_configuration { | ||
|
||
dynamic "authorized_networks" { | ||
for_each = [data.null_data_source.auth_netw_postgres_allowed_1.*.outputs] | ||
for_each = google_compute_instance.apps | ||
iterator = apps | ||
|
||
content { | ||
expiration_time = lookup(authorized_networks.value, "expiration_time", null) | ||
name = lookup(authorized_networks.value, "name", null) | ||
value = lookup(authorized_networks.value, "value", null) | ||
name = apps.value.name | ||
value = apps.value.network_interface.0.access_config.0.nat_ip | ||
} | ||
} | ||
|
||
dynamic "authorized_networks" { | ||
for_each = [data.null_data_source.auth_netw_postgres_allowed_2.*.outputs] | ||
for_each = local.onprem | ||
iterator = onprem | ||
|
||
content { | ||
expiration_time = lookup(authorized_networks.value, "expiration_time", null) | ||
name = lookup(authorized_networks.value, "name", null) | ||
value = lookup(authorized_networks.value, "value", null) | ||
name = "onprem-${onprem.key}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm assuming this is the index? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup! |
||
value = onprem.value | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
After looking above do we not need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not too familiar with this example, but from my reading the goal is to create a list of IP addresses including all of the compute_instance ip's and the two manual ones. Then make sure that all of those ip's are listed as authorized networks and throws a |
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Way nicer than the workaround with null resources.