TemplatesModules
Back to Templates
Google Compute Engine (Windows) Icon

Google Compute Engine (Windows)

By:
Provision Google Compute Engine instances as Coder workspaces
Source
README
Resources (2)
Variables (1)

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
14variable "project_id" {
15  description = "Which Google Compute Project should your workspace live in?"
16}
17
18# See https://registry.coder.com/modules/gcp-region
19module "gcp_region" {
20  source = "registry.coder.com/modules/gcp-region/coder"
21
22  # This ensures that the latest version of the module gets downloaded, you can also pin the module version to prevent breaking changes in production.
23  version = ">= 1.0.0"
24
25  regions = ["us", "europe"]
26  default = "us-central1-a"
27}
28
29provider "google" {
30  zone    = module.gcp_region.value
31  project = var.project_id
32}
33
34data "coder_workspace" "me" {}
35data "coder_workspace_owner" "me" {}
36
37data "google_compute_default_service_account" "default" {}
38
39resource "google_compute_disk" "root" {
40  name  = "coder-${data.coder_workspace.me.id}-root"
41  type  = "pd-ssd"
42  zone  = module.gcp_region.value
43  image = "projects/windows-cloud/global/images/windows-server-2022-dc-core-v20220215"
44  lifecycle {
45    ignore_changes = [name, image]
46  }
47}
48
49resource "coder_agent" "main" {
50  auth = "google-instance-identity"
51  arch = "amd64"
52  os   = "windows"
53}
54
55resource "google_compute_instance" "dev" {
56  zone         = module.gcp_region.value
57  count        = data.coder_workspace.me.start_count
58  name         = "coder-${lower(data.coder_workspace_owner.me.name)}-${lower(data.coder_workspace.me.name)}"
59  machine_type = "e2-medium"
60  network_interface {
61    network = "default"
62    access_config {
63      // Ephemeral public IP
64    }
65  }
66  boot_disk {
67    auto_delete = false
68    source      = google_compute_disk.root.name
69  }
70  service_account {
71    email  = data.google_compute_default_service_account.default.email
72    scopes = ["cloud-platform"]
73  }
74  metadata = {
75    windows-startup-script-ps1 = coder_agent.main.init_script
76    serial-port-enable         = "TRUE"
77  }
78}
79resource "coder_metadata" "workspace_info" {
80  count       = data.coder_workspace.me.start_count
81  resource_id = google_compute_instance.dev[0].id
82
83  item {
84    key   = "type"
85    value = google_compute_instance.dev[0].machine_type
86  }
87}
88
89resource "coder_metadata" "home_info" {
90  resource_id = google_compute_disk.root.id
91
92  item {
93    key   = "size"
94    value = "${google_compute_disk.root.size} GiB"
95  }
96}
97