get Subnet Ids
aws.ec2.getSubnetIds
provides a set of ids for a vpc_id This resource can be useful for getting back a set of subnet ids for a vpc.
NOTE: The
aws.ec2.getSubnetIds
data source has been deprecated and will be removed in a future version. Use theaws.ec2.getSubnets
data source instead.
Example Usage
The following shows outputting all cidr blocks for every subnet id in a vpc.
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.GetSubnetIdsArgs;
import com.pulumi.aws.ec2.Instance;
import com.pulumi.aws.ec2.InstanceArgs;
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 private = Ec2Functions.getSubnetIds(GetSubnetIdsArgs.builder()
.vpcId(var_.vpc_id())
.tags(Map.of("Tier", "Private"))
.build());
final var app = private.applyValue(getSubnetIdsResult -> {
final var resources = new ArrayList<Instance>();
for (var range : KeyedValue.of(getSubnetIdsResult.ids()) {
var resource = new Instance("app-" + range.key(), InstanceArgs.builder()
.ami(var_.ami())
.instanceType("t2.micro")
.subnetId(range.value())
.build());
resources.add(resource);
}
return resources;
});
}
}
Return
A collection of values returned by getSubnetIds.
Parameters
A collection of arguments for invoking getSubnetIds.
Return
A collection of values returned by getSubnetIds.
Parameters
Custom filter block as described below.
Map of tags, each pair of which must exactly match a pair on the desired subnets. More complex filters can be expressed using one or more filter
sub-blocks, which take the following arguments:
VPC ID that you want to filter from.
See also
Return
A collection of values returned by getSubnetIds.
Parameters
Builder for com.pulumi.aws.ec2.kotlin.inputs.GetSubnetIdsPlainArgs.