Skip to content

Commit 7b4d7a9

Browse files
committed
Fix IPv6 address creation
1 parent 348a723 commit 7b4d7a9

File tree

3 files changed

+105
-39
lines changed

3 files changed

+105
-39
lines changed

cloud_sql/mysql_instance_psc/main.tf

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,49 @@ data "google_sql_database_instance" "default" {
5151
}
5252

5353
resource "google_compute_forwarding_rule" "default" {
54-
name = "psc-forwarding-rule-${google_sql_database_instance.default.name}"
55-
region = "us-central1"
56-
network = "default"
57-
ip_address = google_compute_address.default.self_link
58-
load_balancing_scheme = ""
59-
target = data.google_sql_database_instance.default.psc_service_attachment_link
54+
name = "psc-forwarding-rule-${google_sql_database_instance.default.name}"
55+
region = "us-central1"
56+
network = "default"
57+
ip_address = google_compute_address.default.self_link
58+
load_balancing_scheme = ""
59+
target = data.google_sql_database_instance.default.psc_service_attachment_link
6060
allow_psc_global_access = true
6161
}
6262
# [END cloud_sql_mysql_instance_psc_endpoint]
6363

6464
# [START cloud_sql_mysql_instance_ipv6_psc_endpoint]
65+
resource "google_compute_network" "ipv6_default" {
66+
name = "net-ipv6"
67+
auto_create_subnetworks = false
68+
enable_ula_internal_ipv6 = true
69+
}
70+
71+
resource "google_compute_subnetwork" "ipv6_default" {
72+
name = "subnet-internal-ipv6"
73+
ip_cidr_range = "10.0.0.0/16"
74+
region = "us-central1"
75+
stack_type = "IPV4_IPV6"
76+
ipv6_access_type = "INTERNAL"
77+
network = google_compute_network.ipv6_default.id
78+
}
79+
80+
resource "google_compute_address" "ipv6_default" {
81+
name = "psc-compute-ipv6-address-${google_sql_database_instance.default.name}"
82+
region = "us-central1"
83+
address_type = "INTERNAL"
84+
subnetwork = google_compute_subnetwork.ipv6_default.name
85+
ip_version = "IPV6"
86+
}
87+
6588
resource "google_compute_forwarding_rule" "ipv6_ilb_example" {
6689
name = "ipv6-psc-forwarding-rule-${google_sql_database_instance.default.name}"
6790
region = "us-central1"
6891

69-
load_balancing_scheme = ""
70-
target = data.google_sql_database_instance.default.psc_service_attachment_link
71-
all_ports = true
72-
network = "default" # Replace value with the name of the network here.
73-
subnetwork = "default" # Replace value with the name of the subnet here.
74-
ip_version = "IPV6"
92+
load_balancing_scheme = ""
93+
target = data.google_sql_database_instance.default.psc_service_attachment_link
94+
network = google_compute_network.ipv6_default.name
95+
subnetwork = google_compute_subnetwork.ipv6_default.name
96+
ip_address = google_compute_address.ipv6_default.id
7597
allow_psc_global_access = true
7698
}
77-
# [END cloud_sql_mysql_instance_ipv6_psc_endpoint]
99+
# [END cloud_sql_mysql_instance_ipv6_psc_endpoint]

cloud_sql/postgres_instance_psc/main.tf

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,49 @@ data "google_sql_database_instance" "default" {
5050
}
5151

5252
resource "google_compute_forwarding_rule" "default" {
53-
name = "psc-forwarding-rule-${google_sql_database_instance.default.name}"
54-
region = "us-central1"
55-
network = "default"
56-
ip_address = google_compute_address.default.self_link
57-
load_balancing_scheme = ""
58-
target = data.google_sql_database_instance.default.psc_service_attachment_link
53+
name = "psc-forwarding-rule-${google_sql_database_instance.default.name}"
54+
region = "us-central1"
55+
network = "default"
56+
ip_address = google_compute_address.default.self_link
57+
load_balancing_scheme = ""
58+
target = data.google_sql_database_instance.default.psc_service_attachment_link
5959
allow_psc_global_access = true
6060
}
6161
# [END cloud_sql_postgres_instance_psc_endpoint]
6262

6363
# [START cloud_sql_postgres_instance_ipv6_psc_endpoint]
64+
resource "google_compute_network" "ipv6_default" {
65+
name = "net-ipv6"
66+
auto_create_subnetworks = false
67+
enable_ula_internal_ipv6 = true
68+
}
69+
70+
resource "google_compute_subnetwork" "ipv6_default" {
71+
name = "subnet-internal-ipv6"
72+
ip_cidr_range = "10.0.0.0/16"
73+
region = "us-central1"
74+
stack_type = "IPV4_IPV6"
75+
ipv6_access_type = "INTERNAL"
76+
network = google_compute_network.ipv6_default.id
77+
}
78+
79+
resource "google_compute_address" "ipv6_default" {
80+
name = "psc-compute-ipv6-address-${google_sql_database_instance.default.name}"
81+
region = "us-central1"
82+
address_type = "INTERNAL"
83+
subnetwork = google_compute_subnetwork.ipv6_default.name
84+
ip_version = "IPV6"
85+
}
86+
6487
resource "google_compute_forwarding_rule" "ipv6_ilb_example" {
6588
name = "ipv6-psc-forwarding-rule-${google_sql_database_instance.default.name}"
6689
region = "us-central1"
6790

68-
load_balancing_scheme = ""
69-
target = data.google_sql_database_instance.default.psc_service_attachment_link
70-
all_ports = true
71-
network = "default" # Replace value with the name of the network here.
72-
subnetwork = "default" # Replace value with the name of the subnet here.
73-
ip_version = "IPV6"
91+
load_balancing_scheme = ""
92+
target = data.google_sql_database_instance.default.psc_service_attachment_link
93+
network = google_compute_network.ipv6_default.name
94+
subnetwork = google_compute_subnetwork.ipv6_default.name
95+
ip_address = google_compute_address.ipv6_default.id
7496
allow_psc_global_access = true
7597
}
76-
# [END cloud_sql_postgres_instance_ipv6_psc_endpoint]
98+
# [END cloud_sql_postgres_instance_ipv6_psc_endpoint]

cloud_sql/sqlserver_instance_psc/main.tf

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,49 @@ data "google_sql_database_instance" "default" {
5252
}
5353

5454
resource "google_compute_forwarding_rule" "default" {
55-
name = "psc-forwarding-rule-${google_sql_database_instance.default.name}"
56-
region = "us-central1"
57-
network = "default"
58-
ip_address = google_compute_address.default.self_link
59-
load_balancing_scheme = ""
60-
target = data.google_sql_database_instance.default.psc_service_attachment_link
55+
name = "psc-forwarding-rule-${google_sql_database_instance.default.name}"
56+
region = "us-central1"
57+
network = "default"
58+
ip_address = google_compute_address.default.self_link
59+
load_balancing_scheme = ""
60+
target = data.google_sql_database_instance.default.psc_service_attachment_link
6161
allow_psc_global_access = true
6262
}
6363
# [END cloud_sql_sqlserver_instance_psc_endpoint]
6464

6565
# [START cloud_sql_sqlserver_instance_ipv6_psc_endpoint]
66+
resource "google_compute_network" "ipv6_default" {
67+
name = "net-ipv6"
68+
auto_create_subnetworks = false
69+
enable_ula_internal_ipv6 = true
70+
}
71+
72+
resource "google_compute_subnetwork" "ipv6_default" {
73+
name = "subnet-internal-ipv6"
74+
ip_cidr_range = "10.0.0.0/16"
75+
region = "us-central1"
76+
stack_type = "IPV4_IPV6"
77+
ipv6_access_type = "INTERNAL"
78+
network = google_compute_network.ipv6_default.id
79+
}
80+
81+
resource "google_compute_address" "ipv6_default" {
82+
name = "psc-compute-ipv6-address-${google_sql_database_instance.default.name}"
83+
region = "us-central1"
84+
address_type = "INTERNAL"
85+
subnetwork = google_compute_subnetwork.ipv6_default.name
86+
ip_version = "IPV6"
87+
}
88+
6689
resource "google_compute_forwarding_rule" "ipv6_ilb_example" {
6790
name = "ipv6-psc-forwarding-rule-${google_sql_database_instance.default.name}"
6891
region = "us-central1"
6992

70-
load_balancing_scheme = ""
71-
target = data.google_sql_database_instance.default.psc_service_attachment_link
72-
all_ports = true
73-
network = "default" # Replace value with the name of the network here.
74-
subnetwork = "default" # Replace value with the name of the subnet here.
75-
ip_version = "IPV6"
93+
load_balancing_scheme = ""
94+
target = data.google_sql_database_instance.default.psc_service_attachment_link
95+
network = google_compute_network.ipv6_default.name
96+
subnetwork = google_compute_subnetwork.ipv6_default.name
97+
ip_address = google_compute_address.ipv6_default.id
7698
allow_psc_global_access = true
7799
}
78-
# [END cloud_sql_sqlserver_instance_ipv6_psc_endpoint]
100+
# [END cloud_sql_sqlserver_instance_ipv6_psc_endpoint]

0 commit comments

Comments
 (0)