1. Packages
  2. Google Cloud (GCP) Classic
  3. API Docs
  4. compute
  5. getRegions
Google Cloud Classic v8.9.3 published on Monday, Nov 18, 2024 by Pulumi

gcp.compute.getRegions

Explore with Pulumi AI

gcp logo
Google Cloud Classic v8.9.3 published on Monday, Nov 18, 2024 by Pulumi

    Provides access to available Google Compute regions for a given project. See more about regions and zones in the upstream docs.

    import * as pulumi from "@pulumi/pulumi";
    import * as gcp from "@pulumi/gcp";
    
    export = async () => {
        const available = await gcp.compute.getRegions({});
        const cluster: gcp.compute.Subnetwork[] = [];
        for (const range = {value: 0}; range.value < available.names.length; range.value++) {
            cluster.push(new gcp.compute.Subnetwork(`cluster-${range.value}`, {
                name: "my-network",
                ipCidrRange: `10.36.${range.value}.0/24`,
                network: "my-network",
                region: available.names[range.value],
            }));
        }
    }
    
    import pulumi
    import pulumi_gcp as gcp
    
    available = gcp.compute.get_regions()
    cluster = []
    for range in [{"value": i} for i in range(0, len(available.names))]:
        cluster.append(gcp.compute.Subnetwork(f"cluster-{range['value']}",
            name="my-network",
            ip_cidr_range=f"10.36.{range['value']}.0/24",
            network="my-network",
            region=available.names[range["value"]]))
    
    package main
    
    import (
    	"fmt"
    
    	"github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/compute"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		available, err := compute.GetRegions(ctx, &compute.GetRegionsArgs{}, nil)
    		if err != nil {
    			return err
    		}
    		var cluster []*compute.Subnetwork
    		for index := 0; index < int(len(available.Names)); index++ {
    			key0 := index
    			val0 := index
    			__res, err := compute.NewSubnetwork(ctx, fmt.Sprintf("cluster-%v", key0), &compute.SubnetworkArgs{
    				Name:        pulumi.String("my-network"),
    				IpCidrRange: pulumi.Sprintf("10.36.%v.0/24", val0),
    				Network:     pulumi.String("my-network"),
    				Region:      pulumi.String(available.Names[val0]),
    			})
    			if err != nil {
    				return err
    			}
    			cluster = append(cluster, __res)
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Pulumi;
    using Gcp = Pulumi.Gcp;
    
    return await Deployment.RunAsync(async() => 
    {
        var available = await Gcp.Compute.GetRegions.InvokeAsync();
    
        var cluster = new List<Gcp.Compute.Subnetwork>();
        for (var rangeIndex = 0; rangeIndex < available.Names.Length; rangeIndex++)
        {
            var range = new { Value = rangeIndex };
            cluster.Add(new Gcp.Compute.Subnetwork($"cluster-{range.Value}", new()
            {
                Name = "my-network",
                IpCidrRange = $"10.36.{range.Value}.0/24",
                Network = "my-network",
                Region = available.Names[range.Value],
            }));
        }
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.gcp.compute.ComputeFunctions;
    import com.pulumi.gcp.compute.inputs.GetRegionsArgs;
    import com.pulumi.gcp.compute.Subnetwork;
    import com.pulumi.gcp.compute.SubnetworkArgs;
    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 available = ComputeFunctions.getRegions();
    
            for (var i = 0; i < available.applyValue(getRegionsResult -> getRegionsResult.names()).length(); i++) {
                new Subnetwork("cluster-" + i, SubnetworkArgs.builder()
                    .name("my-network")
                    .ipCidrRange(String.format("10.36.%s.0/24", range.value()))
                    .network("my-network")
                    .region(available.applyValue(getRegionsResult -> getRegionsResult.names())[range.value()])
                    .build());
    
            
    }
        }
    }
    
    Coming soon!
    

    Using getRegions

    Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.

    function getRegions(args: GetRegionsArgs, opts?: InvokeOptions): Promise<GetRegionsResult>
    function getRegionsOutput(args: GetRegionsOutputArgs, opts?: InvokeOptions): Output<GetRegionsResult>
    def get_regions(project: Optional[str] = None,
                    status: Optional[str] = None,
                    opts: Optional[InvokeOptions] = None) -> GetRegionsResult
    def get_regions_output(project: Optional[pulumi.Input[str]] = None,
                    status: Optional[pulumi.Input[str]] = None,
                    opts: Optional[InvokeOptions] = None) -> Output[GetRegionsResult]
    func GetRegions(ctx *Context, args *GetRegionsArgs, opts ...InvokeOption) (*GetRegionsResult, error)
    func GetRegionsOutput(ctx *Context, args *GetRegionsOutputArgs, opts ...InvokeOption) GetRegionsResultOutput

    > Note: This function is named GetRegions in the Go SDK.

    public static class GetRegions 
    {
        public static Task<GetRegionsResult> InvokeAsync(GetRegionsArgs args, InvokeOptions? opts = null)
        public static Output<GetRegionsResult> Invoke(GetRegionsInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetRegionsResult> getRegions(GetRegionsArgs args, InvokeOptions options)
    // Output-based functions aren't available in Java yet
    
    fn::invoke:
      function: gcp:compute/getRegions:getRegions
      arguments:
        # arguments dictionary

    The following arguments are supported:

    Project string
    Project from which to list available regions. Defaults to project declared in the provider.
    Status string
    Allows to filter list of regions based on their current status. Status can be either UP or DOWN. Defaults to no filtering (all available regions - both UP and DOWN).
    Project string
    Project from which to list available regions. Defaults to project declared in the provider.
    Status string
    Allows to filter list of regions based on their current status. Status can be either UP or DOWN. Defaults to no filtering (all available regions - both UP and DOWN).
    project String
    Project from which to list available regions. Defaults to project declared in the provider.
    status String
    Allows to filter list of regions based on their current status. Status can be either UP or DOWN. Defaults to no filtering (all available regions - both UP and DOWN).
    project string
    Project from which to list available regions. Defaults to project declared in the provider.
    status string
    Allows to filter list of regions based on their current status. Status can be either UP or DOWN. Defaults to no filtering (all available regions - both UP and DOWN).
    project str
    Project from which to list available regions. Defaults to project declared in the provider.
    status str
    Allows to filter list of regions based on their current status. Status can be either UP or DOWN. Defaults to no filtering (all available regions - both UP and DOWN).
    project String
    Project from which to list available regions. Defaults to project declared in the provider.
    status String
    Allows to filter list of regions based on their current status. Status can be either UP or DOWN. Defaults to no filtering (all available regions - both UP and DOWN).

    getRegions Result

    The following output properties are available:

    Id string
    The provider-assigned unique ID for this managed resource.
    Names List<string>
    A list of regions available in the given project
    Project string
    Status string
    Id string
    The provider-assigned unique ID for this managed resource.
    Names []string
    A list of regions available in the given project
    Project string
    Status string
    id String
    The provider-assigned unique ID for this managed resource.
    names List<String>
    A list of regions available in the given project
    project String
    status String
    id string
    The provider-assigned unique ID for this managed resource.
    names string[]
    A list of regions available in the given project
    project string
    status string
    id str
    The provider-assigned unique ID for this managed resource.
    names Sequence[str]
    A list of regions available in the given project
    project str
    status str
    id String
    The provider-assigned unique ID for this managed resource.
    names List<String>
    A list of regions available in the given project
    project String
    status String

    Package Details

    Repository
    Google Cloud (GCP) Classic pulumi/pulumi-gcp
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the google-beta Terraform Provider.
    gcp logo
    Google Cloud Classic v8.9.3 published on Monday, Nov 18, 2024 by Pulumi