Copy and paste the following into main.tf
and run coder template push
:
1terraform {
2 required_providers {
3 coder = {
4 source = "coder/coder"
5 }
6 google = {
7 source = "hashicorp/google"
8 }
9 }
10}
11
12provider "coder" {
13}
14
15variable "project_id" {
16 description = "Which Google Compute Project should your workspace live in?"
17}
18
19data "coder_parameter" "zone" {
20 name = "zone"
21 display_name = "Zone"
22 description = "Which zone should your workspace live in?"
23 type = "string"
24 default = "us-central1-a"
25 icon = "/emojis/1f30e.png"
26 mutable = false
27 option {
28 name = "North America (Northeast)"
29 value = "northamerica-northeast1-a"
30 icon = "/emojis/1f1fa-1f1f8.png"
31 }
32 option {
33 name = "North America (Central)"
34 value = "us-central1-a"
35 icon = "/emojis/1f1fa-1f1f8.png"
36 }
37 option {
38 name = "North America (West)"
39 value = "us-west2-c"
40 icon = "/emojis/1f1fa-1f1f8.png"
41 }
42 option {
43 name = "Europe (West)"
44 value = "europe-west4-b"
45 icon = "/emojis/1f1ea-1f1fa.png"
46 }
47 option {
48 name = "South America (East)"
49 value = "southamerica-east1-a"
50 icon = "/emojis/1f1e7-1f1f7.png"
51 }
52}
53
54provider "google" {
55 zone = data.coder_parameter.zone.value
56 project = var.project_id
57}
58
59data "coder_workspace" "me" {
60}
61data "coder_workspace_owner" "me" {}
62
63data "google_compute_default_service_account" "default" {
64}
65
66resource "google_compute_disk" "root" {
67 name = "coder-${data.coder_workspace.me.id}-root"
68 type = "pd-ssd"
69 zone = data.coder_parameter.zone.value
70 image = "projects/windows-cloud/global/images/windows-server-2022-dc-core-v20220215"
71 lifecycle {
72 ignore_changes = [name, image]
73 }
74}
75
76resource "coder_agent" "main" {
77 auth = "google-instance-identity"
78 arch = "amd64"
79 os = "windows"
80
81}
82
83resource "google_compute_instance" "dev" {
84 zone = data.coder_parameter.zone.value
85 count = data.coder_workspace.me.start_count
86 name = "coder-${lower(data.coder_workspace_owner.me.name)}-${lower(data.coder_workspace.me.name)}"
87 machine_type = "e2-medium"
88 network_interface {
89 network = "default"
90 access_config {
91 // Ephemeral public IP
92 }
93 }
94 boot_disk {
95 auto_delete = false
96 source = google_compute_disk.root.name
97 }
98 service_account {
99 email = data.google_compute_default_service_account.default.email
100 scopes = ["cloud-platform"]
101 }
102 metadata = {
103 windows-startup-script-ps1 = coder_agent.main.init_script
104 serial-port-enable = "TRUE"
105 }
106}
107resource "coder_metadata" "workspace_info" {
108 count = data.coder_workspace.me.start_count
109 resource_id = google_compute_instance.dev[0].id
110
111 item {
112 key = "type"
113 value = google_compute_instance.dev[0].machine_type
114 }
115}
116
117resource "coder_metadata" "home_info" {
118 resource_id = google_compute_disk.root.id
119
120 item {
121 key = "size"
122 value = "${google_compute_disk.root.size} GiB"
123 }
124}
125