I am creating custom network and cloud SQL in Google Cloud. I am using module approach while creating.
below is my block of code of main.tf
module "network" {
source = "./cloudNetwork"
subnet_count = var.subnets
subnet_names = var.sub_names
region = var.region
vpc_cidr = var.cidr
}
module "cloudsql" {
source = "./cloudSQL"
depends_on = [module.network]
custom_network = module.network.vpc_network_self_link
db_instance_name = var.db_name
db_version = var.versions
db_storage_size = var.dbsize
db_machine_type = var.type
query_insights_enabled = var.insights
db_labels = var.labels
dbname = var.name
password = var.dbpassword
dbuser = var.user
address = local.my_ip_address
region = var.region
}
My Network Configuration,
resource "google_compute_network" "vpc_network" {
name = "terraform-network"
auto_create_subnetworks = false
routing_mode = "REGIONAL"
}
resource "google_compute_subnetwork" "my_subnets" {
count = var.subnet_count
name = var.subnet_names[count.index]
network = google_compute_network.vpc_network.name
region = var.region
ip_cidr_range = cidrsubnet(var.vpc_cidr, 8, count.index)
}
resource "google_service_networking_connection" "private_service_connection" {
network = google_compute_network.vpc_network.name
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [element(google_compute_subnetwork.my_subnets[*].ip_cidr_range, 1)]
depends_on = [google_compute_subnetwork.my_subnets]
}
Error I am getting like below,
Anyone have any idea? Suggest me what I have done wrong..
Thank You
Below changes I have made in code,
I got success. I am able to create cloudSQL and custom network along with private Ip address for connectivity.