-
Notifications
You must be signed in to change notification settings - Fork 190
/
main.tf
153 lines (132 loc) · 3.86 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
### GCP terraform
terraform {
required_version = ">=0.12.0"
required_providers {
google = "2.11.0"
google-beta = "2.13"
}
}
provider "google" {
credentials = file("${var.account}")
project = var.project
region = "us-central1"
zone = "us-central1-c"
}
provider "google-beta" {
credentials = file("${var.account}")
project = var.project
region = var.region
zone = var.zone
}
# Randomize string to avoid duplication
resource "random_string" "random_name_post" {
length = 3
special = true
override_special = ""
min_lower = 3
}
# Create log disk
resource "google_compute_disk" "logdisk" {
name = "log-disk-${random_string.random_name_post.result}"
size = 30
type = "pd-standard"
zone = var.zone
}
### VPC ###
resource "google_compute_network" "vpc_network" {
name = "vpc-${random_string.random_name_post.result}"
auto_create_subnetworks = false
}
resource "google_compute_network" "vpc_network2" {
name = "vpc2-${random_string.random_name_post.result}"
auto_create_subnetworks = false
}
### Public Subnet ###
resource "google_compute_subnetwork" "public_subnet" {
name = "public-subnet-${random_string.random_name_post.result}"
region = var.region
network = google_compute_network.vpc_network.name
ip_cidr_range = var.public_subnet
private_ip_google_access = true
}
### Private Subnet ###
resource "google_compute_subnetwork" "private_subnet" {
name = "private-subnet-${random_string.random_name_post.result}"
region = var.region
network = google_compute_network.vpc_network2.name
ip_cidr_range = var.protected_subnet
}
# Firewall Rule External
resource "google_compute_firewall" "allow-fgt" {
name = "allow-fgt-${random_string.random_name_post.result}"
network = google_compute_network.vpc_network.name
allow {
protocol = "tcp"
ports = ["22", "80", "443"]
}
allow {
protocol = "icmp"
}
source_ranges = ["0.0.0.0/0"]
target_tags = ["allow-fgt"]
}
# Firewall Rule Internal
resource "google_compute_firewall" "allow-internal" {
name = "allow-internal-${random_string.random_name_post.result}"
network = google_compute_network.vpc_network2.name
allow {
protocol = "all"
}
source_ranges = ["0.0.0.0/0"]
target_tags = ["allow-internal"]
}
# Create FGTVM compute instance
resource "google_compute_instance" "default" {
name = "fgtnat-${random_string.random_name_post.result}"
machine_type = var.machine
zone = var.zone
can_ip_forward = "true"
tags = ["allow-fgt", "allow-internal"]
boot_disk {
initialize_params {
image = var.image
}
}
attached_disk {
source = google_compute_disk.logdisk.name
}
network_interface {
subnetwork = google_compute_subnetwork.public_subnet.name
access_config {
}
}
network_interface {
subnetwork = google_compute_subnetwork.private_subnet.name
}
metadata = {
#user-data = "${file(var.user_data)}"
user-data = fileexists("${path.module}/${var.user_data}") ? "${file(var.user_data)}" : null
#license = "${file(var.license_file)}" #this is where to put the license file if using BYOL image
license = fileexists("${path.module}/${var.license_file}") ? "${file(var.license_file)}" : null
}
service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
scheduling {
preemptible = true
automatic_restart = false
}
}
# Output
output "FortiGate-NATIP" {
value = google_compute_instance.default.network_interface.0.access_config.0.nat_ip
}
output "FortiGate-InstanceName" {
value = google_compute_instance.default.name
}
output "FortiGate-Username" {
value = "admin"
}
output "FortiGate-Password" {
value = google_compute_instance.default.instance_id
}