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

deprecate 0.11 syntax in docs (resources) #2574

Merged
merged 2 commits into from
Nov 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ resource "google_dataproc_cluster" "mycluster" {
}

gce_cluster_config {
#network = "${google_compute_network.dataproc_network.name}"
tags = ["foo", "bar"]
service_account_scopes = [
"https://www.googleapis.com/auth/monitoring",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -111,20 +94,24 @@ resource "google_sql_database_instance" "postgres" {
tier = "db-f1-micro"

ip_configuration {

dynamic "authorized_networks" {
Copy link
Contributor

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.

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}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming this is the index?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup!

value = onprem.value
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

terraform 0.12upgrade left this comment here:

TF-UPGRADE-TODO: The automatic upgrade tool can't predict
which keys might be set in maps assigned here, so it has
produced a comprehensive set here. Consider simplifying
this after confirming which keys can be set in practice.

After looking above do we not need expiration_time set in these?

Copy link
Contributor

Choose a reason for hiding this comment

The 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 name in there for good measure. So I feel pretty confident that expiration_time is not needed.
However I'm less confident about the the dynamic block syntax, but it seems like we could get away with removing the null resources here completely and accomplish the same goal. Which I think would be a great example of "here's something we had to work around in 0.11 that isn't such a hack in 0.12".

}
Expand Down