1. Packages
  2. Google Cloud (GCP) Classic
  3. API Docs
  4. compute
  5. getLBIPRanges
Google Cloud Classic v7.11.0 published on Friday, Feb 23, 2024 by Pulumi

gcp.compute.getLBIPRanges

Explore with Pulumi AI

gcp logo
Google Cloud Classic v7.11.0 published on Friday, Feb 23, 2024 by Pulumi

    Use this data source to access IP ranges in your firewall rules.

    https://cloud.google.com/compute/docs/load-balancing/health-checks#health_check_source_ips_and_firewall_rules

    Example Usage

    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Gcp = Pulumi.Gcp;
    
    return await Deployment.RunAsync(() => 
    {
        var ranges = Gcp.Compute.GetLBIPRanges.Invoke();
    
        var lb = new Gcp.Compute.Firewall("lb", new()
        {
            Network = google_compute_network.Main.Name,
            Allows = new[]
            {
                new Gcp.Compute.Inputs.FirewallAllowArgs
                {
                    Protocol = "tcp",
                    Ports = new[]
                    {
                        "80",
                    },
                },
            },
            SourceRanges = ranges.Apply(getLBIPRangesResult => getLBIPRangesResult.Networks),
            TargetTags = new[]
            {
                "InstanceBehindLoadBalancer",
            },
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/compute"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		ranges, err := compute.GetLBIPRanges(ctx, nil, nil)
    		if err != nil {
    			return err
    		}
    		_, err = compute.NewFirewall(ctx, "lb", &compute.FirewallArgs{
    			Network: pulumi.Any(google_compute_network.Main.Name),
    			Allows: compute.FirewallAllowArray{
    				&compute.FirewallAllowArgs{
    					Protocol: pulumi.String("tcp"),
    					Ports: pulumi.StringArray{
    						pulumi.String("80"),
    					},
    				},
    			},
    			SourceRanges: interface{}(ranges.Networks),
    			TargetTags: pulumi.StringArray{
    				pulumi.String("InstanceBehindLoadBalancer"),
    			},
    		})
    		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.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 ranges = ComputeFunctions.getLBIPRanges();
    
            var lb = new Firewall("lb", FirewallArgs.builder()        
                .network(google_compute_network.main().name())
                .allows(FirewallAllowArgs.builder()
                    .protocol("tcp")
                    .ports("80")
                    .build())
                .sourceRanges(ranges.applyValue(getLBIPRangesResult -> getLBIPRangesResult.networks()))
                .targetTags("InstanceBehindLoadBalancer")
                .build());
    
        }
    }
    
    import pulumi
    import pulumi_gcp as gcp
    
    ranges = gcp.compute.get_lbip_ranges()
    lb = gcp.compute.Firewall("lb",
        network=google_compute_network["main"]["name"],
        allows=[gcp.compute.FirewallAllowArgs(
            protocol="tcp",
            ports=["80"],
        )],
        source_ranges=ranges.networks,
        target_tags=["InstanceBehindLoadBalancer"])
    
    import * as pulumi from "@pulumi/pulumi";
    import * as gcp from "@pulumi/gcp";
    
    const ranges = gcp.compute.getLBIPRanges({});
    const lb = new gcp.compute.Firewall("lb", {
        network: google_compute_network.main.name,
        allows: [{
            protocol: "tcp",
            ports: ["80"],
        }],
        sourceRanges: ranges.then(ranges => ranges.networks),
        targetTags: ["InstanceBehindLoadBalancer"],
    });
    
    resources:
      lb:
        type: gcp:compute:Firewall
        properties:
          network: ${google_compute_network.main.name}
          allows:
            - protocol: tcp
              ports:
                - '80'
          sourceRanges: ${ranges.networks}
          targetTags:
            - InstanceBehindLoadBalancer
    variables:
      ranges:
        fn::invoke:
          Function: gcp:compute:getLBIPRanges
          Arguments: {}
    

    Using getLBIPRanges

    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 getLBIPRanges(opts?: InvokeOptions): Promise<GetLBIPRangesResult>
    function getLBIPRangesOutput(opts?: InvokeOptions): Output<GetLBIPRangesResult>
    def get_lbip_ranges(opts: Optional[InvokeOptions] = None) -> GetLBIPRangesResult
    def get_lbip_ranges_output(opts: Optional[InvokeOptions] = None) -> Output[GetLBIPRangesResult]
    func GetLBIPRanges(ctx *Context, opts ...InvokeOption) (*GetLBIPRangesResult, error)
    func GetLBIPRangesOutput(ctx *Context, opts ...InvokeOption) GetLBIPRangesResultOutput

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

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

    getLBIPRanges Result

    The following output properties are available:

    HttpSslTcpInternals List<string>
    The IP ranges used for health checks when HTTP(S), SSL proxy, TCP proxy, and Internal load balancing is used
    Id string
    The provider-assigned unique ID for this managed resource.
    Networks List<string>
    The IP ranges used for health checks when Network load balancing is used
    HttpSslTcpInternals []string
    The IP ranges used for health checks when HTTP(S), SSL proxy, TCP proxy, and Internal load balancing is used
    Id string
    The provider-assigned unique ID for this managed resource.
    Networks []string
    The IP ranges used for health checks when Network load balancing is used
    httpSslTcpInternals List<String>
    The IP ranges used for health checks when HTTP(S), SSL proxy, TCP proxy, and Internal load balancing is used
    id String
    The provider-assigned unique ID for this managed resource.
    networks List<String>
    The IP ranges used for health checks when Network load balancing is used
    httpSslTcpInternals string[]
    The IP ranges used for health checks when HTTP(S), SSL proxy, TCP proxy, and Internal load balancing is used
    id string
    The provider-assigned unique ID for this managed resource.
    networks string[]
    The IP ranges used for health checks when Network load balancing is used
    http_ssl_tcp_internals Sequence[str]
    The IP ranges used for health checks when HTTP(S), SSL proxy, TCP proxy, and Internal load balancing is used
    id str
    The provider-assigned unique ID for this managed resource.
    networks Sequence[str]
    The IP ranges used for health checks when Network load balancing is used
    httpSslTcpInternals List<String>
    The IP ranges used for health checks when HTTP(S), SSL proxy, TCP proxy, and Internal load balancing is used
    id String
    The provider-assigned unique ID for this managed resource.
    networks List<String>
    The IP ranges used for health checks when Network load balancing is used

    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 v7.11.0 published on Friday, Feb 23, 2024 by Pulumi