- Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathmain.tf
64 lines (51 loc) · 1.48 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
variable"nixos_version" {
type=string
default="latest"
description="The NixOS version to use. Eg: 18.09"
}
variable"gcp_project_id" {
type=string
default=""
description="The ID of the project in which the resource belongs. If it is not provided, the provider project is used."
}
variable"labels" {
type=map(string)
default={}
description="A map of labels applied to this image."
}
variable"licenses" {
type=list(string)
default=[
"https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx",
]
description="A list of license URIs to apply to this image. Changing this forces a new resource to be created."
}
# ---
locals {
image_url=var.url_map[var.nixos_version]
# Example: nixos-image-18-09-1228-a4c4cbb613c-x86-64-linux
#
# Remove a few things so that it matches the required regexp for image names
# (?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?)
image_name=replace(
replace(basename(local.image_url), ".raw.tar.gz", ""),
"/[._]+/",
"-",
)
}
resource"google_compute_image""nixos" {
name=local.image_name
description="NixOS ${var.nixos_version}"
family="nixos"
project=var.gcp_project_id
labels=var.labels
licenses=var.licenses
raw_disk {
source=local.image_url
}
}
# ---
output"self_link" {
description="Link to the NixOS Compute Image"
value=google_compute_image.nixos.self_link
}