-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.tf
More file actions
47 lines (38 loc) · 1005 Bytes
/
Copy pathmain.tf
File metadata and controls
47 lines (38 loc) · 1005 Bytes
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
resource "google_compute_address" "default" {
count = var.public_ip ? 1 : 0
name = "${var.name}-ip"
}
resource "google_compute_instance" "instance" {
name = "${var.name}-srv"
machine_type = var.instance_size
zone = "${var.region}-${var.zone}"
boot_disk {
initialize_params {
image = "ubuntu-os-cloud/ubuntu-2204-lts"
}
}
network_interface {
network = var.vpc
subnetwork = var.subnet
dynamic "access_config" {
for_each = var.public_ip == true ? toset([1]) : toset([])
content {
nat_ip = google_compute_address.default[0].address
}
}
}
metadata_startup_script = var.cloud_init_data
tags = ["allow-ssh-${var.name}", var.tags]
metadata = {
ssh-keys = "ubuntu:${var.ssh_key}"
}
}
resource "google_compute_firewall" "fw" {
name = "allow-all-${var.name}"
network = var.vpc
allow {
protocol = "all"
}
source_ranges = ["0.0.0.0/0"]
target_tags = [ ] #"allow-all-${var.name}"]
}