Google Cloud (GCP) Classic

Pulumi Official
Package maintained by Pulumi
v6.24.0 published on Tuesday, May 17, 2022 by Pulumi

getNetblockIPRanges

Use this data source to get the IP addresses from different special IP ranges on Google Cloud Platform.

Example Usage

Cloud Ranges

using Pulumi;
using Gcp = Pulumi.Gcp;

class MyStack : Stack
{
    public MyStack()
    {
        var netblock = Output.Create(Gcp.Compute.GetNetblockIPRanges.InvokeAsync());
        this.CidrBlocks = netblock.Apply(netblock => netblock.CidrBlocks);
        this.CidrBlocksIpv4 = netblock.Apply(netblock => netblock.CidrBlocksIpv4s);
        this.CidrBlocksIpv6 = netblock.Apply(netblock => netblock.CidrBlocksIpv6s);
    }

    [Output("cidrBlocks")]
    public Output<string> CidrBlocks { get; set; }
    [Output("cidrBlocksIpv4")]
    public Output<string> CidrBlocksIpv4 { get; set; }
    [Output("cidrBlocksIpv6")]
    public Output<string> CidrBlocksIpv6 { get; set; }
}
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/compute"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		netblock, err := compute.GetNetblockIPRanges(ctx, nil, nil)
		if err != nil {
			return err
		}
		ctx.Export("cidrBlocks", netblock.CidrBlocks)
		ctx.Export("cidrBlocksIpv4", netblock.CidrBlocksIpv4s)
		ctx.Export("cidrBlocksIpv6", netblock.CidrBlocksIpv6s)
		return nil
	})
}
package generated_program;

import java.util.*;
import java.io.*;
import java.nio.*;
import com.pulumi.*;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        final var netblock = Output.of(ComputeFunctions.getNetblockIPRanges());

        ctx.export("cidrBlocks", netblock.apply(getNetblockIPRangesResult -> getNetblockIPRangesResult.getCidrBlocks()));
        ctx.export("cidrBlocksIpv4", netblock.apply(getNetblockIPRangesResult -> getNetblockIPRangesResult.getCidrBlocksIpv4s()));
        ctx.export("cidrBlocksIpv6", netblock.apply(getNetblockIPRangesResult -> getNetblockIPRangesResult.getCidrBlocksIpv6s()));
        }
}
import pulumi
import pulumi_gcp as gcp

netblock = gcp.compute.get_netblock_ip_ranges()
pulumi.export("cidrBlocks", netblock.cidr_blocks)
pulumi.export("cidrBlocksIpv4", netblock.cidr_blocks_ipv4s)
pulumi.export("cidrBlocksIpv6", netblock.cidr_blocks_ipv6s)
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const netblock = gcp.compute.getNetblockIPRanges({});
export const cidrBlocks = netblock.then(netblock => netblock.cidrBlocks);
export const cidrBlocksIpv4 = netblock.then(netblock => netblock.cidrBlocksIpv4s);
export const cidrBlocksIpv6 = netblock.then(netblock => netblock.cidrBlocksIpv6s);
variables:
  netblock:
    Fn::Invoke:
      Function: gcp:compute:getNetblockIPRanges
      Arguments: {}
outputs:
  cidrBlocks: ${netblock.cidrBlocks}
  cidrBlocksIpv4: ${netblock.cidrBlocksIpv4s}
  cidrBlocksIpv6: ${netblock.cidrBlocksIpv6s}

Allow Health Checks

using Pulumi;
using Gcp = Pulumi.Gcp;

class MyStack : Stack
{
    public MyStack()
    {
        var legacy_hcs = Output.Create(Gcp.Compute.GetNetblockIPRanges.InvokeAsync(new Gcp.Compute.GetNetblockIPRangesArgs
        {
            RangeType = "legacy-health-checkers",
        }));
        var @default = new Gcp.Compute.Network("default", new Gcp.Compute.NetworkArgs
        {
        });
        var allow_hcs = new Gcp.Compute.Firewall("allow-hcs", new Gcp.Compute.FirewallArgs
        {
            Network = @default.Name,
            Allows = 
            {
                new Gcp.Compute.Inputs.FirewallAllowArgs
                {
                    Protocol = "tcp",
                    Ports = 
                    {
                        "80",
                    },
                },
            },
            SourceRanges = legacy_hcs.Apply(legacy_hcs => legacy_hcs.CidrBlocksIpv4s),
        });
    }

}
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/compute"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		legacy_hcs, err := compute.GetNetblockIPRanges(ctx, &compute.GetNetblockIPRangesArgs{
			RangeType: pulumi.StringRef("legacy-health-checkers"),
		}, nil)
		if err != nil {
			return err
		}
		_, err = compute.NewNetwork(ctx, "default", nil)
		if err != nil {
			return err
		}
		_, err = compute.NewFirewall(ctx, "allow-hcs", &compute.FirewallArgs{
			Network: _default.Name,
			Allows: compute.FirewallAllowArray{
				&compute.FirewallAllowArgs{
					Protocol: pulumi.String("tcp"),
					Ports: pulumi.StringArray{
						pulumi.String("80"),
					},
				},
			},
			SourceRanges: interface{}(legacy_hcs.CidrBlocksIpv4s),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import java.util.*;
import java.io.*;
import java.nio.*;
import com.pulumi.*;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        final var legacy-hcs = Output.of(ComputeFunctions.getNetblockIPRanges(GetNetblockIPRangesArgs.builder()
            .rangeType("legacy-health-checkers")
            .build()));

        var default_ = new Network("default");

        var allow_hcs = new Firewall("allow-hcs", FirewallArgs.builder()        
            .network(default_.getName())
            .allows(FirewallAllow.builder()
                .protocol("tcp")
                .ports("80")
                .build())
            .sourceRanges(legacy_hcs.getCidrBlocksIpv4s())
            .build());

        }
}
import pulumi
import pulumi_gcp as gcp

legacy_hcs = gcp.compute.get_netblock_ip_ranges(range_type="legacy-health-checkers")
default = gcp.compute.Network("default")
allow_hcs = gcp.compute.Firewall("allow-hcs",
    network=default.name,
    allows=[gcp.compute.FirewallAllowArgs(
        protocol="tcp",
        ports=["80"],
    )],
    source_ranges=legacy_hcs.cidr_blocks_ipv4s)
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const legacy-hcs = gcp.compute.getNetblockIPRanges({
    rangeType: "legacy-health-checkers",
});
const _default = new gcp.compute.Network("default", {});
const allow_hcs = new gcp.compute.Firewall("allow-hcs", {
    network: _default.name,
    allows: [{
        protocol: "tcp",
        ports: ["80"],
    }],
    sourceRanges: legacy_hcs.then(legacy_hcs => legacy_hcs.cidrBlocksIpv4s),
});
resources:
  allow-hcs:
    type: gcp:compute:Firewall
    properties:
      network: ${default.name}
      allows:
        - protocol: tcp
          ports:
            - 80
      sourceRanges: ${["legacy-hcs"].cidrBlocksIpv4s}
  default:
    type: gcp:compute:Network
variables:
  legacy-hcs:
    Fn::Invoke:
      Function: gcp:compute:getNetblockIPRanges
      Arguments:
        rangeType: legacy-health-checkers

Using getNetblockIPRanges

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 getNetblockIPRanges(args: GetNetblockIPRangesArgs, opts?: InvokeOptions): Promise<GetNetblockIPRangesResult>
function getNetblockIPRangesOutput(args: GetNetblockIPRangesOutputArgs, opts?: InvokeOptions): Output<GetNetblockIPRangesResult>
def get_netblock_ip_ranges(range_type: Optional[str] = None,
                           opts: Optional[InvokeOptions] = None) -> GetNetblockIPRangesResult
def get_netblock_ip_ranges_output(range_type: Optional[pulumi.Input[str]] = None,
                           opts: Optional[InvokeOptions] = None) -> Output[GetNetblockIPRangesResult]
func GetNetblockIPRanges(ctx *Context, args *GetNetblockIPRangesArgs, opts ...InvokeOption) (*GetNetblockIPRangesResult, error)
func GetNetblockIPRangesOutput(ctx *Context, args *GetNetblockIPRangesOutputArgs, opts ...InvokeOption) GetNetblockIPRangesResultOutput

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

public static class GetNetblockIPRanges 
{
    public static Task<GetNetblockIPRangesResult> InvokeAsync(GetNetblockIPRangesArgs args, InvokeOptions? opts = null)
    public static Output<GetNetblockIPRangesResult> Invoke(GetNetblockIPRangesInvokeArgs args, InvokeOptions? opts = null)
}
public static CompletableFuture<GetNetblockIPRangesResult> getNetblockIPRanges(GetNetblockIPRangesArgs args, InvokeOptions options)
// Output-based functions aren't available in Java yet
Fn::Invoke:
  Function: gcp:compute/getNetblockIPRanges:getNetblockIPRanges
  Arguments:
    # Arguments dictionary

The following arguments are supported:

RangeType string

The type of range for which to provide results.

RangeType string

The type of range for which to provide results.

rangeType String

The type of range for which to provide results.

rangeType string

The type of range for which to provide results.

range_type str

The type of range for which to provide results.

rangeType String

The type of range for which to provide results.

getNetblockIPRanges Result

The following output properties are available:

CidrBlocks List<string>

Retrieve list of all CIDR blocks.

CidrBlocksIpv4s List<string>

Retrieve list of the IPv4 CIDR blocks

CidrBlocksIpv6s List<string>

Retrieve list of the IPv6 CIDR blocks, if available.

Id string

The provider-assigned unique ID for this managed resource.

RangeType string
CidrBlocks []string

Retrieve list of all CIDR blocks.

CidrBlocksIpv4s []string

Retrieve list of the IPv4 CIDR blocks

CidrBlocksIpv6s []string

Retrieve list of the IPv6 CIDR blocks, if available.

Id string

The provider-assigned unique ID for this managed resource.

RangeType string
cidrBlocks List

Retrieve list of all CIDR blocks.

cidrBlocksIpv4s List

Retrieve list of the IPv4 CIDR blocks

cidrBlocksIpv6s List

Retrieve list of the IPv6 CIDR blocks, if available.

id String

The provider-assigned unique ID for this managed resource.

rangeType String
cidrBlocks string[]

Retrieve list of all CIDR blocks.

cidrBlocksIpv4s string[]

Retrieve list of the IPv4 CIDR blocks

cidrBlocksIpv6s string[]

Retrieve list of the IPv6 CIDR blocks, if available.

id string

The provider-assigned unique ID for this managed resource.

rangeType string
cidr_blocks Sequence[str]

Retrieve list of all CIDR blocks.

cidr_blocks_ipv4s Sequence[str]

Retrieve list of the IPv4 CIDR blocks

cidr_blocks_ipv6s Sequence[str]

Retrieve list of the IPv6 CIDR blocks, if available.

id str

The provider-assigned unique ID for this managed resource.

range_type str
cidrBlocks List

Retrieve list of all CIDR blocks.

cidrBlocksIpv4s List

Retrieve list of the IPv4 CIDR blocks

cidrBlocksIpv6s List

Retrieve list of the IPv6 CIDR blocks, if available.

id String

The provider-assigned unique ID for this managed resource.

rangeType String

Package Details

Repository
https://github.com/pulumi/pulumi-gcp
License
Apache-2.0
Notes

This Pulumi package is based on the google-beta Terraform Provider.