Class GetInstances
Inheritance
System.Object
GetInstances
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Pulumi.Aws.Ec2
Assembly: Pulumi.Aws.dll
Syntax
public static class GetInstances
Methods
View SourceInvokeAsync(GetInstancesArgs, InvokeOptions)
Use this data source to get IDs or IPs of Amazon EC2 instances to be referenced elsewhere, e.g. to allow easier migration from another management solution or to make it easier for an operator to connect through bastion host(s).
Note: It's strongly discouraged to use this data source for querying ephemeral instances (e.g. managed via autoscaling group), as the output may change at any time and you'd need to re-run
applyevery time an instance comes up or dies.
{{% examples %}}
Example Usage
{{% example %}}
using System.Collections.Generic;
using System.Threading.Tasks;
using Pulumi;
using Aws = Pulumi.Aws;
class MyStack : Stack
{
public MyStack()
{
var dict = Output.Create(Initialize());
}
private async Task<IDictionary<string, Output<string>>> Initialize()
{
var testInstances = await Aws.Ec2.GetInstances.InvokeAsync(new Aws.Ec2.GetInstancesArgs
{
Filters =
{
new Aws.Ec2.Inputs.GetInstancesFilterArgs
{
Name = "instance.group-id",
Values =
{
"sg-12345678",
},
},
},
InstanceStateNames =
{
"running",
"stopped",
},
InstanceTags =
{
{ "Role", "HardWorker" },
},
});
var testEip = new List<Aws.Ec2.Eip>();
for (var rangeIndex = 0; rangeIndex < testInstances.Ids.Length; rangeIndex++)
{
var range = new { Value = rangeIndex };
testEip.Add(new Aws.Ec2.Eip($"testEip-{range.Value}", new Aws.Ec2.EipArgs
{
Instance = testInstances.Ids[range.Value],
}));
}
return new Dictionary<string, Output<string>>
{
};
}
}
{{% /example %}} {{% /examples %}}
Declaration
public static Task<GetInstancesResult> InvokeAsync(GetInstancesArgs args = null, InvokeOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| GetInstancesArgs | args | |
| InvokeOptions | options |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task<GetInstancesResult> |