forked from bhupen/terraform-google-network-subnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
51 lines (41 loc) · 1.48 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> 3.28.0"
} # https://github.com/terraform-providers/terraform-provider-google-beta/releases
}
}
/******************************************
Create subnetwork without secondary_range
*****************************************/
resource "google_compute_subnetwork" "basic" {
count = var.create_secondary_ranges ? 0 : 1
name = var.name
description = var.description != "" ? var.description : local.description
region = var.region
ip_cidr_range = var.ip_cidr_range
network = var.network
project = var.project
private_ip_google_access = true
}
/******************************************
Create subnetwork with secondary_range
*****************************************/
resource "google_compute_subnetwork" "ranged" {
count = var.create_secondary_ranges ? 1 : 0
name = var.name
description = var.description != "" ? var.description : local.description
region = var.region
ip_cidr_range = var.ip_cidr_range
network = var.network
dynamic "secondary_ip_range" {
for_each = var.secondary_ranges
content {
ip_cidr_range = lookup(secondary_ip_range.value, "ip_cidr_range", null)
range_name = lookup(secondary_ip_range.value, "range_name", null)
}
}
project = var.project
private_ip_google_access = true
}