-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
101 lines (78 loc) · 2 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
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "5.29.1"
}
}
}
provider "google" {
project = var.project
region = var.region
}
resource "google_compute_image" "this" {
name = "nested-ubuntu-jammy"
source_image = "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-2204-jammy-v20240515"
licenses = [
"https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/licenses/ubuntu-2204-lts",
"https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx"
]
}
module "vpc" {
source = "terraform-google-modules/network/google"
version = "9.1.0"
project_id = var.project
network_name = "${var.name}-vpc"
subnets = [
{
subnet_name = "${var.name}-${var.region}-subnet"
subnet_ip = "10.10.10.0/24"
subnet_region = var.region
}
]
}
resource "google_compute_firewall" "allow-in" {
name = "${var.name}-all-in"
network = module.vpc.network_id
allow {
protocol = "all"
}
priority = 1000
direction = "INGRESS"
source_ranges = ["0.0.0.0/0"]
}
resource "google_compute_firewall" "allow-out" {
name = "${var.name}-all-out"
network = module.vpc.network_id
allow {
protocol = "all"
}
priority = 1000
direction = "EGRESS"
source_ranges = ["0.0.0.0/0"]
}
resource "google_compute_instance" "this" {
name = "${var.name}-instance"
machine_type = var.machine_type
zone = var.zone
boot_disk {
initialize_params {
size = var.disk_size
type = "pd-balanced"
image = google_compute_image.this.self_link
}
}
network_interface {
subnetwork = module.vpc.subnets_names[0]
subnetwork_project = var.project
access_config {
}
}
depends_on = [google_compute_image.this]
}
output "ip" {
value = google_compute_instance.this.network_interface[0].access_config[0].nat_ip
}
output "instance_name" {
value = google_compute_instance.this.name
}