GetInstance

Use this data source to get the ID of an Amazon EC2 Instance for use in other resources.

Example Usage

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var foo = Output.Create(Aws.Ec2.GetInstance.InvokeAsync(new Aws.Ec2.GetInstanceArgs
        {
            Filters = 
            {
                new Aws.Ec2.Inputs.GetInstanceFilterArgs
                {
                    Name = "image-id",
                    Values = 
                    {
                        "ami-xxxxxxxx",
                    },
                },
                new Aws.Ec2.Inputs.GetInstanceFilterArgs
                {
                    Name = "tag:Name",
                    Values = 
                    {
                        "instance-name-tag",
                    },
                },
            },
            InstanceId = "i-instanceid",
        }));
    }

}
package main

import (
    "github.com/pulumi/pulumi-aws/sdk/v2/go/aws/ec2"
    "github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)

func main() {
    pulumi.Run(func(ctx *pulumi.Context) error {
        opt0 := "i-instanceid"
        _, err := ec2.LookupInstance(ctx, &ec2.LookupInstanceArgs{
            Filters: []ec2.GetInstanceFilter{
                ec2.GetInstanceFilter{
                    Name: "image-id",
                    Values: []string{
                        "ami-xxxxxxxx",
                    },
                },
                ec2.GetInstanceFilter{
                    Name: "tag:Name",
                    Values: []string{
                        "instance-name-tag",
                    },
                },
            },
            InstanceId: &opt0,
        }, nil)
        if err != nil {
            return err
        }
        return nil
    })
}
import pulumi
import pulumi_aws as aws

foo = aws.ec2.get_instance(filters=[
        {
            "name": "image-id",
            "values": ["ami-xxxxxxxx"],
        },
        {
            "name": "tag:Name",
            "values": ["instance-name-tag"],
        },
    ],
    instance_id="i-instanceid")
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const foo = pulumi.output(aws.ec2.getInstance({
    filters: [
        {
            name: "image-id",
            values: ["ami-xxxxxxxx"],
        },
        {
            name: "tag:Name",
            values: ["instance-name-tag"],
        },
    ],
    instanceId: "i-instanceid",
}, { async: true }));

Using GetInstance

function getInstance(args: GetInstanceArgs, opts?: InvokeOptions): Promise<GetInstanceResult>
function  get_instance(filters=None, get_password_data=None, get_user_data=None, instance_id=None, instance_tags=None, tags=None, opts=None)
func LookupInstance(ctx *Context, args *LookupInstanceArgs, opts ...InvokeOption) (*LookupInstanceResult, error)

Note: This function is named LookupInstance in the Go SDK.

public static class GetInstance {
    public static Task<GetInstanceResult> InvokeAsync(GetInstanceArgs args, InvokeOptions? opts = null)
}

The following arguments are supported:

Filters List<GetInstanceFilterArgs>

One or more name/value pairs to use as filters. There are several valid keys, for a full reference, check out [describe-instances in the AWS CLI reference][1].

GetPasswordData bool

If true, wait for password data to become available and retrieve it. Useful for getting the administrator password for instances running Microsoft Windows. The password data is exported to the password_data attribute. See GetPasswordData for more information.

GetUserData bool

Retrieve Base64 encoded User Data contents into the user_data_base64 attribute. A SHA-1 hash of the User Data contents will always be present in the user_data attribute. Defaults to false.

InstanceId string

Specify the exact Instance ID with which to populate the data source.

InstanceTags Dictionary<string, string>

A map of tags, each pair of which must exactly match a pair on the desired Instance.

Tags Dictionary<string, string>

A mapping of tags assigned to the Instance.

Filters []GetInstanceFilter

One or more name/value pairs to use as filters. There are several valid keys, for a full reference, check out [describe-instances in the AWS CLI reference][1].

GetPasswordData bool

If true, wait for password data to become available and retrieve it. Useful for getting the administrator password for instances running Microsoft Windows. The password data is exported to the password_data attribute. See GetPasswordData for more information.

GetUserData bool

Retrieve Base64 encoded User Data contents into the user_data_base64 attribute. A SHA-1 hash of the User Data contents will always be present in the user_data attribute. Defaults to false.

InstanceId string

Specify the exact Instance ID with which to populate the data source.

InstanceTags map[string]string

A map of tags, each pair of which must exactly match a pair on the desired Instance.

Tags map[string]string

A mapping of tags assigned to the Instance.

filters GetInstanceFilter[]

One or more name/value pairs to use as filters. There are several valid keys, for a full reference, check out [describe-instances in the AWS CLI reference][1].

getPasswordData boolean

If true, wait for password data to become available and retrieve it. Useful for getting the administrator password for instances running Microsoft Windows. The password data is exported to the password_data attribute. See GetPasswordData for more information.

getUserData boolean

Retrieve Base64 encoded User Data contents into the user_data_base64 attribute. A SHA-1 hash of the User Data contents will always be present in the user_data attribute. Defaults to false.

instanceId string

Specify the exact Instance ID with which to populate the data source.

instanceTags {[key: string]: string}

A map of tags, each pair of which must exactly match a pair on the desired Instance.

tags {[key: string]: string}

A mapping of tags assigned to the Instance.

filters List[GetInstanceFilter]

One or more name/value pairs to use as filters. There are several valid keys, for a full reference, check out [describe-instances in the AWS CLI reference][1].

get_password_data bool

If true, wait for password data to become available and retrieve it. Useful for getting the administrator password for instances running Microsoft Windows. The password data is exported to the password_data attribute. See GetPasswordData for more information.

get_user_data bool

Retrieve Base64 encoded User Data contents into the user_data_base64 attribute. A SHA-1 hash of the User Data contents will always be present in the user_data attribute. Defaults to false.

instance_id str

Specify the exact Instance ID with which to populate the data source.

instance_tags Dict[str, str]

A map of tags, each pair of which must exactly match a pair on the desired Instance.

tags Dict[str, str]

A mapping of tags assigned to the Instance.

GetInstance Result

The following output properties are available:

Ami string

The ID of the AMI used to launch the instance.

Arn string

The ARN of the instance.

AssociatePublicIpAddress bool

Whether or not the Instance is associated with a public IP address or not (Boolean).

AvailabilityZone string

The availability zone of the Instance.

CreditSpecifications List<GetInstanceCreditSpecification>

The credit specification of the Instance.

DisableApiTermination bool
EbsBlockDevices List<GetInstanceEbsBlockDevice>

The EBS block device mappings of the Instance.

EbsOptimized bool

Whether the Instance is EBS optimized or not (Boolean).

EphemeralBlockDevices List<GetInstanceEphemeralBlockDevice>

The ephemeral block device mappings of the Instance.

HostId string

The Id of the dedicated host the instance will be assigned to.

IamInstanceProfile string

The name of the instance profile associated with the Instance.

Id string

The provider-assigned unique ID for this managed resource.

InstanceState string

The state of the instance. One of: pending, running, shutting-down, terminated, stopping, stopped. See Instance Lifecycle for more information.

InstanceTags Dictionary<string, string>
InstanceType string

The type of the Instance.

KeyName string

The key name of the Instance.

MetadataOptions List<GetInstanceMetadataOption>

The metadata options of the Instance.

Monitoring bool

Whether detailed monitoring is enabled or disabled for the Instance (Boolean).

NetworkInterfaceId string

The ID of the network interface that was created with the Instance.

OutpostArn string

The Amazon Resource Name (ARN) of the Outpost.

PasswordData string

Base-64 encoded encrypted password data for the instance. Useful for getting the administrator password for instances running Microsoft Windows. This attribute is only exported if get_password_data is true. See GetPasswordData for more information.

PlacementGroup string

The placement group of the Instance.

PrivateDns string

The private DNS name assigned to the Instance. Can only be used inside the Amazon EC2, and only available if you’ve enabled DNS hostnames for your VPC.

PrivateIp string

The private IP address assigned to the Instance.

PublicDns string

The public DNS name assigned to the Instance. For EC2-VPC, this is only available if you’ve enabled DNS hostnames for your VPC.

PublicIp string

The public IP address assigned to the Instance, if applicable. NOTE: If you are using an aws.ec2.Eip with your instance, you should refer to the EIP’s address directly and not use public_ip, as this field will change after the EIP is attached.

RootBlockDevices List<GetInstanceRootBlockDevice>

The root block device mappings of the Instance

SecurityGroups List<string>

The associated security groups.

SourceDestCheck bool

Whether the network interface performs source/destination checking (Boolean).

SubnetId string

The VPC subnet ID.

Tags Dictionary<string, string>

A mapping of tags assigned to the Instance.

Tenancy string

The tenancy of the instance: dedicated, default, host.

UserData string

SHA-1 hash of User Data supplied to the Instance.

UserDataBase64 string

Base64 encoded contents of User Data supplied to the Instance. This attribute is only exported if get_user_data is true.

VpcSecurityGroupIds List<string>

The associated security groups in a non-default VPC.

Filters List<GetInstanceFilter>
GetPasswordData bool
GetUserData bool
InstanceId string
Ami string

The ID of the AMI used to launch the instance.

Arn string

The ARN of the instance.

AssociatePublicIpAddress bool

Whether or not the Instance is associated with a public IP address or not (Boolean).

AvailabilityZone string

The availability zone of the Instance.

CreditSpecifications []GetInstanceCreditSpecification

The credit specification of the Instance.

DisableApiTermination bool
EbsBlockDevices []GetInstanceEbsBlockDevice

The EBS block device mappings of the Instance.

EbsOptimized bool

Whether the Instance is EBS optimized or not (Boolean).

EphemeralBlockDevices []GetInstanceEphemeralBlockDevice

The ephemeral block device mappings of the Instance.

HostId string

The Id of the dedicated host the instance will be assigned to.

IamInstanceProfile string

The name of the instance profile associated with the Instance.

Id string

The provider-assigned unique ID for this managed resource.

InstanceState string

The state of the instance. One of: pending, running, shutting-down, terminated, stopping, stopped. See Instance Lifecycle for more information.

InstanceTags map[string]string
InstanceType string

The type of the Instance.

KeyName string

The key name of the Instance.

MetadataOptions []GetInstanceMetadataOption

The metadata options of the Instance.

Monitoring bool

Whether detailed monitoring is enabled or disabled for the Instance (Boolean).

NetworkInterfaceId string

The ID of the network interface that was created with the Instance.

OutpostArn string

The Amazon Resource Name (ARN) of the Outpost.

PasswordData string

Base-64 encoded encrypted password data for the instance. Useful for getting the administrator password for instances running Microsoft Windows. This attribute is only exported if get_password_data is true. See GetPasswordData for more information.

PlacementGroup string

The placement group of the Instance.

PrivateDns string

The private DNS name assigned to the Instance. Can only be used inside the Amazon EC2, and only available if you’ve enabled DNS hostnames for your VPC.

PrivateIp string

The private IP address assigned to the Instance.

PublicDns string

The public DNS name assigned to the Instance. For EC2-VPC, this is only available if you’ve enabled DNS hostnames for your VPC.

PublicIp string

The public IP address assigned to the Instance, if applicable. NOTE: If you are using an aws.ec2.Eip with your instance, you should refer to the EIP’s address directly and not use public_ip, as this field will change after the EIP is attached.

RootBlockDevices []GetInstanceRootBlockDevice

The root block device mappings of the Instance

SecurityGroups []string

The associated security groups.

SourceDestCheck bool

Whether the network interface performs source/destination checking (Boolean).

SubnetId string

The VPC subnet ID.

Tags map[string]string

A mapping of tags assigned to the Instance.

Tenancy string

The tenancy of the instance: dedicated, default, host.

UserData string

SHA-1 hash of User Data supplied to the Instance.

UserDataBase64 string

Base64 encoded contents of User Data supplied to the Instance. This attribute is only exported if get_user_data is true.

VpcSecurityGroupIds []string

The associated security groups in a non-default VPC.

Filters []GetInstanceFilter
GetPasswordData bool
GetUserData bool
InstanceId string
ami string

The ID of the AMI used to launch the instance.

arn string

The ARN of the instance.

associatePublicIpAddress boolean

Whether or not the Instance is associated with a public IP address or not (Boolean).

availabilityZone string

The availability zone of the Instance.

creditSpecifications GetInstanceCreditSpecification[]

The credit specification of the Instance.

disableApiTermination boolean
ebsBlockDevices GetInstanceEbsBlockDevice[]

The EBS block device mappings of the Instance.

ebsOptimized boolean

Whether the Instance is EBS optimized or not (Boolean).

ephemeralBlockDevices GetInstanceEphemeralBlockDevice[]

The ephemeral block device mappings of the Instance.

hostId string

The Id of the dedicated host the instance will be assigned to.

iamInstanceProfile string

The name of the instance profile associated with the Instance.

id string

The provider-assigned unique ID for this managed resource.

instanceState string

The state of the instance. One of: pending, running, shutting-down, terminated, stopping, stopped. See Instance Lifecycle for more information.

instanceTags {[key: string]: string}
instanceType string

The type of the Instance.

keyName string

The key name of the Instance.

metadataOptions GetInstanceMetadataOption[]

The metadata options of the Instance.

monitoring boolean

Whether detailed monitoring is enabled or disabled for the Instance (Boolean).

networkInterfaceId string

The ID of the network interface that was created with the Instance.

outpostArn string

The Amazon Resource Name (ARN) of the Outpost.

passwordData string

Base-64 encoded encrypted password data for the instance. Useful for getting the administrator password for instances running Microsoft Windows. This attribute is only exported if get_password_data is true. See GetPasswordData for more information.

placementGroup string

The placement group of the Instance.

privateDns string

The private DNS name assigned to the Instance. Can only be used inside the Amazon EC2, and only available if you’ve enabled DNS hostnames for your VPC.

privateIp string

The private IP address assigned to the Instance.

publicDns string

The public DNS name assigned to the Instance. For EC2-VPC, this is only available if you’ve enabled DNS hostnames for your VPC.

publicIp string

The public IP address assigned to the Instance, if applicable. NOTE: If you are using an aws.ec2.Eip with your instance, you should refer to the EIP’s address directly and not use public_ip, as this field will change after the EIP is attached.

rootBlockDevices GetInstanceRootBlockDevice[]

The root block device mappings of the Instance

securityGroups string[]

The associated security groups.

sourceDestCheck boolean

Whether the network interface performs source/destination checking (Boolean).

subnetId string

The VPC subnet ID.

tags {[key: string]: string}

A mapping of tags assigned to the Instance.

tenancy string

The tenancy of the instance: dedicated, default, host.

userData string

SHA-1 hash of User Data supplied to the Instance.

userDataBase64 string

Base64 encoded contents of User Data supplied to the Instance. This attribute is only exported if get_user_data is true.

vpcSecurityGroupIds string[]

The associated security groups in a non-default VPC.

filters GetInstanceFilter[]
getPasswordData boolean
getUserData boolean
instanceId string
ami str

The ID of the AMI used to launch the instance.

arn str

The ARN of the instance.

associate_public_ip_address bool

Whether or not the Instance is associated with a public IP address or not (Boolean).

availability_zone str

The availability zone of the Instance.

credit_specifications List[GetInstanceCreditSpecification]

The credit specification of the Instance.

disable_api_termination bool
ebs_block_devices List[GetInstanceEbsBlockDevice]

The EBS block device mappings of the Instance.

ebs_optimized bool

Whether the Instance is EBS optimized or not (Boolean).

ephemeral_block_devices List[GetInstanceEphemeralBlockDevice]

The ephemeral block device mappings of the Instance.

host_id str

The Id of the dedicated host the instance will be assigned to.

iam_instance_profile str

The name of the instance profile associated with the Instance.

id str

The provider-assigned unique ID for this managed resource.

instance_state str

The state of the instance. One of: pending, running, shutting-down, terminated, stopping, stopped. See Instance Lifecycle for more information.

instance_tags Dict[str, str]
instance_type str

The type of the Instance.

key_name str

The key name of the Instance.

metadata_options List[GetInstanceMetadataOption]

The metadata options of the Instance.

monitoring bool

Whether detailed monitoring is enabled or disabled for the Instance (Boolean).

network_interface_id str

The ID of the network interface that was created with the Instance.

outpost_arn str

The Amazon Resource Name (ARN) of the Outpost.

password_data str

Base-64 encoded encrypted password data for the instance. Useful for getting the administrator password for instances running Microsoft Windows. This attribute is only exported if get_password_data is true. See GetPasswordData for more information.

placement_group str

The placement group of the Instance.

private_dns str

The private DNS name assigned to the Instance. Can only be used inside the Amazon EC2, and only available if you’ve enabled DNS hostnames for your VPC.

private_ip str

The private IP address assigned to the Instance.

public_dns str

The public DNS name assigned to the Instance. For EC2-VPC, this is only available if you’ve enabled DNS hostnames for your VPC.

public_ip str

The public IP address assigned to the Instance, if applicable. NOTE: If you are using an aws.ec2.Eip with your instance, you should refer to the EIP’s address directly and not use public_ip, as this field will change after the EIP is attached.

root_block_devices List[GetInstanceRootBlockDevice]

The root block device mappings of the Instance

security_groups List[str]

The associated security groups.

source_dest_check bool

Whether the network interface performs source/destination checking (Boolean).

subnet_id str

The VPC subnet ID.

tags Dict[str, str]

A mapping of tags assigned to the Instance.

tenancy str

The tenancy of the instance: dedicated, default, host.

user_data str

SHA-1 hash of User Data supplied to the Instance.

user_data_base64 str

Base64 encoded contents of User Data supplied to the Instance. This attribute is only exported if get_user_data is true.

vpc_security_group_ids List[str]

The associated security groups in a non-default VPC.

filters List[GetInstanceFilter]
get_password_data bool
get_user_data bool
instance_id str

Supporting Types

GetInstanceCreditSpecification

See the output API doc for this type.

See the output API doc for this type.

See the output API doc for this type.

CpuCredits string
CpuCredits string
cpuCredits string
cpuCredits str

GetInstanceEbsBlockDevice

See the output API doc for this type.

See the output API doc for this type.

See the output API doc for this type.

DeleteOnTermination bool

If the root block device will be deleted on termination.

DeviceName string

The physical name of the device.

Encrypted bool

If the EBS volume is encrypted.

Iops int

0 If the volume is not a provisioned IOPS image, otherwise the supported IOPS count.

KmsKeyId string
SnapshotId string

The ID of the snapshot.

VolumeId string
VolumeSize int

The size of the volume, in GiB.

VolumeType string

The type of the volume.

DeleteOnTermination bool

If the root block device will be deleted on termination.

DeviceName string

The physical name of the device.

Encrypted bool

If the EBS volume is encrypted.

Iops int

0 If the volume is not a provisioned IOPS image, otherwise the supported IOPS count.

KmsKeyId string
SnapshotId string

The ID of the snapshot.

VolumeId string
VolumeSize int

The size of the volume, in GiB.

VolumeType string

The type of the volume.

deleteOnTermination boolean

If the root block device will be deleted on termination.

deviceName string

The physical name of the device.

encrypted boolean

If the EBS volume is encrypted.

iops number

0 If the volume is not a provisioned IOPS image, otherwise the supported IOPS count.

kmsKeyId string
snapshotId string

The ID of the snapshot.

volumeId string
volumeSize number

The size of the volume, in GiB.

volumeType string

The type of the volume.

deleteOnTermination bool

If the root block device will be deleted on termination.

device_name str

The physical name of the device.

encrypted bool

If the EBS volume is encrypted.

iops float

0 If the volume is not a provisioned IOPS image, otherwise the supported IOPS count.

kms_key_id str
snapshot_id str

The ID of the snapshot.

volumeType str

The type of the volume.

volume_id str
volume_size float

The size of the volume, in GiB.

GetInstanceEphemeralBlockDevice

See the output API doc for this type.

See the output API doc for this type.

See the output API doc for this type.

DeviceName string

The physical name of the device.

NoDevice bool

Whether the specified device included in the device mapping was suppressed or not (Boolean).

VirtualName string

The virtual device name.

DeviceName string

The physical name of the device.

NoDevice bool

Whether the specified device included in the device mapping was suppressed or not (Boolean).

VirtualName string

The virtual device name.

deviceName string

The physical name of the device.

noDevice boolean

Whether the specified device included in the device mapping was suppressed or not (Boolean).

virtualName string

The virtual device name.

device_name str

The physical name of the device.

noDevice bool

Whether the specified device included in the device mapping was suppressed or not (Boolean).

virtualName str

The virtual device name.

GetInstanceFilter

See the input and output API doc for this type.

See the input and output API doc for this type.

See the input and output API doc for this type.

Name string
Values List<string>
Name string
Values []string
name string
values string[]
name str
values List[str]

GetInstanceMetadataOption

See the output API doc for this type.

See the output API doc for this type.

See the output API doc for this type.

HttpEndpoint string

The state of the metadata service: enabled, disabled.

HttpPutResponseHopLimit int

The desired HTTP PUT response hop limit for instance metadata requests.

HttpTokens string

If session tokens are required: optional, required.

HttpEndpoint string

The state of the metadata service: enabled, disabled.

HttpPutResponseHopLimit int

The desired HTTP PUT response hop limit for instance metadata requests.

HttpTokens string

If session tokens are required: optional, required.

httpEndpoint string

The state of the metadata service: enabled, disabled.

httpPutResponseHopLimit number

The desired HTTP PUT response hop limit for instance metadata requests.

httpTokens string

If session tokens are required: optional, required.

httpEndpoint str

The state of the metadata service: enabled, disabled.

httpPutResponseHopLimit float

The desired HTTP PUT response hop limit for instance metadata requests.

httpTokens str

If session tokens are required: optional, required.

GetInstanceRootBlockDevice

See the output API doc for this type.

See the output API doc for this type.

See the output API doc for this type.

DeleteOnTermination bool

If the root block device will be deleted on termination.

DeviceName string

The physical name of the device.

Encrypted bool

If the EBS volume is encrypted.

Iops int

0 If the volume is not a provisioned IOPS image, otherwise the supported IOPS count.

KmsKeyId string
VolumeId string
VolumeSize int

The size of the volume, in GiB.

VolumeType string

The type of the volume.

DeleteOnTermination bool

If the root block device will be deleted on termination.

DeviceName string

The physical name of the device.

Encrypted bool

If the EBS volume is encrypted.

Iops int

0 If the volume is not a provisioned IOPS image, otherwise the supported IOPS count.

KmsKeyId string
VolumeId string
VolumeSize int

The size of the volume, in GiB.

VolumeType string

The type of the volume.

deleteOnTermination boolean

If the root block device will be deleted on termination.

deviceName string

The physical name of the device.

encrypted boolean

If the EBS volume is encrypted.

iops number

0 If the volume is not a provisioned IOPS image, otherwise the supported IOPS count.

kmsKeyId string
volumeId string
volumeSize number

The size of the volume, in GiB.

volumeType string

The type of the volume.

deleteOnTermination bool

If the root block device will be deleted on termination.

device_name str

The physical name of the device.

encrypted bool

If the EBS volume is encrypted.

iops float

0 If the volume is not a provisioned IOPS image, otherwise the supported IOPS count.

kms_key_id str
volumeType str

The type of the volume.

volume_id str
volume_size float

The size of the volume, in GiB.

Package Details

Repository
https://github.com/pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.