-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
81 lines (65 loc) · 1.68 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
provider "google" {
region = "us-east1"
}
variable "billing_account_id" {
type = string
}
resource "random_string" "project_number" {
length = 4
special = false
upper = false
lower = false
}
resource "google_project" "freebie" {
name = "Freebie VM"
project_id = "freebie-vm-${random_string.project_number.result}"
billing_account = var.billing_account_id
}
resource "google_compute_project_metadata" "freebie" {
project = google_project.freebie.project_id
metadata = {
enable-oslogin = true
}
depends_on = [
google_project_service.compute_engine_api,
]
}
resource "google_project_service" "compute_engine_api" {
service = "compute.googleapis.com"
project = google_project.freebie.project_id
disable_dependent_services = true
}
resource "google_compute_instance" "free_vm" {
name = "freebie"
machine_type = "f1-micro"
zone = "us-east1-b"
project = google_project.freebie.project_id
depends_on = [
google_project_service.compute_engine_api,
google_compute_project_metadata.freebie,
]
boot_disk {
initialize_params {
image = "ubuntu-os-cloud/ubuntu-minimal-2004-lts"
size = 30
}
}
network_interface {
network = "default"
access_config {
network_tier = "STANDARD"
}
}
}
output "public_ip" {
value = google_compute_instance.free_vm.network_interface.0.access_config.0.nat_ip
}
output "project_id" {
value = google_project.freebie.project_id
}
output "vm_name" {
value = google_compute_instance.free_vm.name
}
output "zone" {
value = google_compute_instance.free_vm.zone
}