get Instances
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
apply
every time an instance comes up or dies.
Example Usage
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.Ec2Functions;
import com.pulumi.aws.ec2.inputs.GetInstancesArgs;
import com.pulumi.aws.ec2.Eip;
import com.pulumi.aws.ec2.EipArgs;
import com.pulumi.codegen.internal.KeyedValue;
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 testInstances = Ec2Functions.getInstances(GetInstancesArgs.builder()
.instanceTags(Map.of("Role", "HardWorker"))
.filters(GetInstancesFilterArgs.builder()
.name("instance.group-id")
.values("sg-12345678")
.build())
.instanceStateNames(
"running",
"stopped")
.build());
for (var i = 0; i < testInstances.applyValue(getInstancesResult -> getInstancesResult.ids()).length(); i++) {
new Eip("testEip-" + i, EipArgs.builder()
.instance(testInstances.applyValue(getInstancesResult -> getInstancesResult.ids())[range.value()])
.build());
}
}
}
Return
A collection of values returned by getInstances.
Parameters
A collection of arguments for invoking getInstances.
Return
A collection of values returned by getInstances.
Parameters
One or more name/value pairs to use as filters. There are several valid keys, for a full reference, check out 1.
List of instance states that should be applicable to the desired instances. The permitted values are: pending, running, shutting-down, stopped, stopping, terminated
. The default value is running
.
Map of tags, each pair of which must exactly match a pair on desired instances.
See also
Return
A collection of values returned by getInstances.
Parameters
Builder for com.pulumi.aws.ec2.kotlin.inputs.GetInstancesPlainArgs.