Google Cloud Classic v7.29.0 published on Wednesday, Jun 26, 2024 by Pulumi
gcp.compute.getInstanceSerialPort
Explore with Pulumi AI
Get the serial port output from a Compute Instance. For more information see the official API documentation.
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const serial = gcp.compute.getInstanceSerialPort({
instance: "my-instance",
zone: "us-central1-a",
port: 1,
});
export const serialOut = serial.then(serial => serial.contents);
import pulumi
import pulumi_gcp as gcp
serial = gcp.compute.get_instance_serial_port(instance="my-instance",
zone="us-central1-a",
port=1)
pulumi.export("serialOut", serial.contents)
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/compute"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
serial, err := compute.GetInstanceSerialPort(ctx, &compute.GetInstanceSerialPortArgs{
Instance: "my-instance",
Zone: pulumi.StringRef("us-central1-a"),
Port: 1,
}, nil)
if err != nil {
return err
}
ctx.Export("serialOut", serial.Contents)
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var serial = Gcp.Compute.GetInstanceSerialPort.Invoke(new()
{
Instance = "my-instance",
Zone = "us-central1-a",
Port = 1,
});
return new Dictionary<string, object?>
{
["serialOut"] = serial.Apply(getInstanceSerialPortResult => getInstanceSerialPortResult.Contents),
};
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.ComputeFunctions;
import com.pulumi.gcp.compute.inputs.GetInstanceSerialPortArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
final var serial = ComputeFunctions.getInstanceSerialPort(GetInstanceSerialPortArgs.builder()
.instance("my-instance")
.zone("us-central1-a")
.port(1)
.build());
ctx.export("serialOut", serial.applyValue(getInstanceSerialPortResult -> getInstanceSerialPortResult.contents()));
}
}
variables:
serial:
fn::invoke:
Function: gcp:compute:getInstanceSerialPort
Arguments:
instance: my-instance
zone: us-central1-a
port: 1
outputs:
serialOut: ${serial.contents}
Using the serial port output to generate a windows password, derived from the official guide:
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const windows = new gcp.compute.Instance("windows", {
networkInterfaces: [{
accessConfigs: [{}],
network: "default",
}],
name: "windows-instance",
machineType: "e2-medium",
zone: "us-central1-a",
bootDisk: {
initializeParams: {
image: "windows-cloud/windows-2019",
},
},
metadata: {
"serial-port-logging-enable": "TRUE",
"windows-keys": JSON.stringify({
email: "example.user@example.com",
expireOn: "2020-04-14T01:37:19Z",
exponent: "AQAB",
modulus: "wgsquN4IBNPqIUnu+h/5Za1kujb2YRhX1vCQVQAkBwnWigcCqOBVfRa5JoZfx6KIvEXjWqa77jPvlsxM4WPqnDIM2qiK36up3SKkYwFjff6F2ni/ry8vrwXCX3sGZ1hbIHlK0O012HpA3ISeEswVZmX2X67naOvJXfY5v0hGPWqCADao+xVxrmxsZD4IWnKl1UaZzI5lhAzr8fw6utHwx1EZ/MSgsEki6tujcZfN+GUDRnmJGQSnPTXmsf7Q4DKreTZk49cuyB3prV91S0x3DYjCUpSXrkVy1Ha5XicGD/q+ystuFsJnrrhbNXJbpSjM6sjo/aduAkZJl4FmOt0R7Q==",
userName: "example-user",
}),
},
serviceAccount: {
scopes: [
"userinfo-email",
"compute-ro",
"storage-ro",
],
},
});
const serial = pulumi.all([windows.name, windows.zone]).apply(([name, zone]) => gcp.compute.getInstanceSerialPortOutput({
instance: name,
zone: zone,
port: 4,
}));
export const serialOut = serial.apply(serial => serial.contents);
import pulumi
import json
import pulumi_gcp as gcp
windows = gcp.compute.Instance("windows",
network_interfaces=[gcp.compute.InstanceNetworkInterfaceArgs(
access_configs=[gcp.compute.InstanceNetworkInterfaceAccessConfigArgs()],
network="default",
)],
name="windows-instance",
machine_type="e2-medium",
zone="us-central1-a",
boot_disk=gcp.compute.InstanceBootDiskArgs(
initialize_params=gcp.compute.InstanceBootDiskInitializeParamsArgs(
image="windows-cloud/windows-2019",
),
),
metadata={
"serial-port-logging-enable": "TRUE",
"windows-keys": json.dumps({
"email": "example.user@example.com",
"expireOn": "2020-04-14T01:37:19Z",
"exponent": "AQAB",
"modulus": "wgsquN4IBNPqIUnu+h/5Za1kujb2YRhX1vCQVQAkBwnWigcCqOBVfRa5JoZfx6KIvEXjWqa77jPvlsxM4WPqnDIM2qiK36up3SKkYwFjff6F2ni/ry8vrwXCX3sGZ1hbIHlK0O012HpA3ISeEswVZmX2X67naOvJXfY5v0hGPWqCADao+xVxrmxsZD4IWnKl1UaZzI5lhAzr8fw6utHwx1EZ/MSgsEki6tujcZfN+GUDRnmJGQSnPTXmsf7Q4DKreTZk49cuyB3prV91S0x3DYjCUpSXrkVy1Ha5XicGD/q+ystuFsJnrrhbNXJbpSjM6sjo/aduAkZJl4FmOt0R7Q==",
"userName": "example-user",
}),
},
service_account=gcp.compute.InstanceServiceAccountArgs(
scopes=[
"userinfo-email",
"compute-ro",
"storage-ro",
],
))
serial = pulumi.Output.all(windows.name, windows.zone).apply(lambda name, zone: gcp.compute.get_instance_serial_port_output(instance=name,
zone=zone,
port=4))
pulumi.export("serialOut", serial.contents)
package main
import (
"encoding/json"
"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/compute"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
tmpJSON0, err := json.Marshal(map[string]interface{}{
"email": "example.user@example.com",
"expireOn": "2020-04-14T01:37:19Z",
"exponent": "AQAB",
"modulus": "wgsquN4IBNPqIUnu+h/5Za1kujb2YRhX1vCQVQAkBwnWigcCqOBVfRa5JoZfx6KIvEXjWqa77jPvlsxM4WPqnDIM2qiK36up3SKkYwFjff6F2ni/ry8vrwXCX3sGZ1hbIHlK0O012HpA3ISeEswVZmX2X67naOvJXfY5v0hGPWqCADao+xVxrmxsZD4IWnKl1UaZzI5lhAzr8fw6utHwx1EZ/MSgsEki6tujcZfN+GUDRnmJGQSnPTXmsf7Q4DKreTZk49cuyB3prV91S0x3DYjCUpSXrkVy1Ha5XicGD/q+ystuFsJnrrhbNXJbpSjM6sjo/aduAkZJl4FmOt0R7Q==",
"userName": "example-user",
})
if err != nil {
return err
}
json0 := string(tmpJSON0)
windows, err := compute.NewInstance(ctx, "windows", &compute.InstanceArgs{
NetworkInterfaces: compute.InstanceNetworkInterfaceArray{
&compute.InstanceNetworkInterfaceArgs{
AccessConfigs: compute.InstanceNetworkInterfaceAccessConfigArray{
nil,
},
Network: pulumi.String("default"),
},
},
Name: pulumi.String("windows-instance"),
MachineType: pulumi.String("e2-medium"),
Zone: pulumi.String("us-central1-a"),
BootDisk: &compute.InstanceBootDiskArgs{
InitializeParams: &compute.InstanceBootDiskInitializeParamsArgs{
Image: pulumi.String("windows-cloud/windows-2019"),
},
},
Metadata: pulumi.StringMap{
"serial-port-logging-enable": pulumi.String("TRUE"),
"windows-keys": pulumi.String(json0),
},
ServiceAccount: &compute.InstanceServiceAccountArgs{
Scopes: pulumi.StringArray{
pulumi.String("userinfo-email"),
pulumi.String("compute-ro"),
pulumi.String("storage-ro"),
},
},
})
if err != nil {
return err
}
serial := pulumi.All(windows.Name, windows.Zone).ApplyT(func(_args []interface{}) (compute.GetInstanceSerialPortResult, error) {
name := _args[0].(string)
zone := _args[1].(string)
return compute.GetInstanceSerialPortOutput(ctx, compute.GetInstanceSerialPortOutputArgs{
Instance: name,
Zone: zone,
Port: 4,
}, nil), nil
}).(compute.GetInstanceSerialPortResultOutput)
ctx.Export("serialOut", serial.ApplyT(func(serial compute.GetInstanceSerialPortResult) (*string, error) {
return &serial.Contents, nil
}).(pulumi.StringPtrOutput))
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var windows = new Gcp.Compute.Instance("windows", new()
{
NetworkInterfaces = new[]
{
new Gcp.Compute.Inputs.InstanceNetworkInterfaceArgs
{
AccessConfigs = new[]
{
null,
},
Network = "default",
},
},
Name = "windows-instance",
MachineType = "e2-medium",
Zone = "us-central1-a",
BootDisk = new Gcp.Compute.Inputs.InstanceBootDiskArgs
{
InitializeParams = new Gcp.Compute.Inputs.InstanceBootDiskInitializeParamsArgs
{
Image = "windows-cloud/windows-2019",
},
},
Metadata =
{
{ "serial-port-logging-enable", "TRUE" },
{ "windows-keys", JsonSerializer.Serialize(new Dictionary<string, object?>
{
["email"] = "example.user@example.com",
["expireOn"] = "2020-04-14T01:37:19Z",
["exponent"] = "AQAB",
["modulus"] = "wgsquN4IBNPqIUnu+h/5Za1kujb2YRhX1vCQVQAkBwnWigcCqOBVfRa5JoZfx6KIvEXjWqa77jPvlsxM4WPqnDIM2qiK36up3SKkYwFjff6F2ni/ry8vrwXCX3sGZ1hbIHlK0O012HpA3ISeEswVZmX2X67naOvJXfY5v0hGPWqCADao+xVxrmxsZD4IWnKl1UaZzI5lhAzr8fw6utHwx1EZ/MSgsEki6tujcZfN+GUDRnmJGQSnPTXmsf7Q4DKreTZk49cuyB3prV91S0x3DYjCUpSXrkVy1Ha5XicGD/q+ystuFsJnrrhbNXJbpSjM6sjo/aduAkZJl4FmOt0R7Q==",
["userName"] = "example-user",
}) },
},
ServiceAccount = new Gcp.Compute.Inputs.InstanceServiceAccountArgs
{
Scopes = new[]
{
"userinfo-email",
"compute-ro",
"storage-ro",
},
},
});
var serial = Gcp.Compute.GetInstanceSerialPort.Invoke(new()
{
Instance = windows.Name,
Zone = windows.Zone,
Port = 4,
});
return new Dictionary<string, object?>
{
["serialOut"] = serial.Apply(getInstanceSerialPortResult => getInstanceSerialPortResult.Contents),
};
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.Instance;
import com.pulumi.gcp.compute.InstanceArgs;
import com.pulumi.gcp.compute.inputs.InstanceNetworkInterfaceArgs;
import com.pulumi.gcp.compute.inputs.InstanceBootDiskArgs;
import com.pulumi.gcp.compute.inputs.InstanceBootDiskInitializeParamsArgs;
import com.pulumi.gcp.compute.inputs.InstanceServiceAccountArgs;
import com.pulumi.gcp.compute.ComputeFunctions;
import com.pulumi.gcp.compute.inputs.GetInstanceSerialPortArgs;
import static com.pulumi.codegen.internal.Serialization.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var windows = new Instance("windows", InstanceArgs.builder()
.networkInterfaces(InstanceNetworkInterfaceArgs.builder()
.accessConfigs()
.network("default")
.build())
.name("windows-instance")
.machineType("e2-medium")
.zone("us-central1-a")
.bootDisk(InstanceBootDiskArgs.builder()
.initializeParams(InstanceBootDiskInitializeParamsArgs.builder()
.image("windows-cloud/windows-2019")
.build())
.build())
.metadata(Map.ofEntries(
Map.entry("serial-port-logging-enable", "TRUE"),
Map.entry("windows-keys", serializeJson(
jsonObject(
jsonProperty("email", "example.user@example.com"),
jsonProperty("expireOn", "2020-04-14T01:37:19Z"),
jsonProperty("exponent", "AQAB"),
jsonProperty("modulus", "wgsquN4IBNPqIUnu+h/5Za1kujb2YRhX1vCQVQAkBwnWigcCqOBVfRa5JoZfx6KIvEXjWqa77jPvlsxM4WPqnDIM2qiK36up3SKkYwFjff6F2ni/ry8vrwXCX3sGZ1hbIHlK0O012HpA3ISeEswVZmX2X67naOvJXfY5v0hGPWqCADao+xVxrmxsZD4IWnKl1UaZzI5lhAzr8fw6utHwx1EZ/MSgsEki6tujcZfN+GUDRnmJGQSnPTXmsf7Q4DKreTZk49cuyB3prV91S0x3DYjCUpSXrkVy1Ha5XicGD/q+ystuFsJnrrhbNXJbpSjM6sjo/aduAkZJl4FmOt0R7Q=="),
jsonProperty("userName", "example-user")
)))
))
.serviceAccount(InstanceServiceAccountArgs.builder()
.scopes(
"userinfo-email",
"compute-ro",
"storage-ro")
.build())
.build());
final var serial = ComputeFunctions.getInstanceSerialPort(GetInstanceSerialPortArgs.builder()
.instance(windows.name())
.zone(windows.zone())
.port(4)
.build());
ctx.export("serialOut", serial.applyValue(getInstanceSerialPortResult -> getInstanceSerialPortResult).applyValue(serial -> serial.applyValue(getInstanceSerialPortResult -> getInstanceSerialPortResult.contents())));
}
}
resources:
windows:
type: gcp:compute:Instance
properties:
networkInterfaces:
- accessConfigs:
- {}
network: default
name: windows-instance
machineType: e2-medium
zone: us-central1-a
bootDisk:
initializeParams:
image: windows-cloud/windows-2019
metadata:
serial-port-logging-enable: TRUE
windows-keys:
fn::toJSON:
email: example.user@example.com
expireOn: 2020-04-14T01:37:19Z
exponent: AQAB
modulus: wgsquN4IBNPqIUnu+h/5Za1kujb2YRhX1vCQVQAkBwnWigcCqOBVfRa5JoZfx6KIvEXjWqa77jPvlsxM4WPqnDIM2qiK36up3SKkYwFjff6F2ni/ry8vrwXCX3sGZ1hbIHlK0O012HpA3ISeEswVZmX2X67naOvJXfY5v0hGPWqCADao+xVxrmxsZD4IWnKl1UaZzI5lhAzr8fw6utHwx1EZ/MSgsEki6tujcZfN+GUDRnmJGQSnPTXmsf7Q4DKreTZk49cuyB3prV91S0x3DYjCUpSXrkVy1Ha5XicGD/q+ystuFsJnrrhbNXJbpSjM6sjo/aduAkZJl4FmOt0R7Q==
userName: example-user
serviceAccount:
scopes:
- userinfo-email
- compute-ro
- storage-ro
variables:
serial:
fn::invoke:
Function: gcp:compute:getInstanceSerialPort
Arguments:
instance: ${windows.name}
zone: ${windows.zone}
port: 4
outputs:
serialOut: ${serial.contents}
Using getInstanceSerialPort
Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.
function getInstanceSerialPort(args: GetInstanceSerialPortArgs, opts?: InvokeOptions): Promise<GetInstanceSerialPortResult>
function getInstanceSerialPortOutput(args: GetInstanceSerialPortOutputArgs, opts?: InvokeOptions): Output<GetInstanceSerialPortResult>
def get_instance_serial_port(instance: Optional[str] = None,
port: Optional[int] = None,
project: Optional[str] = None,
zone: Optional[str] = None,
opts: Optional[InvokeOptions] = None) -> GetInstanceSerialPortResult
def get_instance_serial_port_output(instance: Optional[pulumi.Input[str]] = None,
port: Optional[pulumi.Input[int]] = None,
project: Optional[pulumi.Input[str]] = None,
zone: Optional[pulumi.Input[str]] = None,
opts: Optional[InvokeOptions] = None) -> Output[GetInstanceSerialPortResult]
func GetInstanceSerialPort(ctx *Context, args *GetInstanceSerialPortArgs, opts ...InvokeOption) (*GetInstanceSerialPortResult, error)
func GetInstanceSerialPortOutput(ctx *Context, args *GetInstanceSerialPortOutputArgs, opts ...InvokeOption) GetInstanceSerialPortResultOutput
> Note: This function is named GetInstanceSerialPort
in the Go SDK.
public static class GetInstanceSerialPort
{
public static Task<GetInstanceSerialPortResult> InvokeAsync(GetInstanceSerialPortArgs args, InvokeOptions? opts = null)
public static Output<GetInstanceSerialPortResult> Invoke(GetInstanceSerialPortInvokeArgs args, InvokeOptions? opts = null)
}
public static CompletableFuture<GetInstanceSerialPortResult> getInstanceSerialPort(GetInstanceSerialPortArgs args, InvokeOptions options)
// Output-based functions aren't available in Java yet
fn::invoke:
function: gcp:compute/getInstanceSerialPort:getInstanceSerialPort
arguments:
# arguments dictionary
The following arguments are supported:
- Instance string
- The name of the Compute Instance to read output from.
- Port int
- The number of the serial port to read output from. Possible values are 1-4.
- Project string
- The project in which the Compute Instance exists. If it is not provided, the provider project is used.
- Zone string
- The zone in which the Compute Instance exists. If it is not provided, the provider zone is used.
- Instance string
- The name of the Compute Instance to read output from.
- Port int
- The number of the serial port to read output from. Possible values are 1-4.
- Project string
- The project in which the Compute Instance exists. If it is not provided, the provider project is used.
- Zone string
- The zone in which the Compute Instance exists. If it is not provided, the provider zone is used.
- instance String
- The name of the Compute Instance to read output from.
- port Integer
- The number of the serial port to read output from. Possible values are 1-4.
- project String
- The project in which the Compute Instance exists. If it is not provided, the provider project is used.
- zone String
- The zone in which the Compute Instance exists. If it is not provided, the provider zone is used.
- instance string
- The name of the Compute Instance to read output from.
- port number
- The number of the serial port to read output from. Possible values are 1-4.
- project string
- The project in which the Compute Instance exists. If it is not provided, the provider project is used.
- zone string
- The zone in which the Compute Instance exists. If it is not provided, the provider zone is used.
- instance str
- The name of the Compute Instance to read output from.
- port int
- The number of the serial port to read output from. Possible values are 1-4.
- project str
- The project in which the Compute Instance exists. If it is not provided, the provider project is used.
- zone str
- The zone in which the Compute Instance exists. If it is not provided, the provider zone is used.
- instance String
- The name of the Compute Instance to read output from.
- port Number
- The number of the serial port to read output from. Possible values are 1-4.
- project String
- The project in which the Compute Instance exists. If it is not provided, the provider project is used.
- zone String
- The zone in which the Compute Instance exists. If it is not provided, the provider zone is used.
getInstanceSerialPort Result
The following output properties are available:
Package Details
- Repository
- Google Cloud (GCP) Classic pulumi/pulumi-gcp
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
google-beta
Terraform Provider.