Google Cloud (GCP) Classic

v6.38.0 published on Thursday, Sep 22, 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 System.Collections.Generic;
using Pulumi;
using Gcp = Pulumi.Gcp;

return await Deployment.RunAsync(() => 
{
    var netblock = Gcp.Compute.GetNetblockIPRanges.Invoke();

    return new Dictionary<string, object?>
    {
        ["cidrBlocks"] = netblock.Apply(getNetblockIPRangesResult => getNetblockIPRangesResult.CidrBlocks),
        ["cidrBlocksIpv4"] = netblock.Apply(getNetblockIPRangesResult => getNetblockIPRangesResult.CidrBlocksIpv4s),
        ["cidrBlocksIpv6"] = netblock.Apply(getNetblockIPRangesResult => getNetblockIPRangesResult.CidrBlocksIpv6s),
    };
});
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 com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.ComputeFunctions;
import com.pulumi.gcp.compute.inputs.GetNetblockIPRangesArgs;
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 netblock = ComputeFunctions.getNetblockIPRanges();

        ctx.export("cidrBlocks", netblock.applyValue(getNetblockIPRangesResult -> getNetblockIPRangesResult.cidrBlocks()));
        ctx.export("cidrBlocksIpv4", netblock.applyValue(getNetblockIPRangesResult -> getNetblockIPRangesResult.cidrBlocksIpv4s()));
        ctx.export("cidrBlocksIpv6", netblock.applyValue(getNetblockIPRangesResult -> getNetblockIPRangesResult.cidrBlocksIpv6s()));
    }
}
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 System.Collections.Generic;
using Pulumi;
using Gcp = Pulumi.Gcp;

return await Deployment.RunAsync(() => 
{
    var legacy_hcs = Gcp.Compute.GetNetblockIPRanges.Invoke(new()
    {
        RangeType = "legacy-health-checkers",
    });

    var @default = new Gcp.Compute.Network("default");

    var allow_hcs = new Gcp.Compute.Firewall("allow-hcs", new()
    {
        Network = @default.Name,
        Allows = new[]
        {
            new Gcp.Compute.Inputs.FirewallAllowArgs
            {
                Protocol = "tcp",
                Ports = new[]
                {
                    "80",
                },
            },
        },
        SourceRanges = legacy_hcs.Apply(getNetblockIPRangesResult => getNetblockIPRangesResult).Apply(legacy_hcs => legacy_hcs.Apply(getNetblockIPRangesResult => getNetblockIPRangesResult.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 com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.ComputeFunctions;
import com.pulumi.gcp.compute.inputs.GetNetblockIPRangesArgs;
import com.pulumi.gcp.compute.Network;
import com.pulumi.gcp.compute.Firewall;
import com.pulumi.gcp.compute.FirewallArgs;
import com.pulumi.gcp.compute.inputs.FirewallAllowArgs;
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 legacy-hcs = 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_.name())
            .allows(FirewallAllowArgs.builder()
                .protocol("tcp")
                .ports("80")
                .build())
            .sourceRanges(legacy_hcs.cidrBlocksIpv4s())
            .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<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
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<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

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.