0

I have made a simple Terraform manifest that successfully initiates a Windows 2016 instance in GCP. As a next step I would like to execute a Powershell script to further configure and install software in the Windows instance.

I can not for my life find any example on how to execute a remote script through Terraform in a Windows GCP instance. For Linux instances it seems pretty straight forward, but how is it supposed to be done for Windows? Does anyone know any examples?

Any thoughts or ideas are much appreciated, thanks!

1 Answer 1

0

You can set the metadata to init your script like this:

resource "google_compute_instance" "default" {
 project = "your_project"
 zone = "us-central1-c"
 name = "tf-windows-script"
 machine_type = "f1-micro"
 boot_disk {
   initialize_params {
     image = "windows-server-2008-r2-dc-v20180710"
   }
 }
 network_interface {
   network = "default"
   access_config {
   }
 }
 metadata {
    windows-startup-script-url = "gs://your_bucket/startup.ps1"
  }
}

In my test the init script works without problems,

Here you can check the documentation of how to provide a startup script for Windows instances

5
  • Thanks @miguelfrancisco85 I use windows-startup-script-ps1, and can see in Windows application log that GCEMetadataScripts: Finished running startup scripts.. However I can not see anything being executed. In my example I have used a simple script that creates a folder. Do you have any thoughts on why my script does not execute? Thanks
    – TKO
    Aug 19, 2018 at 8:02
  • Perhaps you have an error inside your script. This is what I'm using storage.googleapis.com/windows-script-mnunez/startup.ps1 Aug 20, 2018 at 0:31
  • It's actually more likely permissions on the bucket. This part confuses me a bit. Which user is actually making the access to the bucket? I tried giving the service account, that runs the Terraform connection, owner access to the bucket.Still I get 403 in the Windows event log. GCEMetadataScripts: ERROR main.go:320: error downloading script: GET "https://storage.googleapis.com/qsefw-bucket/startup.ps1", bad status: 403 Forbidden
    – TKO
    Aug 20, 2018 at 8:54
  • GCE documentation confirms that windows-startup-script-url has to point to a public file, which does not work for me as I need to pass in some user credentials
    – TKO
    Aug 21, 2018 at 8:19
  • It's not only to the bucket, you can control the access to the file/object cloud.google.com/storage/docs/gsutil/commands/acl#ch-examples Aug 24, 2018 at 20:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .