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
LookupInstancein the Go SDK.
public static class GetInstance {
public static Task<GetInstanceResult> InvokeAsync(GetInstanceArgs args, InvokeOptions? opts = null)
}The following arguments are supported:
- Filters
List<Get
Instance Filter Args> 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 boolData 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_dataattribute. See GetPasswordData for more information.- Get
User boolData Retrieve Base64 encoded User Data contents into the
user_data_base64attribute. A SHA-1 hash of the User Data contents will always be present in theuser_dataattribute. Defaults tofalse.- Instance
Id string Specify the exact Instance ID with which to populate the data source.
- Dictionary<string, string>
A map of tags, each pair of which must exactly match a pair on the desired Instance.
- Dictionary<string, string>
A mapping of tags assigned to the Instance.
- Filters
[]Get
Instance Filter 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 boolData 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_dataattribute. See GetPasswordData for more information.- Get
User boolData Retrieve Base64 encoded User Data contents into the
user_data_base64attribute. A SHA-1 hash of the User Data contents will always be present in theuser_dataattribute. Defaults tofalse.- Instance
Id string Specify the exact Instance ID with which to populate the data source.
- map[string]string
A map of tags, each pair of which must exactly match a pair on the desired Instance.
- map[string]string
A mapping of tags assigned to the Instance.
- filters
Get
Instance Filter[] 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 booleanData 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_dataattribute. See GetPasswordData for more information.- get
User booleanData Retrieve Base64 encoded User Data contents into the
user_data_base64attribute. A SHA-1 hash of the User Data contents will always be present in theuser_dataattribute. Defaults tofalse.- instance
Id string Specify the exact Instance ID with which to populate the data source.
- {[key: string]: string}
A map of tags, each pair of which must exactly match a pair on the desired Instance.
- {[key: string]: string}
A mapping of tags assigned to the Instance.
- filters
List[Get
Instance Filter] 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_ booldata 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_dataattribute. See GetPasswordData for more information.- get_
user_ booldata Retrieve Base64 encoded User Data contents into the
user_data_base64attribute. A SHA-1 hash of the User Data contents will always be present in theuser_dataattribute. Defaults tofalse.- instance_
id str Specify the exact Instance ID with which to populate the data source.
- Dict[str, str]
A map of tags, each pair of which must exactly match a pair on the desired Instance.
- 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.
- Associate
Public boolIp Address Whether or not the Instance is associated with a public IP address or not (Boolean).
- Availability
Zone string The availability zone of the Instance.
- Credit
Specifications List<GetInstance Credit Specification> The credit specification of the Instance.
- Disable
Api boolTermination - Ebs
Block List<GetDevices Instance Ebs Block Device> The EBS block device mappings of the Instance.
- Ebs
Optimized bool Whether the Instance is EBS optimized or not (Boolean).
- Ephemeral
Block List<GetDevices Instance Ephemeral Block Device> The ephemeral block device mappings of the Instance.
- Host
Id string The Id of the dedicated host the instance will be assigned to.
- Iam
Instance stringProfile The name of the instance profile associated with the Instance.
- Id string
The provider-assigned unique ID for this managed resource.
- Instance
State string The state of the instance. One of:
pending,running,shutting-down,terminated,stopping,stopped. See Instance Lifecycle for more information.- Dictionary<string, string>
- Instance
Type string The type of the Instance.
- Key
Name string The key name of the Instance.
- Metadata
Options List<GetInstance Metadata Option> The metadata options of the Instance.
- Monitoring bool
Whether detailed monitoring is enabled or disabled for the Instance (Boolean).
- Network
Interface stringId The ID of the network interface that was created with the Instance.
- Outpost
Arn string The Amazon Resource Name (ARN) of the Outpost.
- Password
Data 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_datais true. See GetPasswordData for more information.- Placement
Group string The placement group of the Instance.
- Private
Dns 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.
- Private
Ip string The private IP address assigned to the Instance.
- Public
Dns 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.
- Public
Ip string The public IP address assigned to the Instance, if applicable. NOTE: If you are using an
aws.ec2.Eipwith your instance, you should refer to the EIP’s address directly and not usepublic_ip, as this field will change after the EIP is attached.- Root
Block List<GetDevices Instance Root Block Device> The root block device mappings of the Instance
- Security
Groups List<string> The associated security groups.
- Source
Dest boolCheck Whether the network interface performs source/destination checking (Boolean).
- Subnet
Id string The VPC subnet ID.
- Dictionary<string, string>
A mapping of tags assigned to the Instance.
- Tenancy string
The tenancy of the instance:
dedicated,default,host.- User
Data string SHA-1 hash of User Data supplied to the Instance.
- User
Data stringBase64 Base64 encoded contents of User Data supplied to the Instance. This attribute is only exported if
get_user_datais true.- Vpc
Security List<string>Group Ids The associated security groups in a non-default VPC.
- Filters
List<Get
Instance Filter> - Get
Password boolData - Get
User boolData - Instance
Id string
- Ami string
The ID of the AMI used to launch the instance.
- Arn string
The ARN of the instance.
- Associate
Public boolIp Address Whether or not the Instance is associated with a public IP address or not (Boolean).
- Availability
Zone string The availability zone of the Instance.
- Credit
Specifications []GetInstance Credit Specification The credit specification of the Instance.
- Disable
Api boolTermination - Ebs
Block []GetDevices Instance Ebs Block Device The EBS block device mappings of the Instance.
- Ebs
Optimized bool Whether the Instance is EBS optimized or not (Boolean).
- Ephemeral
Block []GetDevices Instance Ephemeral Block Device The ephemeral block device mappings of the Instance.
- Host
Id string The Id of the dedicated host the instance will be assigned to.
- Iam
Instance stringProfile The name of the instance profile associated with the Instance.
- Id string
The provider-assigned unique ID for this managed resource.
- Instance
State string The state of the instance. One of:
pending,running,shutting-down,terminated,stopping,stopped. See Instance Lifecycle for more information.- map[string]string
- Instance
Type string The type of the Instance.
- Key
Name string The key name of the Instance.
- Metadata
Options []GetInstance Metadata Option The metadata options of the Instance.
- Monitoring bool
Whether detailed monitoring is enabled or disabled for the Instance (Boolean).
- Network
Interface stringId The ID of the network interface that was created with the Instance.
- Outpost
Arn string The Amazon Resource Name (ARN) of the Outpost.
- Password
Data 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_datais true. See GetPasswordData for more information.- Placement
Group string The placement group of the Instance.
- Private
Dns 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.
- Private
Ip string The private IP address assigned to the Instance.
- Public
Dns 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.
- Public
Ip string The public IP address assigned to the Instance, if applicable. NOTE: If you are using an
aws.ec2.Eipwith your instance, you should refer to the EIP’s address directly and not usepublic_ip, as this field will change after the EIP is attached.- Root
Block []GetDevices Instance Root Block Device The root block device mappings of the Instance
- Security
Groups []string The associated security groups.
- Source
Dest boolCheck Whether the network interface performs source/destination checking (Boolean).
- Subnet
Id string The VPC subnet ID.
- map[string]string
A mapping of tags assigned to the Instance.
- Tenancy string
The tenancy of the instance:
dedicated,default,host.- User
Data string SHA-1 hash of User Data supplied to the Instance.
- User
Data stringBase64 Base64 encoded contents of User Data supplied to the Instance. This attribute is only exported if
get_user_datais true.- Vpc
Security []stringGroup Ids The associated security groups in a non-default VPC.
- Filters
[]Get
Instance Filter - Get
Password boolData - Get
User boolData - Instance
Id string
- ami string
The ID of the AMI used to launch the instance.
- arn string
The ARN of the instance.
- associate
Public booleanIp Address Whether or not the Instance is associated with a public IP address or not (Boolean).
- availability
Zone string The availability zone of the Instance.
- credit
Specifications GetInstance Credit Specification[] The credit specification of the Instance.
- disable
Api booleanTermination - ebs
Block GetDevices Instance Ebs Block Device[] The EBS block device mappings of the Instance.
- ebs
Optimized boolean Whether the Instance is EBS optimized or not (Boolean).
- ephemeral
Block GetDevices Instance Ephemeral Block Device[] The ephemeral block device mappings of the Instance.
- host
Id string The Id of the dedicated host the instance will be assigned to.
- iam
Instance stringProfile The name of the instance profile associated with the Instance.
- id string
The provider-assigned unique ID for this managed resource.
- instance
State string The state of the instance. One of:
pending,running,shutting-down,terminated,stopping,stopped. See Instance Lifecycle for more information.- {[key: string]: string}
- instance
Type string The type of the Instance.
- key
Name string The key name of the Instance.
- metadata
Options GetInstance Metadata Option[] The metadata options of the Instance.
- monitoring boolean
Whether detailed monitoring is enabled or disabled for the Instance (Boolean).
- network
Interface stringId The ID of the network interface that was created with the Instance.
- outpost
Arn string The Amazon Resource Name (ARN) of the Outpost.
- password
Data 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_datais true. See GetPasswordData for more information.- placement
Group string The placement group of the Instance.
- private
Dns 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.
- private
Ip string The private IP address assigned to the Instance.
- public
Dns 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.
- public
Ip string The public IP address assigned to the Instance, if applicable. NOTE: If you are using an
aws.ec2.Eipwith your instance, you should refer to the EIP’s address directly and not usepublic_ip, as this field will change after the EIP is attached.- root
Block GetDevices Instance Root Block Device[] The root block device mappings of the Instance
- security
Groups string[] The associated security groups.
- source
Dest booleanCheck Whether the network interface performs source/destination checking (Boolean).
- subnet
Id string The VPC subnet ID.
- {[key: string]: string}
A mapping of tags assigned to the Instance.
- tenancy string
The tenancy of the instance:
dedicated,default,host.- user
Data string SHA-1 hash of User Data supplied to the Instance.
- user
Data stringBase64 Base64 encoded contents of User Data supplied to the Instance. This attribute is only exported if
get_user_datais true.- vpc
Security string[]Group Ids The associated security groups in a non-default VPC.
- filters
Get
Instance Filter[] - get
Password booleanData - get
User booleanData - instance
Id string
- ami str
The ID of the AMI used to launch the instance.
- arn str
The ARN of the instance.
- associate_
public_ boolip_ address 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[GetInstance Credit Specification] The credit specification of the Instance.
- disable_
api_ booltermination - ebs_
block_ List[Getdevices Instance Ebs Block Device] The EBS block device mappings of the Instance.
- ebs_
optimized bool Whether the Instance is EBS optimized or not (Boolean).
- ephemeral_
block_ List[Getdevices Instance Ephemeral Block Device] 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_ strprofile 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.- Dict[str, str]
- instance_
type str The type of the Instance.
- key_
name str The key name of the Instance.
- metadata_
options List[GetInstance Metadata Option] The metadata options of the Instance.
- monitoring bool
Whether detailed monitoring is enabled or disabled for the Instance (Boolean).
- network_
interface_ strid 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_datais 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.Eipwith your instance, you should refer to the EIP’s address directly and not usepublic_ip, as this field will change after the EIP is attached.- root_
block_ List[Getdevices Instance Root Block Device] The root block device mappings of the Instance
- security_
groups List[str] The associated security groups.
- source_
dest_ boolcheck Whether the network interface performs source/destination checking (Boolean).
- subnet_
id str The VPC subnet ID.
- 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_ strbase64 Base64 encoded contents of User Data supplied to the Instance. This attribute is only exported if
get_user_datais true.- vpc_
security_ List[str]group_ ids The associated security groups in a non-default VPC.
- filters
List[Get
Instance Filter] - get_
password_ booldata - get_
user_ booldata - 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.
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.
- Delete
On boolTermination If the root block device will be deleted on termination.
- Device
Name string The physical name of the device.
- Encrypted bool
If the EBS volume is encrypted.
- Iops int
0If the volume is not a provisioned IOPS image, otherwise the supported IOPS count.- Kms
Key stringId - Snapshot
Id string The ID of the snapshot.
- Volume
Id string - Volume
Size int The size of the volume, in GiB.
- Volume
Type string The type of the volume.
- Delete
On boolTermination If the root block device will be deleted on termination.
- Device
Name string The physical name of the device.
- Encrypted bool
If the EBS volume is encrypted.
- Iops int
0If the volume is not a provisioned IOPS image, otherwise the supported IOPS count.- Kms
Key stringId - Snapshot
Id string The ID of the snapshot.
- Volume
Id string - Volume
Size int The size of the volume, in GiB.
- Volume
Type string The type of the volume.
- delete
On booleanTermination If the root block device will be deleted on termination.
- device
Name string The physical name of the device.
- encrypted boolean
If the EBS volume is encrypted.
- iops number
0If the volume is not a provisioned IOPS image, otherwise the supported IOPS count.- kms
Key stringId - snapshot
Id string The ID of the snapshot.
- volume
Id string - volume
Size number The size of the volume, in GiB.
- volume
Type string The type of the volume.
- delete
On boolTermination 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
0If the volume is not a provisioned IOPS image, otherwise the supported IOPS count.- kms_
key_ strid - snapshot_
id str The ID of the snapshot.
- volume
Type 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.
- Device
Name string The physical name of the device.
- No
Device bool Whether the specified device included in the device mapping was suppressed or not (Boolean).
- Virtual
Name string The virtual device name.
- Device
Name string The physical name of the device.
- No
Device bool Whether the specified device included in the device mapping was suppressed or not (Boolean).
- Virtual
Name string The virtual device name.
- device
Name string The physical name of the device.
- no
Device boolean Whether the specified device included in the device mapping was suppressed or not (Boolean).
- virtual
Name string The virtual device name.
- device_
name str The physical name of the device.
- no
Device bool Whether the specified device included in the device mapping was suppressed or not (Boolean).
- virtual
Name str The virtual device name.
GetInstanceFilter
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.
- Http
Endpoint string The state of the metadata service:
enabled,disabled.- Http
Put intResponse Hop Limit The desired HTTP PUT response hop limit for instance metadata requests.
- Http
Tokens string If session tokens are required:
optional,required.
- Http
Endpoint string The state of the metadata service:
enabled,disabled.- Http
Put intResponse Hop Limit The desired HTTP PUT response hop limit for instance metadata requests.
- Http
Tokens string If session tokens are required:
optional,required.
- http
Endpoint string The state of the metadata service:
enabled,disabled.- http
Put numberResponse Hop Limit The desired HTTP PUT response hop limit for instance metadata requests.
- http
Tokens string If session tokens are required:
optional,required.
- http
Endpoint str The state of the metadata service:
enabled,disabled.- http
Put floatResponse Hop Limit The desired HTTP PUT response hop limit for instance metadata requests.
- http
Tokens 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.
- Delete
On boolTermination If the root block device will be deleted on termination.
- Device
Name string The physical name of the device.
- Encrypted bool
If the EBS volume is encrypted.
- Iops int
0If the volume is not a provisioned IOPS image, otherwise the supported IOPS count.- Kms
Key stringId - Volume
Id string - Volume
Size int The size of the volume, in GiB.
- Volume
Type string The type of the volume.
- Delete
On boolTermination If the root block device will be deleted on termination.
- Device
Name string The physical name of the device.
- Encrypted bool
If the EBS volume is encrypted.
- Iops int
0If the volume is not a provisioned IOPS image, otherwise the supported IOPS count.- Kms
Key stringId - Volume
Id string - Volume
Size int The size of the volume, in GiB.
- Volume
Type string The type of the volume.
- delete
On booleanTermination If the root block device will be deleted on termination.
- device
Name string The physical name of the device.
- encrypted boolean
If the EBS volume is encrypted.
- iops number
0If the volume is not a provisioned IOPS image, otherwise the supported IOPS count.- kms
Key stringId - volume
Id string - volume
Size number The size of the volume, in GiB.
- volume
Type string The type of the volume.
- delete
On boolTermination 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
0If the volume is not a provisioned IOPS image, otherwise the supported IOPS count.- kms_
key_ strid - volume
Type 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
awsTerraform Provider.