-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkl-gce-vm.tf
81 lines (66 loc) · 1.61 KB
/
kl-gce-vm.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
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "4.55.0"
}
time = {
source = "hashicorp/time"
version = "0.9.1"
}
}
}
variable "image_name" {
type = string
}
variable "ssh_public_key" {
type = string
nullable = true
default = null
}
variable "ovmid" {
type = string
nullable = true
default = null
}
resource "time_static" "activation_date" {}
locals {
project = "project-keylime"
region = "europe-west2"
zone = "europe-west2-c"
}
provider "google" {
project = local.project
region = local.region
zone = local.zone
}
resource "google_compute_instance" "vm_instance" {
name = "terraform-keylime-${coalesce(var.ovmid, time_static.activation_date.unix)}"
machine_type = "n1-standard-2"
tags = ["allow-ssh"]
allow_stopping_for_update = true
metadata = {
ssh-keys = var.ssh_public_key != null ? "kluser:${file(var.ssh_public_key)}" : ""
}
boot_disk {
initialize_params {
image = "${local.project}/${var.image_name}"
}
}
network_interface {
network = "keylime"
subnetwork = "keylime-london"
access_config {
network_tier = "STANDARD"
}
}
}
output "vm_name" {
value = google_compute_instance.vm_instance.name
}
output "ephemeral_vm_ip" {
value = google_compute_instance.vm_instance.network_interface[0].access_config[0].nat_ip
}
output "gcloud_ssh_cmd" {
value = "gcloud compute ssh --zone ${local.zone} ${google_compute_instance.vm_instance.name} --project ${local.project}"
}