-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnixstrap.tf
62 lines (51 loc) · 1.42 KB
/
nixstrap.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
data "google_project" "default" {}
locals {
service_account = "${data.google_project.default.number}[email protected]"
}
variable "nixstrap_path" {
type = string
}
variable "nixstrap_hash" {
type = string
}
resource "random_pet" "bucket_name" {
prefix = "mut-nixstrap"
}
resource "google_storage_bucket" "default" {
name = random_pet.bucket_name.id
location = "US-CENTRAL1"
project = data.google_project.default.project_id
# Delete objects after a day, as they'll have been uploaded to a GCP disk image.
lifecycle_rule {
action {
type = "Delete"
}
condition {
age = 1
}
}
}
resource "google_storage_bucket_object" "default" {
name = "mut-${var.nixstrap_hash}.tar.gz"
source = var.nixstrap_path
bucket = google_storage_bucket.default.name
}
resource "google_compute_image" "default" {
name = "nixstrap-${var.nixstrap_hash}"
raw_disk {
source = "https://storage.googleapis.com/${google_storage_bucket.default.name}/${google_storage_bucket_object.default.output_name}"
}
disk_size_gb = 1
family = "mut-nixstrap"
guest_os_features {
type = "UEFI_COMPATIBLE"
}
licenses = ["https://compute.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx"]
lifecycle {
# ensure we atomically upgrade the nixstrap image
create_before_destroy = true
}
}
output "image" {
value = google_compute_image.default.id
}