1. Packages
  2. Ucloud Provider
  3. API Docs
  4. LbAttachment
ucloud 1.39.1 published on Monday, Apr 14, 2025 by ucloud

ucloud.LbAttachment

Explore with Pulumi AI

Provides a Load Balancer Attachment resource for attaching Load Balancer to UHost Instance, etc.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as ucloud from "@pulumi/ucloud";

const defaultImages = ucloud.getImages({
    availabilityZone: "cn-bj2-04",
    nameRegex: "^CentOS 6.5 64",
    imageType: "base",
});
// Create Load Balancer
const webLb = new ucloud.Lb("webLb", {tag: "tf-example"});
// Create Load Balancer Listener with http protocol
const defaultLbListener = new ucloud.LbListener("defaultLbListener", {
    loadBalancerId: webLb.lbId,
    protocol: "http",
});
// Create web server
const webInstance = new ucloud.Instance("webInstance", {
    instanceType: "n-basic-2",
    availabilityZone: "cn-bj2-04",
    rootPassword: "wA1234567",
    imageId: defaultImages.then(defaultImages => defaultImages.images?.[0]?.id),
    tag: "tf-example",
});
// Attach instances to Load Balancer
const example = new ucloud.LbAttachment("example", {
    loadBalancerId: webLb.lbId,
    listenerId: defaultLbListener.lbListenerId,
    resourceId: webInstance.instanceId,
    port: 80,
});
Copy
import pulumi
import pulumi_ucloud as ucloud

default_images = ucloud.get_images(availability_zone="cn-bj2-04",
    name_regex="^CentOS 6.5 64",
    image_type="base")
# Create Load Balancer
web_lb = ucloud.Lb("webLb", tag="tf-example")
# Create Load Balancer Listener with http protocol
default_lb_listener = ucloud.LbListener("defaultLbListener",
    load_balancer_id=web_lb.lb_id,
    protocol="http")
# Create web server
web_instance = ucloud.Instance("webInstance",
    instance_type="n-basic-2",
    availability_zone="cn-bj2-04",
    root_password="wA1234567",
    image_id=default_images.images[0].id,
    tag="tf-example")
# Attach instances to Load Balancer
example = ucloud.LbAttachment("example",
    load_balancer_id=web_lb.lb_id,
    listener_id=default_lb_listener.lb_listener_id,
    resource_id=web_instance.instance_id,
    port=80)
Copy
package main

import (
	"github.com/pulumi/pulumi-terraform-provider/sdks/go/ucloud/ucloud"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		defaultImages, err := ucloud.GetImages(ctx, &ucloud.GetImagesArgs{
			AvailabilityZone: pulumi.StringRef("cn-bj2-04"),
			NameRegex:        pulumi.StringRef("^CentOS 6.5 64"),
			ImageType:        pulumi.StringRef("base"),
		}, nil)
		if err != nil {
			return err
		}
		// Create Load Balancer
		webLb, err := ucloud.NewLb(ctx, "webLb", &ucloud.LbArgs{
			Tag: pulumi.String("tf-example"),
		})
		if err != nil {
			return err
		}
		// Create Load Balancer Listener with http protocol
		defaultLbListener, err := ucloud.NewLbListener(ctx, "defaultLbListener", &ucloud.LbListenerArgs{
			LoadBalancerId: webLb.LbId,
			Protocol:       pulumi.String("http"),
		})
		if err != nil {
			return err
		}
		// Create web server
		webInstance, err := ucloud.NewInstance(ctx, "webInstance", &ucloud.InstanceArgs{
			InstanceType:     pulumi.String("n-basic-2"),
			AvailabilityZone: pulumi.String("cn-bj2-04"),
			RootPassword:     pulumi.String("wA1234567"),
			ImageId:          pulumi.String(defaultImages.Images[0].Id),
			Tag:              pulumi.String("tf-example"),
		})
		if err != nil {
			return err
		}
		// Attach instances to Load Balancer
		_, err = ucloud.NewLbAttachment(ctx, "example", &ucloud.LbAttachmentArgs{
			LoadBalancerId: webLb.LbId,
			ListenerId:     defaultLbListener.LbListenerId,
			ResourceId:     webInstance.InstanceId,
			Port:           pulumi.Float64(80),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Ucloud = Pulumi.Ucloud;

return await Deployment.RunAsync(() => 
{
    var defaultImages = Ucloud.GetImages.Invoke(new()
    {
        AvailabilityZone = "cn-bj2-04",
        NameRegex = "^CentOS 6.5 64",
        ImageType = "base",
    });

    // Create Load Balancer
    var webLb = new Ucloud.Lb("webLb", new()
    {
        Tag = "tf-example",
    });

    // Create Load Balancer Listener with http protocol
    var defaultLbListener = new Ucloud.LbListener("defaultLbListener", new()
    {
        LoadBalancerId = webLb.LbId,
        Protocol = "http",
    });

    // Create web server
    var webInstance = new Ucloud.Instance("webInstance", new()
    {
        InstanceType = "n-basic-2",
        AvailabilityZone = "cn-bj2-04",
        RootPassword = "wA1234567",
        ImageId = defaultImages.Apply(getImagesResult => getImagesResult.Images[0]?.Id),
        Tag = "tf-example",
    });

    // Attach instances to Load Balancer
    var example = new Ucloud.LbAttachment("example", new()
    {
        LoadBalancerId = webLb.LbId,
        ListenerId = defaultLbListener.LbListenerId,
        ResourceId = webInstance.InstanceId,
        Port = 80,
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.ucloud.UcloudFunctions;
import com.pulumi.ucloud.inputs.GetImagesArgs;
import com.pulumi.ucloud.Lb;
import com.pulumi.ucloud.LbArgs;
import com.pulumi.ucloud.LbListener;
import com.pulumi.ucloud.LbListenerArgs;
import com.pulumi.ucloud.Instance;
import com.pulumi.ucloud.InstanceArgs;
import com.pulumi.ucloud.LbAttachment;
import com.pulumi.ucloud.LbAttachmentArgs;
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 defaultImages = UcloudFunctions.getImages(GetImagesArgs.builder()
            .availabilityZone("cn-bj2-04")
            .nameRegex("^CentOS 6.5 64")
            .imageType("base")
            .build());

        // Create Load Balancer
        var webLb = new Lb("webLb", LbArgs.builder()
            .tag("tf-example")
            .build());

        // Create Load Balancer Listener with http protocol
        var defaultLbListener = new LbListener("defaultLbListener", LbListenerArgs.builder()
            .loadBalancerId(webLb.lbId())
            .protocol("http")
            .build());

        // Create web server
        var webInstance = new Instance("webInstance", InstanceArgs.builder()
            .instanceType("n-basic-2")
            .availabilityZone("cn-bj2-04")
            .rootPassword("wA1234567")
            .imageId(defaultImages.applyValue(getImagesResult -> getImagesResult.images()[0].id()))
            .tag("tf-example")
            .build());

        // Attach instances to Load Balancer
        var example = new LbAttachment("example", LbAttachmentArgs.builder()
            .loadBalancerId(webLb.lbId())
            .listenerId(defaultLbListener.lbListenerId())
            .resourceId(webInstance.instanceId())
            .port(80)
            .build());

    }
}
Copy
resources:
  # Create Load Balancer
  webLb:
    type: ucloud:Lb
    properties:
      tag: tf-example
  # Create Load Balancer Listener with http protocol
  defaultLbListener:
    type: ucloud:LbListener
    properties:
      loadBalancerId: ${webLb.lbId}
      protocol: http
  # Create web server
  webInstance:
    type: ucloud:Instance
    properties:
      instanceType: n-basic-2
      availabilityZone: cn-bj2-04
      rootPassword: wA1234567
      imageId: ${defaultImages.images[0].id}
      tag: tf-example
  # Attach instances to Load Balancer
  example:
    type: ucloud:LbAttachment
    properties:
      loadBalancerId: ${webLb.lbId}
      listenerId: ${defaultLbListener.lbListenerId}
      resourceId: ${webInstance.instanceId}
      port: 80
variables:
  defaultImages:
    fn::invoke:
      function: ucloud:getImages
      arguments:
        availabilityZone: cn-bj2-04
        nameRegex: ^CentOS 6.5 64
        imageType: base
Copy

Create LbAttachment Resource

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

Constructor syntax

new LbAttachment(name: string, args: LbAttachmentArgs, opts?: CustomResourceOptions);
@overload
def LbAttachment(resource_name: str,
                 args: LbAttachmentArgs,
                 opts: Optional[ResourceOptions] = None)

@overload
def LbAttachment(resource_name: str,
                 opts: Optional[ResourceOptions] = None,
                 listener_id: Optional[str] = None,
                 load_balancer_id: Optional[str] = None,
                 resource_id: Optional[str] = None,
                 lb_attachment_id: Optional[str] = None,
                 port: Optional[float] = None,
                 resource_type: Optional[str] = None)
func NewLbAttachment(ctx *Context, name string, args LbAttachmentArgs, opts ...ResourceOption) (*LbAttachment, error)
public LbAttachment(string name, LbAttachmentArgs args, CustomResourceOptions? opts = null)
public LbAttachment(String name, LbAttachmentArgs args)
public LbAttachment(String name, LbAttachmentArgs args, CustomResourceOptions options)
type: ucloud:LbAttachment
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. LbAttachmentArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. LbAttachmentArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. LbAttachmentArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. LbAttachmentArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. LbAttachmentArgs
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 lbAttachmentResource = new Ucloud.LbAttachment("lbAttachmentResource", new()
{
    ListenerId = "string",
    LoadBalancerId = "string",
    ResourceId = "string",
    LbAttachmentId = "string",
    Port = 0,
    ResourceType = "string",
});
Copy
example, err := ucloud.NewLbAttachment(ctx, "lbAttachmentResource", &ucloud.LbAttachmentArgs{
ListenerId: pulumi.String("string"),
LoadBalancerId: pulumi.String("string"),
ResourceId: pulumi.String("string"),
LbAttachmentId: pulumi.String("string"),
Port: pulumi.Float64(0),
ResourceType: pulumi.String("string"),
})
Copy
var lbAttachmentResource = new LbAttachment("lbAttachmentResource", LbAttachmentArgs.builder()
    .listenerId("string")
    .loadBalancerId("string")
    .resourceId("string")
    .lbAttachmentId("string")
    .port(0)
    .resourceType("string")
    .build());
Copy
lb_attachment_resource = ucloud.LbAttachment("lbAttachmentResource",
    listener_id="string",
    load_balancer_id="string",
    resource_id="string",
    lb_attachment_id="string",
    port=0,
    resource_type="string")
Copy
const lbAttachmentResource = new ucloud.LbAttachment("lbAttachmentResource", {
    listenerId: "string",
    loadBalancerId: "string",
    resourceId: "string",
    lbAttachmentId: "string",
    port: 0,
    resourceType: "string",
});
Copy
type: ucloud:LbAttachment
properties:
    lbAttachmentId: string
    listenerId: string
    loadBalancerId: string
    port: 0
    resourceId: string
    resourceType: string
Copy

LbAttachment 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 LbAttachment resource accepts the following input properties:

ListenerId This property is required. string
The ID of a listener server.
LoadBalancerId This property is required. string
The ID of a load balancer.
ResourceId This property is required. string
The ID of a backend server.


LbAttachmentId string
The ID of the resource lb attachment.
Port double
The listening port of the backend server, range: 1-65535, (Default: 80). Backend server port have the following restrictions: If the LB listener type is request_proxy, the backend serve can add different ports to implement different service instances of the same IP. Else if LB listener type is packets_transmit, the port of the backend server must be consistent with the LB listening port.
ResourceType string
The types of backend servers, possible values are: instance or UHost as UHost instance.
ListenerId This property is required. string
The ID of a listener server.
LoadBalancerId This property is required. string
The ID of a load balancer.
ResourceId This property is required. string
The ID of a backend server.


LbAttachmentId string
The ID of the resource lb attachment.
Port float64
The listening port of the backend server, range: 1-65535, (Default: 80). Backend server port have the following restrictions: If the LB listener type is request_proxy, the backend serve can add different ports to implement different service instances of the same IP. Else if LB listener type is packets_transmit, the port of the backend server must be consistent with the LB listening port.
ResourceType string
The types of backend servers, possible values are: instance or UHost as UHost instance.
listenerId This property is required. String
The ID of a listener server.
loadBalancerId This property is required. String
The ID of a load balancer.
resourceId This property is required. String
The ID of a backend server.


lbAttachmentId String
The ID of the resource lb attachment.
port Double
The listening port of the backend server, range: 1-65535, (Default: 80). Backend server port have the following restrictions: If the LB listener type is request_proxy, the backend serve can add different ports to implement different service instances of the same IP. Else if LB listener type is packets_transmit, the port of the backend server must be consistent with the LB listening port.
resourceType String
The types of backend servers, possible values are: instance or UHost as UHost instance.
listenerId This property is required. string
The ID of a listener server.
loadBalancerId This property is required. string
The ID of a load balancer.
resourceId This property is required. string
The ID of a backend server.


lbAttachmentId string
The ID of the resource lb attachment.
port number
The listening port of the backend server, range: 1-65535, (Default: 80). Backend server port have the following restrictions: If the LB listener type is request_proxy, the backend serve can add different ports to implement different service instances of the same IP. Else if LB listener type is packets_transmit, the port of the backend server must be consistent with the LB listening port.
resourceType string
The types of backend servers, possible values are: instance or UHost as UHost instance.
listener_id This property is required. str
The ID of a listener server.
load_balancer_id This property is required. str
The ID of a load balancer.
resource_id This property is required. str
The ID of a backend server.


lb_attachment_id str
The ID of the resource lb attachment.
port float
The listening port of the backend server, range: 1-65535, (Default: 80). Backend server port have the following restrictions: If the LB listener type is request_proxy, the backend serve can add different ports to implement different service instances of the same IP. Else if LB listener type is packets_transmit, the port of the backend server must be consistent with the LB listening port.
resource_type str
The types of backend servers, possible values are: instance or UHost as UHost instance.
listenerId This property is required. String
The ID of a listener server.
loadBalancerId This property is required. String
The ID of a load balancer.
resourceId This property is required. String
The ID of a backend server.


lbAttachmentId String
The ID of the resource lb attachment.
port Number
The listening port of the backend server, range: 1-65535, (Default: 80). Backend server port have the following restrictions: If the LB listener type is request_proxy, the backend serve can add different ports to implement different service instances of the same IP. Else if LB listener type is packets_transmit, the port of the backend server must be consistent with the LB listening port.
resourceType String
The types of backend servers, possible values are: instance or UHost as UHost instance.

Outputs

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

Id string
The provider-assigned unique ID for this managed resource.
PrivateIp string
The private ip address for backend servers.
Status string
The status of backend servers. Possible values are: normalRunning, exceptionRunning.
Id string
The provider-assigned unique ID for this managed resource.
PrivateIp string
The private ip address for backend servers.
Status string
The status of backend servers. Possible values are: normalRunning, exceptionRunning.
id String
The provider-assigned unique ID for this managed resource.
privateIp String
The private ip address for backend servers.
status String
The status of backend servers. Possible values are: normalRunning, exceptionRunning.
id string
The provider-assigned unique ID for this managed resource.
privateIp string
The private ip address for backend servers.
status string
The status of backend servers. Possible values are: normalRunning, exceptionRunning.
id str
The provider-assigned unique ID for this managed resource.
private_ip str
The private ip address for backend servers.
status str
The status of backend servers. Possible values are: normalRunning, exceptionRunning.
id String
The provider-assigned unique ID for this managed resource.
privateIp String
The private ip address for backend servers.
status String
The status of backend servers. Possible values are: normalRunning, exceptionRunning.

Look up Existing LbAttachment Resource

Get an existing LbAttachment 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?: LbAttachmentState, opts?: CustomResourceOptions): LbAttachment
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        lb_attachment_id: Optional[str] = None,
        listener_id: Optional[str] = None,
        load_balancer_id: Optional[str] = None,
        port: Optional[float] = None,
        private_ip: Optional[str] = None,
        resource_id: Optional[str] = None,
        resource_type: Optional[str] = None,
        status: Optional[str] = None) -> LbAttachment
func GetLbAttachment(ctx *Context, name string, id IDInput, state *LbAttachmentState, opts ...ResourceOption) (*LbAttachment, error)
public static LbAttachment Get(string name, Input<string> id, LbAttachmentState? state, CustomResourceOptions? opts = null)
public static LbAttachment get(String name, Output<String> id, LbAttachmentState state, CustomResourceOptions options)
resources:  _:    type: ucloud:LbAttachment    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
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:
LbAttachmentId string
The ID of the resource lb attachment.
ListenerId string
The ID of a listener server.
LoadBalancerId string
The ID of a load balancer.
Port double
The listening port of the backend server, range: 1-65535, (Default: 80). Backend server port have the following restrictions: If the LB listener type is request_proxy, the backend serve can add different ports to implement different service instances of the same IP. Else if LB listener type is packets_transmit, the port of the backend server must be consistent with the LB listening port.
PrivateIp string
The private ip address for backend servers.
ResourceId string
The ID of a backend server.


ResourceType string
The types of backend servers, possible values are: instance or UHost as UHost instance.
Status string
The status of backend servers. Possible values are: normalRunning, exceptionRunning.
LbAttachmentId string
The ID of the resource lb attachment.
ListenerId string
The ID of a listener server.
LoadBalancerId string
The ID of a load balancer.
Port float64
The listening port of the backend server, range: 1-65535, (Default: 80). Backend server port have the following restrictions: If the LB listener type is request_proxy, the backend serve can add different ports to implement different service instances of the same IP. Else if LB listener type is packets_transmit, the port of the backend server must be consistent with the LB listening port.
PrivateIp string
The private ip address for backend servers.
ResourceId string
The ID of a backend server.


ResourceType string
The types of backend servers, possible values are: instance or UHost as UHost instance.
Status string
The status of backend servers. Possible values are: normalRunning, exceptionRunning.
lbAttachmentId String
The ID of the resource lb attachment.
listenerId String
The ID of a listener server.
loadBalancerId String
The ID of a load balancer.
port Double
The listening port of the backend server, range: 1-65535, (Default: 80). Backend server port have the following restrictions: If the LB listener type is request_proxy, the backend serve can add different ports to implement different service instances of the same IP. Else if LB listener type is packets_transmit, the port of the backend server must be consistent with the LB listening port.
privateIp String
The private ip address for backend servers.
resourceId String
The ID of a backend server.


resourceType String
The types of backend servers, possible values are: instance or UHost as UHost instance.
status String
The status of backend servers. Possible values are: normalRunning, exceptionRunning.
lbAttachmentId string
The ID of the resource lb attachment.
listenerId string
The ID of a listener server.
loadBalancerId string
The ID of a load balancer.
port number
The listening port of the backend server, range: 1-65535, (Default: 80). Backend server port have the following restrictions: If the LB listener type is request_proxy, the backend serve can add different ports to implement different service instances of the same IP. Else if LB listener type is packets_transmit, the port of the backend server must be consistent with the LB listening port.
privateIp string
The private ip address for backend servers.
resourceId string
The ID of a backend server.


resourceType string
The types of backend servers, possible values are: instance or UHost as UHost instance.
status string
The status of backend servers. Possible values are: normalRunning, exceptionRunning.
lb_attachment_id str
The ID of the resource lb attachment.
listener_id str
The ID of a listener server.
load_balancer_id str
The ID of a load balancer.
port float
The listening port of the backend server, range: 1-65535, (Default: 80). Backend server port have the following restrictions: If the LB listener type is request_proxy, the backend serve can add different ports to implement different service instances of the same IP. Else if LB listener type is packets_transmit, the port of the backend server must be consistent with the LB listening port.
private_ip str
The private ip address for backend servers.
resource_id str
The ID of a backend server.


resource_type str
The types of backend servers, possible values are: instance or UHost as UHost instance.
status str
The status of backend servers. Possible values are: normalRunning, exceptionRunning.
lbAttachmentId String
The ID of the resource lb attachment.
listenerId String
The ID of a listener server.
loadBalancerId String
The ID of a load balancer.
port Number
The listening port of the backend server, range: 1-65535, (Default: 80). Backend server port have the following restrictions: If the LB listener type is request_proxy, the backend serve can add different ports to implement different service instances of the same IP. Else if LB listener type is packets_transmit, the port of the backend server must be consistent with the LB listening port.
privateIp String
The private ip address for backend servers.
resourceId String
The ID of a backend server.


resourceType String
The types of backend servers, possible values are: instance or UHost as UHost instance.
status String
The status of backend servers. Possible values are: normalRunning, exceptionRunning.

Import

LB Listener can be imported using the id, e.g.

$ pulumi import ucloud:index/lbAttachment:LbAttachment example backend-abcdefg
Copy

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

Package Details

Repository
ucloud ucloud/terraform-provider-ucloud
License
Notes
This Pulumi package is based on the ucloud Terraform Provider.