Skip to content

googleComputeInstanceSerialPort

Get the serial port output from a Compute Instance. For more information see the official API documentation.

Example Usage

import * as cdktf from "cdktf";
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const dataGoogleComputeInstanceSerialPortSerial =
  new google.dataGoogleComputeInstanceSerialPort.DataGoogleComputeInstanceSerialPort(
    this,
    "serial",
    {
      instance: "my-instance",
      port: 1,
      zone: "us-central1-a",
    }
  );
new cdktf.TerraformOutput(this, "serial_out", {
  value: dataGoogleComputeInstanceSerialPortSerial.contents,
});

Using the serial port output to generate a windows password, derived from the official guide:

import * as cdktf from "cdktf";
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleComputeInstanceWindows = new google.computeInstance.ComputeInstance(
  this,
  "windows",
  {
    boot_disk: [
      {
        initialize_params: [
          {
            image: "windows-cloud/windows-2019",
          },
        ],
      },
    ],
    machine_type: "e2-medium",
    metadata: [
      {
        "serial-port-logging-enable": "TRUE",
        "windows-keys":
          '${jsonencode(\n      {\n        email    = "example.user@example.com"\n        expireOn = "2020-04-14T01:37:19Z"\n        exponent = "AQAB"\n        modulus  = "wgsquN4IBNPqIUnu+h/5Za1kujb2YRhX1vCQVQAkBwnWigcCqOBVfRa5JoZfx6KIvEXjWqa77jPvlsxM4WPqnDIM2qiK36up3SKkYwFjff6F2ni/ry8vrwXCX3sGZ1hbIHlK0O012HpA3ISeEswVZmX2X67naOvJXfY5v0hGPWqCADao+xVxrmxsZD4IWnKl1UaZzI5lhAzr8fw6utHwx1EZ/MSgsEki6tujcZfN+GUDRnmJGQSnPTXmsf7Q4DKreTZk49cuyB3prV91S0x3DYjCUpSXrkVy1Ha5XicGD/q+ystuFsJnrrhbNXJbpSjM6sjo/aduAkZJl4FmOt0R7Q=="\n        userName = "example-user"\n      }\n    )}',
      },
    ],
    name: "windows-instance",
    network_interface: [
      {
        access_config: [{}],
        network: "default",
      },
    ],
    service_account: [
      {
        scopes: ["userinfo-email", "compute-ro", "storage-ro"],
      },
    ],
    zone: "us-central1-a",
  }
);
const dataGoogleComputeInstanceSerialPortSerial =
  new google.dataGoogleComputeInstanceSerialPort.DataGoogleComputeInstanceSerialPort(
    this,
    "serial",
    {
      instance: googleComputeInstanceWindows.name,
      port: 4,
      zone: googleComputeInstanceWindows.zone,
    }
  );
new cdktf.TerraformOutput(this, "serial_out", {
  value: dataGoogleComputeInstanceSerialPortSerial.contents,
});

Argument Reference

The following arguments are supported:

  • instance - (Required) The name of the Compute Instance to read output from.

  • port - (Required) The number of the serial port to read output from. Possible values are 1-4.


  • project - (Optional) The project in which the Compute Instance exists. If it is not provided, the provider project is used.

  • zone - (Optional) The zone in which the Compute Instance exists. If it is not provided, the provider zone is used.

Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

  • contents - The output of the serial port. Serial port output is available only when the VM instance is running, and logs are limited to the most recent 1 MB of output per port.