If you attempt to start a windows instance with terraform on google compute, it will error because it uses a different path in the api.
config
provider "google" {
account_file = "account.json"
client_secrets_file = "client_secrets.json"
project = "foobar"
region = "us-central1"
}
resource "google_compute_instance" "windows2008-01" {
name = "win2008"
machine_type = "g1-small"
zone = "us-central1-a"
disk {
image = "windows-server-2008-r2-dc-v20150110"
}
network {
source = "default"
}
}
The error it produces
error applying plan:
1 error(s) occurred:
* Error loading image 'windows-server-2008-r2-dc-v20150110': googleapi: Error 404: The resource 'projects/foobar/global/images/windows-server-2008-r2-dc-v20150110' was not found, notFound
Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
The path to the image should be 'projects/windows-cloud/global/images/....'
"https://www.googleapis.com/compute/v1/projects/windows-cloud/global/images/windows-server-2008-r2-dc-v20150110",
I'm not sure if this is something that can be overwritten in the terraform file.
As a side note, notice that there is a typo in the error message. The phrase 'not found' shows up twice.
....v20150110' was not found, notFound
Have you tried putting the entire URL in?
Ok here's the situation. The string you enter into Terraform instance config is used in the following way:
1) A call to the query image API https://cloud.google.com/compute/docs/reference/latest/images/get to get the actual image URL. That API takes project and image name parameters and yields lots of info about the image (e.g. size) but in this case we only use its full URL. Terraform uses your project name (from provider settings) as the project argument to that call.
2) The Instance is created with https://cloud.google.com/compute/docs/reference/latest/instances/insert with the sourceImage field set to the URL retrieved from the previous step.
If you attempt to give the full URL of the image or something like windows-cloud/global/images/windows-server-2008-r2-dc-v20150110 then this string will be provided as the "name" field to the query API as well as your own project name. It then gets rejected because image names cannot contain / among other things (regex check).
I think the right thing to do is to allow the user to put the full URL into terraform if desired (instead of a short hand name) and in that case, do not do step (1) above, just use the URL when creating the instance.
So I already did something similar for target pools:
I'll start work on a PR to do the same thing for images
Your original example should work with that PR as I added windows-cloud to the other public image hosting projects. But don't forget to set a password so you can rdesktop in. Unlike gcloud, terraform will not generate a password for you.
metadata {
gce-initial-windows-user = "yourname"
gce-initial-windows-password = "fooBAR123"
}
@sparkprime Those metadata keys seem to have been deprecated, any ideas on how we can set up the initial password for a windows vm when provisioning through terraform now?
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Most helpful comment
@sparkprime Those metadata keys seem to have been deprecated, any ideas on how we can set up the initial password for a windows vm when provisioning through terraform now?