Newer
Older
terraform_templates / vpc_with_subnetworks / main.tf
@Curtis Lewis Curtis Lewis on 23 Jun 866 bytes initial commit vpc_with_subnets
# ref:
# https://www.easydeploy.io/blog/create-vpc-network-using-terraform-in-gcp/#

provider "google" {
    project = var.project_id
    region = var.region
}

data "google_compute_zones" "this" {
    region = var.region
    project = var.project_id
}

locals {
    type = ["public"]
    zones = data.google_compute_zones.this.names
}

# VPC
resource "google_compute_network" "this" {
    name                            = "vpc-${var.name}"
    delete_default_routes_on_create = false 
    auto_create_subnetworks         = false 
    routing_mode                    = "REGIONAL"
}

# Subnets
resource "google_compute_subnetwork" "this" {
    count = 1
    name="${var.name}-${local.type[count.index]}-subnetwork"
    ip_cidr_range= var.ip_cidr_range[count.index]
    region=var.region
    network=google_compute_network.this.id 
    private_ip_google_access=true
}