1. Packages
  2. Hcloud Provider
  3. API Docs
  4. LoadBalancerTarget
Hetzner Cloud v1.21.0 published on Tuesday, Nov 12, 2024 by Pulumi

hcloud.LoadBalancerTarget

Explore with Pulumi AI

hcloud logo
Hetzner Cloud v1.21.0 published on Tuesday, Nov 12, 2024 by Pulumi

    Adds a target to a Hetzner Cloud Load Balancer.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as hcloud from "@pulumi/hcloud";
    
    const myServer = new hcloud.Server("my_server", {
        name: "my-server",
        serverType: "cx22",
        image: "ubuntu-18.04",
    });
    const loadBalancer = new hcloud.LoadBalancer("load_balancer", {
        name: "my-load-balancer",
        loadBalancerType: "lb11",
        location: "nbg1",
    });
    const loadBalancerTarget = new hcloud.LoadBalancerTarget("load_balancer_target", {
        type: "server",
        loadBalancerId: loadBalancer.id,
        serverId: myServer.id,
    });
    
    import pulumi
    import pulumi_hcloud as hcloud
    
    my_server = hcloud.Server("my_server",
        name="my-server",
        server_type="cx22",
        image="ubuntu-18.04")
    load_balancer = hcloud.LoadBalancer("load_balancer",
        name="my-load-balancer",
        load_balancer_type="lb11",
        location="nbg1")
    load_balancer_target = hcloud.LoadBalancerTarget("load_balancer_target",
        type="server",
        load_balancer_id=load_balancer.id,
        server_id=my_server.id)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-hcloud/sdk/go/hcloud"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		myServer, err := hcloud.NewServer(ctx, "my_server", &hcloud.ServerArgs{
    			Name:       pulumi.String("my-server"),
    			ServerType: pulumi.String("cx22"),
    			Image:      pulumi.String("ubuntu-18.04"),
    		})
    		if err != nil {
    			return err
    		}
    		loadBalancer, err := hcloud.NewLoadBalancer(ctx, "load_balancer", &hcloud.LoadBalancerArgs{
    			Name:             pulumi.String("my-load-balancer"),
    			LoadBalancerType: pulumi.String("lb11"),
    			Location:         pulumi.String("nbg1"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = hcloud.NewLoadBalancerTarget(ctx, "load_balancer_target", &hcloud.LoadBalancerTargetArgs{
    			Type:           pulumi.String("server"),
    			LoadBalancerId: loadBalancer.ID(),
    			ServerId:       myServer.ID(),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using HCloud = Pulumi.HCloud;
    
    return await Deployment.RunAsync(() => 
    {
        var myServer = new HCloud.Server("my_server", new()
        {
            Name = "my-server",
            ServerType = "cx22",
            Image = "ubuntu-18.04",
        });
    
        var loadBalancer = new HCloud.LoadBalancer("load_balancer", new()
        {
            Name = "my-load-balancer",
            LoadBalancerType = "lb11",
            Location = "nbg1",
        });
    
        var loadBalancerTarget = new HCloud.LoadBalancerTarget("load_balancer_target", new()
        {
            Type = "server",
            LoadBalancerId = loadBalancer.Id,
            ServerId = myServer.Id,
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.hcloud.Server;
    import com.pulumi.hcloud.ServerArgs;
    import com.pulumi.hcloud.LoadBalancer;
    import com.pulumi.hcloud.LoadBalancerArgs;
    import com.pulumi.hcloud.LoadBalancerTarget;
    import com.pulumi.hcloud.LoadBalancerTargetArgs;
    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) {
            var myServer = new Server("myServer", ServerArgs.builder()
                .name("my-server")
                .serverType("cx22")
                .image("ubuntu-18.04")
                .build());
    
            var loadBalancer = new LoadBalancer("loadBalancer", LoadBalancerArgs.builder()
                .name("my-load-balancer")
                .loadBalancerType("lb11")
                .location("nbg1")
                .build());
    
            var loadBalancerTarget = new LoadBalancerTarget("loadBalancerTarget", LoadBalancerTargetArgs.builder()
                .type("server")
                .loadBalancerId(loadBalancer.id())
                .serverId(myServer.id())
                .build());
    
        }
    }
    
    resources:
      myServer:
        type: hcloud:Server
        name: my_server
        properties:
          name: my-server
          serverType: cx22
          image: ubuntu-18.04
      loadBalancer:
        type: hcloud:LoadBalancer
        name: load_balancer
        properties:
          name: my-load-balancer
          loadBalancerType: lb11
          location: nbg1
      loadBalancerTarget:
        type: hcloud:LoadBalancerTarget
        name: load_balancer_target
        properties:
          type: server
          loadBalancerId: ${loadBalancer.id}
          serverId: ${myServer.id}
    

    Create LoadBalancerTarget Resource

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new LoadBalancerTarget(name: string, args: LoadBalancerTargetArgs, opts?: CustomResourceOptions);
    @overload
    def LoadBalancerTarget(resource_name: str,
                           args: LoadBalancerTargetInitArgs,
                           opts: Optional[ResourceOptions] = None)
    
    @overload
    def LoadBalancerTarget(resource_name: str,
                           opts: Optional[ResourceOptions] = None,
                           load_balancer_id: Optional[int] = None,
                           type: Optional[str] = None,
                           ip: Optional[str] = None,
                           label_selector: Optional[str] = None,
                           server_id: Optional[int] = None,
                           use_private_ip: Optional[bool] = None)
    func NewLoadBalancerTarget(ctx *Context, name string, args LoadBalancerTargetArgs, opts ...ResourceOption) (*LoadBalancerTarget, error)
    public LoadBalancerTarget(string name, LoadBalancerTargetArgs args, CustomResourceOptions? opts = null)
    public LoadBalancerTarget(String name, LoadBalancerTargetArgs args)
    public LoadBalancerTarget(String name, LoadBalancerTargetArgs args, CustomResourceOptions options)
    
    type: hcloud:LoadBalancerTarget
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    

    Parameters

    name string
    The unique name of the resource.
    args LoadBalancerTargetArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    resource_name str
    The unique name of the resource.
    args LoadBalancerTargetInitArgs
    The arguments to resource properties.
    opts ResourceOptions
    Bag of options to control resource's behavior.
    ctx Context
    Context object for the current deployment.
    name string
    The unique name of the resource.
    args LoadBalancerTargetArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args LoadBalancerTargetArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args LoadBalancerTargetArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    Constructor example

    The following reference example uses placeholder values for all input properties.

    var loadBalancerTargetResource = new HCloud.LoadBalancerTarget("loadBalancerTargetResource", new()
    {
        LoadBalancerId = 0,
        Type = "string",
        Ip = "string",
        LabelSelector = "string",
        ServerId = 0,
        UsePrivateIp = false,
    });
    
    example, err := hcloud.NewLoadBalancerTarget(ctx, "loadBalancerTargetResource", &hcloud.LoadBalancerTargetArgs{
    	LoadBalancerId: pulumi.Int(0),
    	Type:           pulumi.String("string"),
    	Ip:             pulumi.String("string"),
    	LabelSelector:  pulumi.String("string"),
    	ServerId:       pulumi.Int(0),
    	UsePrivateIp:   pulumi.Bool(false),
    })
    
    var loadBalancerTargetResource = new LoadBalancerTarget("loadBalancerTargetResource", LoadBalancerTargetArgs.builder()
        .loadBalancerId(0)
        .type("string")
        .ip("string")
        .labelSelector("string")
        .serverId(0)
        .usePrivateIp(false)
        .build());
    
    load_balancer_target_resource = hcloud.LoadBalancerTarget("loadBalancerTargetResource",
        load_balancer_id=0,
        type="string",
        ip="string",
        label_selector="string",
        server_id=0,
        use_private_ip=False)
    
    const loadBalancerTargetResource = new hcloud.LoadBalancerTarget("loadBalancerTargetResource", {
        loadBalancerId: 0,
        type: "string",
        ip: "string",
        labelSelector: "string",
        serverId: 0,
        usePrivateIp: false,
    });
    
    type: hcloud:LoadBalancerTarget
    properties:
        ip: string
        labelSelector: string
        loadBalancerId: 0
        serverId: 0
        type: string
        usePrivateIp: false
    

    LoadBalancerTarget Resource Properties

    To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

    Inputs

    In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

    The LoadBalancerTarget resource accepts the following input properties:

    LoadBalancerId int
    ID of the Load Balancer to which the target gets attached.
    Type string
    Type of the target. Possible values server, label_selector, ip.
    Ip string
    IP address for an IP Target. Required if type is ip.
    LabelSelector string
    Label Selector selecting targets for this Load Balancer. Required if type is label_selector.
    ServerId int
    ID of the server which should be a target for this Load Balancer. Required if type is server
    UsePrivateIp bool
    use the private IP to connect to Load Balancer targets. Only allowed if type is server or label_selector.
    LoadBalancerId int
    ID of the Load Balancer to which the target gets attached.
    Type string
    Type of the target. Possible values server, label_selector, ip.
    Ip string
    IP address for an IP Target. Required if type is ip.
    LabelSelector string
    Label Selector selecting targets for this Load Balancer. Required if type is label_selector.
    ServerId int
    ID of the server which should be a target for this Load Balancer. Required if type is server
    UsePrivateIp bool
    use the private IP to connect to Load Balancer targets. Only allowed if type is server or label_selector.
    loadBalancerId Integer
    ID of the Load Balancer to which the target gets attached.
    type String
    Type of the target. Possible values server, label_selector, ip.
    ip String
    IP address for an IP Target. Required if type is ip.
    labelSelector String
    Label Selector selecting targets for this Load Balancer. Required if type is label_selector.
    serverId Integer
    ID of the server which should be a target for this Load Balancer. Required if type is server
    usePrivateIp Boolean
    use the private IP to connect to Load Balancer targets. Only allowed if type is server or label_selector.
    loadBalancerId number
    ID of the Load Balancer to which the target gets attached.
    type string
    Type of the target. Possible values server, label_selector, ip.
    ip string
    IP address for an IP Target. Required if type is ip.
    labelSelector string
    Label Selector selecting targets for this Load Balancer. Required if type is label_selector.
    serverId number
    ID of the server which should be a target for this Load Balancer. Required if type is server
    usePrivateIp boolean
    use the private IP to connect to Load Balancer targets. Only allowed if type is server or label_selector.
    load_balancer_id int
    ID of the Load Balancer to which the target gets attached.
    type str
    Type of the target. Possible values server, label_selector, ip.
    ip str
    IP address for an IP Target. Required if type is ip.
    label_selector str
    Label Selector selecting targets for this Load Balancer. Required if type is label_selector.
    server_id int
    ID of the server which should be a target for this Load Balancer. Required if type is server
    use_private_ip bool
    use the private IP to connect to Load Balancer targets. Only allowed if type is server or label_selector.
    loadBalancerId Number
    ID of the Load Balancer to which the target gets attached.
    type String
    Type of the target. Possible values server, label_selector, ip.
    ip String
    IP address for an IP Target. Required if type is ip.
    labelSelector String
    Label Selector selecting targets for this Load Balancer. Required if type is label_selector.
    serverId Number
    ID of the server which should be a target for this Load Balancer. Required if type is server
    usePrivateIp Boolean
    use the private IP to connect to Load Balancer targets. Only allowed if type is server or label_selector.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the LoadBalancerTarget resource produces the following output properties:

    Id string
    The provider-assigned unique ID for this managed resource.
    Id string
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.
    id string
    The provider-assigned unique ID for this managed resource.
    id str
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.

    Look up Existing LoadBalancerTarget Resource

    Get an existing LoadBalancerTarget resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

    public static get(name: string, id: Input<ID>, state?: LoadBalancerTargetState, opts?: CustomResourceOptions): LoadBalancerTarget
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            ip: Optional[str] = None,
            label_selector: Optional[str] = None,
            load_balancer_id: Optional[int] = None,
            server_id: Optional[int] = None,
            type: Optional[str] = None,
            use_private_ip: Optional[bool] = None) -> LoadBalancerTarget
    func GetLoadBalancerTarget(ctx *Context, name string, id IDInput, state *LoadBalancerTargetState, opts ...ResourceOption) (*LoadBalancerTarget, error)
    public static LoadBalancerTarget Get(string name, Input<string> id, LoadBalancerTargetState? state, CustomResourceOptions? opts = null)
    public static LoadBalancerTarget get(String name, Output<String> id, LoadBalancerTargetState state, CustomResourceOptions options)
    Resource lookup is not supported in YAML
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    resource_name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    The following state arguments are supported:
    Ip string
    IP address for an IP Target. Required if type is ip.
    LabelSelector string
    Label Selector selecting targets for this Load Balancer. Required if type is label_selector.
    LoadBalancerId int
    ID of the Load Balancer to which the target gets attached.
    ServerId int
    ID of the server which should be a target for this Load Balancer. Required if type is server
    Type string
    Type of the target. Possible values server, label_selector, ip.
    UsePrivateIp bool
    use the private IP to connect to Load Balancer targets. Only allowed if type is server or label_selector.
    Ip string
    IP address for an IP Target. Required if type is ip.
    LabelSelector string
    Label Selector selecting targets for this Load Balancer. Required if type is label_selector.
    LoadBalancerId int
    ID of the Load Balancer to which the target gets attached.
    ServerId int
    ID of the server which should be a target for this Load Balancer. Required if type is server
    Type string
    Type of the target. Possible values server, label_selector, ip.
    UsePrivateIp bool
    use the private IP to connect to Load Balancer targets. Only allowed if type is server or label_selector.
    ip String
    IP address for an IP Target. Required if type is ip.
    labelSelector String
    Label Selector selecting targets for this Load Balancer. Required if type is label_selector.
    loadBalancerId Integer
    ID of the Load Balancer to which the target gets attached.
    serverId Integer
    ID of the server which should be a target for this Load Balancer. Required if type is server
    type String
    Type of the target. Possible values server, label_selector, ip.
    usePrivateIp Boolean
    use the private IP to connect to Load Balancer targets. Only allowed if type is server or label_selector.
    ip string
    IP address for an IP Target. Required if type is ip.
    labelSelector string
    Label Selector selecting targets for this Load Balancer. Required if type is label_selector.
    loadBalancerId number
    ID of the Load Balancer to which the target gets attached.
    serverId number
    ID of the server which should be a target for this Load Balancer. Required if type is server
    type string
    Type of the target. Possible values server, label_selector, ip.
    usePrivateIp boolean
    use the private IP to connect to Load Balancer targets. Only allowed if type is server or label_selector.
    ip str
    IP address for an IP Target. Required if type is ip.
    label_selector str
    Label Selector selecting targets for this Load Balancer. Required if type is label_selector.
    load_balancer_id int
    ID of the Load Balancer to which the target gets attached.
    server_id int
    ID of the server which should be a target for this Load Balancer. Required if type is server
    type str
    Type of the target. Possible values server, label_selector, ip.
    use_private_ip bool
    use the private IP to connect to Load Balancer targets. Only allowed if type is server or label_selector.
    ip String
    IP address for an IP Target. Required if type is ip.
    labelSelector String
    Label Selector selecting targets for this Load Balancer. Required if type is label_selector.
    loadBalancerId Number
    ID of the Load Balancer to which the target gets attached.
    serverId Number
    ID of the server which should be a target for this Load Balancer. Required if type is server
    type String
    Type of the target. Possible values server, label_selector, ip.
    usePrivateIp Boolean
    use the private IP to connect to Load Balancer targets. Only allowed if type is server or label_selector.

    Import

    Load Balancer Target entries can be imported using a compound ID with the following format:

    <load-balancer-id>__<type>__<identifier>

    Where identifier depends on the type:

    • server: server id, for example: 123

    • label_selector: label selector, for example: foo=bar

    • ip: ip address, for example: 203.0.113.123

    $ pulumi import hcloud:index/loadBalancerTarget:LoadBalancerTarget myloadbalancerservertarget 123__server__321
    
    $ pulumi import hcloud:index/loadBalancerTarget:LoadBalancerTarget myloadbalancerlabeltarget 123__label_selector__foo=bar
    
    $ pulumi import hcloud:index/loadBalancerTarget:LoadBalancerTarget myloadbalanceriptarget 123__ip__203.0.113.123
    

    To learn more about importing existing cloud resources, see Importing resources.

    Package Details

    Repository
    Hetzner Cloud pulumi/pulumi-hcloud
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the hcloud Terraform Provider.
    hcloud logo
    Hetzner Cloud v1.21.0 published on Tuesday, Nov 12, 2024 by Pulumi