Terraform-provider-google: Serial Port data source

Created on 1 Jun 2018  ·  14Comments  ·  Source: hashicorp/terraform-provider-google

It would be useful to be able to query instance's serial ports from Terraform (for example, to retrieve generated Windows passwords. Therefore I would propose the addition of a new google_compute_instance_serial_port data source.

it would use this API: https://cloud.google.com/compute/docs/reference/rest/v1/instances/getSerialPortOutput

Proposed Terraform Config

data "google_compute_instance_serial_port" "password" {
    project = "instance-project"
    zone = "us-central1-a"
    instance = "some-instance-name"
    port = "4"
}

It would automatically handle pagination and return the following fields:

  • contents
enhancement new-data-source sizM

Most helpful comment

Don't suppose there has been any progress on this @paddycarver @morgante ? Pretty necessary when having to unfortunately deal with Windows.

All 14 comments

I believe a copy-and-paste mistake slipped in your Proposed Terraform Config and should probably be called google_compute_instance_serial_port.

I am not familiar with generated Windows passwords, can you add an example Terraform config for a google_compute_instance running windows and exposing the data through its serial ports.

Thank you

Forget my last comment, I have found the information about Windows password generation in #1472:
https://cloud.google.com/compute/docs/instances/windows/automate-pw-generation

I have concerns about this, especially as a data source, because if I'm reading this right, serial ports can only be read once. Data sources will be read many, many times, so the values they retrieve need to be repeatably retrievable, and stable (they don't arbitrarily change between runs).

This _could_ make sense as a resource, but I'm not sure how sensitive to timing it is.

if I'm reading this right, serial ports can only be read once

Where did you see that? In general it isn't true. I just verified in an instance by rerunning the get-serial-port command multiple times and it returned identical output after multiple runs.

Where did you see that? In general it isn't true. I just verified in an instance by rerunning the get-serial-port command multiple times and it returned identical output after multiple runs.

I honestly don't recall where I came across that first, but the impression I got was that the Serial Ports API operated like a stream, that could be only read from once. It sounds like that's not the case, however, which is great news! It also alleviates my concerns. Thanks!

Don't suppose there has been any progress on this @paddycarver @morgante ? Pretty necessary when having to unfortunately deal with Windows.

I am also checking for an update. Currently there is no integrated way to reset windows password on a new Google cloud windows build. I am going to try local-exec , but the proper calls are documented in both go and python. getting data back out of serial port 4 is an essential item for this. Without this we have incomplete windows solutions and have to rely on startup scripts to create initial users.

Just checking in again to see if there is any update. I see it is in the current sprint, does that mean this is being actively worked on now? Would be great to be able to manage Windows VMs via Terraform

@bjaworski3 just FYI I'm actively working on this now and expect to finish it soon (may take a week or two to be fully released though)

Hi,

So now the generated password can be get using this datasource.
But to generate the password, do we still need to write a shell script or go/python program ?

It seems this new resource take into account only step 7 of the manual procedure

Thank you

[1] : https://cloud.google.com/compute/docs/instances/windows/automate-pw-generation

@mldmld68 you can also set the windows-keys label on the instance via the google_compute_instance resource, as shown in the example here: https://github.com/terraform-providers/terraform-provider-google/blob/master/website/docs/d/datasource_compute_instance_serial_port.html.markdown#google_compute_instance_serial_port

Handling RSA public/private keys is somewhat outside of the scope of this provider, but should possible via other Terraform utilities. See https://github.com/terraform-providers/terraform-provider-google/issues/1472#issuecomment-393991415 for an idea of how this would work.

Thanks Slevenick. The sample is not ready to use, but it's a foot in the door !

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

Was this page helpful?
0 / 5 - 0 ratings