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

ucloud.LbRule

Explore with Pulumi AI

ucloud logo
ucloud 1.39.1 published on Monday, Apr 14, 2025 by ucloud

    Provides a Load Balancer Rule resource to add content forwarding policies for Load Balancer backend resource.

    Note The Load Balancer Rule can only be define while the protocol of lb listener is one of HTTP and HTTPS. In addition, should set one of domain and path if defined.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as ucloud from "@pulumi/ucloud";
    
    const defaultImages = ucloud.getImages({
        availabilityZone: "cn-bj2-02",
        nameRegex: "^CentOS 6.5 64",
        imageType: "base",
    });
    const webLb = new ucloud.Lb("webLb", {tag: "tf-example"});
    const defaultLbListener = new ucloud.LbListener("defaultLbListener", {
        loadBalancerId: webLb.lbId,
        protocol: "http",
    });
    const webInstance = new ucloud.Instance("webInstance", {
        instanceType: "n-basic-2",
        availabilityZone: "cn-bj2-02",
        rootPassword: "wA1234567",
        imageId: defaultImages.then(defaultImages => defaultImages.images?.[0]?.id),
        tag: "tf-example",
    });
    const defaultLbAttachment = new ucloud.LbAttachment("defaultLbAttachment", {
        loadBalancerId: webLb.lbId,
        listenerId: defaultLbListener.lbListenerId,
        resourceType: "instance",
        resourceId: webInstance.instanceId,
        port: 80,
    });
    const example = new ucloud.LbRule("example", {
        loadBalancerId: webLb.lbId,
        listenerId: defaultLbListener.lbListenerId,
        backendIds: [defaultLbAttachment].map(__item => __item.id),
        domain: "www.ucloud.cn",
    });
    
    import pulumi
    import pulumi_ucloud as ucloud
    
    default_images = ucloud.get_images(availability_zone="cn-bj2-02",
        name_regex="^CentOS 6.5 64",
        image_type="base")
    web_lb = ucloud.Lb("webLb", tag="tf-example")
    default_lb_listener = ucloud.LbListener("defaultLbListener",
        load_balancer_id=web_lb.lb_id,
        protocol="http")
    web_instance = ucloud.Instance("webInstance",
        instance_type="n-basic-2",
        availability_zone="cn-bj2-02",
        root_password="wA1234567",
        image_id=default_images.images[0].id,
        tag="tf-example")
    default_lb_attachment = ucloud.LbAttachment("defaultLbAttachment",
        load_balancer_id=web_lb.lb_id,
        listener_id=default_lb_listener.lb_listener_id,
        resource_type="instance",
        resource_id=web_instance.instance_id,
        port=80)
    example = ucloud.LbRule("example",
        load_balancer_id=web_lb.lb_id,
        listener_id=default_lb_listener.lb_listener_id,
        backend_ids=[__item.id for __item in [default_lb_attachment]],
        domain="www.ucloud.cn")
    
    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-02"),
    NameRegex: pulumi.StringRef("^CentOS 6.5 64"),
    ImageType: pulumi.StringRef("base"),
    }, nil);
    if err != nil {
    return err
    }
    webLb, err := ucloud.NewLb(ctx, "webLb", &ucloud.LbArgs{
    Tag: pulumi.String("tf-example"),
    })
    if err != nil {
    return err
    }
    defaultLbListener, err := ucloud.NewLbListener(ctx, "defaultLbListener", &ucloud.LbListenerArgs{
    LoadBalancerId: webLb.LbId,
    Protocol: pulumi.String("http"),
    })
    if err != nil {
    return err
    }
    webInstance, err := ucloud.NewInstance(ctx, "webInstance", &ucloud.InstanceArgs{
    InstanceType: pulumi.String("n-basic-2"),
    AvailabilityZone: pulumi.String("cn-bj2-02"),
    RootPassword: pulumi.String("wA1234567"),
    ImageId: pulumi.String(defaultImages.Images[0].Id),
    Tag: pulumi.String("tf-example"),
    })
    if err != nil {
    return err
    }
    defaultLbAttachment, err := ucloud.NewLbAttachment(ctx, "defaultLbAttachment", &ucloud.LbAttachmentArgs{
    LoadBalancerId: webLb.LbId,
    ListenerId: defaultLbListener.LbListenerId,
    ResourceType: pulumi.String("instance"),
    ResourceId: webInstance.InstanceId,
    Port: pulumi.Float64(80),
    })
    if err != nil {
    return err
    }
    var splat0 pulumi.StringArray
    for _, val0 := range %!v(PANIC=Format method: fatal: An assertion has failed: tok: ) {
    splat0 = append(splat0, val0.ID())
    }
    _, err = ucloud.NewLbRule(ctx, "example", &ucloud.LbRuleArgs{
    LoadBalancerId: webLb.LbId,
    ListenerId: defaultLbListener.LbListenerId,
    BackendIds: splat0,
    Domain: pulumi.String("www.ucloud.cn"),
    })
    if err != nil {
    return err
    }
    return nil
    })
    }
    
    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-02",
            NameRegex = "^CentOS 6.5 64",
            ImageType = "base",
        });
    
        var webLb = new Ucloud.Lb("webLb", new()
        {
            Tag = "tf-example",
        });
    
        var defaultLbListener = new Ucloud.LbListener("defaultLbListener", new()
        {
            LoadBalancerId = webLb.LbId,
            Protocol = "http",
        });
    
        var webInstance = new Ucloud.Instance("webInstance", new()
        {
            InstanceType = "n-basic-2",
            AvailabilityZone = "cn-bj2-02",
            RootPassword = "wA1234567",
            ImageId = defaultImages.Apply(getImagesResult => getImagesResult.Images[0]?.Id),
            Tag = "tf-example",
        });
    
        var defaultLbAttachment = new Ucloud.LbAttachment("defaultLbAttachment", new()
        {
            LoadBalancerId = webLb.LbId,
            ListenerId = defaultLbListener.LbListenerId,
            ResourceType = "instance",
            ResourceId = webInstance.InstanceId,
            Port = 80,
        });
    
        var example = new Ucloud.LbRule("example", new()
        {
            LoadBalancerId = webLb.LbId,
            ListenerId = defaultLbListener.LbListenerId,
            BackendIds = new[]
            {
                defaultLbAttachment,
            }.Select(__item => __item.Id).ToList(),
            Domain = "www.ucloud.cn",
        });
    
    });
    
    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 com.pulumi.ucloud.LbRule;
    import com.pulumi.ucloud.LbRuleArgs;
    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-02")
                .nameRegex("^CentOS 6.5 64")
                .imageType("base")
                .build());
    
            var webLb = new Lb("webLb", LbArgs.builder()
                .tag("tf-example")
                .build());
    
            var defaultLbListener = new LbListener("defaultLbListener", LbListenerArgs.builder()
                .loadBalancerId(webLb.lbId())
                .protocol("http")
                .build());
    
            var webInstance = new Instance("webInstance", InstanceArgs.builder()
                .instanceType("n-basic-2")
                .availabilityZone("cn-bj2-02")
                .rootPassword("wA1234567")
                .imageId(defaultImages.applyValue(getImagesResult -> getImagesResult.images()[0].id()))
                .tag("tf-example")
                .build());
    
            var defaultLbAttachment = new LbAttachment("defaultLbAttachment", LbAttachmentArgs.builder()
                .loadBalancerId(webLb.lbId())
                .listenerId(defaultLbListener.lbListenerId())
                .resourceType("instance")
                .resourceId(webInstance.instanceId())
                .port(80)
                .build());
    
            var example = new LbRule("example", LbRuleArgs.builder()
                .loadBalancerId(webLb.lbId())
                .listenerId(defaultLbListener.lbListenerId())
                .backendIds(defaultLbAttachment.stream().map(element -> element.id()).collect(toList()))
                .domain("www.ucloud.cn")
                .build());
    
        }
    }
    
    Coming soon!
    

    Create LbRule Resource

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

    Constructor syntax

    new LbRule(name: string, args: LbRuleArgs, opts?: CustomResourceOptions);
    @overload
    def LbRule(resource_name: str,
               args: LbRuleArgs,
               opts: Optional[ResourceOptions] = None)
    
    @overload
    def LbRule(resource_name: str,
               opts: Optional[ResourceOptions] = None,
               backend_ids: Optional[Sequence[str]] = None,
               listener_id: Optional[str] = None,
               load_balancer_id: Optional[str] = None,
               domain: Optional[str] = None,
               lb_rule_id: Optional[str] = None,
               path: Optional[str] = None)
    func NewLbRule(ctx *Context, name string, args LbRuleArgs, opts ...ResourceOption) (*LbRule, error)
    public LbRule(string name, LbRuleArgs args, CustomResourceOptions? opts = null)
    public LbRule(String name, LbRuleArgs args)
    public LbRule(String name, LbRuleArgs args, CustomResourceOptions options)
    
    type: ucloud:LbRule
    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 LbRuleArgs
    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 LbRuleArgs
    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 LbRuleArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args LbRuleArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args LbRuleArgs
    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 lbRuleResource = new Ucloud.LbRule("lbRuleResource", new()
    {
        BackendIds = new[]
        {
            "string",
        },
        ListenerId = "string",
        LoadBalancerId = "string",
        Domain = "string",
        LbRuleId = "string",
        Path = "string",
    });
    
    example, err := ucloud.NewLbRule(ctx, "lbRuleResource", &ucloud.LbRuleArgs{
    	BackendIds: pulumi.StringArray{
    		pulumi.String("string"),
    	},
    	ListenerId:     pulumi.String("string"),
    	LoadBalancerId: pulumi.String("string"),
    	Domain:         pulumi.String("string"),
    	LbRuleId:       pulumi.String("string"),
    	Path:           pulumi.String("string"),
    })
    
    var lbRuleResource = new LbRule("lbRuleResource", LbRuleArgs.builder()
        .backendIds("string")
        .listenerId("string")
        .loadBalancerId("string")
        .domain("string")
        .lbRuleId("string")
        .path("string")
        .build());
    
    lb_rule_resource = ucloud.LbRule("lbRuleResource",
        backend_ids=["string"],
        listener_id="string",
        load_balancer_id="string",
        domain="string",
        lb_rule_id="string",
        path="string")
    
    const lbRuleResource = new ucloud.LbRule("lbRuleResource", {
        backendIds: ["string"],
        listenerId: "string",
        loadBalancerId: "string",
        domain: "string",
        lbRuleId: "string",
        path: "string",
    });
    
    type: ucloud:LbRule
    properties:
        backendIds:
            - string
        domain: string
        lbRuleId: string
        listenerId: string
        loadBalancerId: string
        path: string
    

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

    BackendIds List<string>
    The IDs of the backend servers where rule applies, this argument is populated base on the backend_id responded from lb_attachment create.


    ListenerId string
    The ID of a listener server.
    LoadBalancerId string
    The ID of a load balancer.
    Domain string
    The domain of content forward matching fields. path and domain cannot coexist. path and domain must be filled in one.
    LbRuleId string
    The ID of the resource lb rule.
    Path string
    The path of Content forward matching fields. path and domain cannot coexist. path and domain must be filled in one.
    BackendIds []string
    The IDs of the backend servers where rule applies, this argument is populated base on the backend_id responded from lb_attachment create.


    ListenerId string
    The ID of a listener server.
    LoadBalancerId string
    The ID of a load balancer.
    Domain string
    The domain of content forward matching fields. path and domain cannot coexist. path and domain must be filled in one.
    LbRuleId string
    The ID of the resource lb rule.
    Path string
    The path of Content forward matching fields. path and domain cannot coexist. path and domain must be filled in one.
    backendIds List<String>
    The IDs of the backend servers where rule applies, this argument is populated base on the backend_id responded from lb_attachment create.


    listenerId String
    The ID of a listener server.
    loadBalancerId String
    The ID of a load balancer.
    domain String
    The domain of content forward matching fields. path and domain cannot coexist. path and domain must be filled in one.
    lbRuleId String
    The ID of the resource lb rule.
    path String
    The path of Content forward matching fields. path and domain cannot coexist. path and domain must be filled in one.
    backendIds string[]
    The IDs of the backend servers where rule applies, this argument is populated base on the backend_id responded from lb_attachment create.


    listenerId string
    The ID of a listener server.
    loadBalancerId string
    The ID of a load balancer.
    domain string
    The domain of content forward matching fields. path and domain cannot coexist. path and domain must be filled in one.
    lbRuleId string
    The ID of the resource lb rule.
    path string
    The path of Content forward matching fields. path and domain cannot coexist. path and domain must be filled in one.
    backend_ids Sequence[str]
    The IDs of the backend servers where rule applies, this argument is populated base on the backend_id responded from lb_attachment create.


    listener_id str
    The ID of a listener server.
    load_balancer_id str
    The ID of a load balancer.
    domain str
    The domain of content forward matching fields. path and domain cannot coexist. path and domain must be filled in one.
    lb_rule_id str
    The ID of the resource lb rule.
    path str
    The path of Content forward matching fields. path and domain cannot coexist. path and domain must be filled in one.
    backendIds List<String>
    The IDs of the backend servers where rule applies, this argument is populated base on the backend_id responded from lb_attachment create.


    listenerId String
    The ID of a listener server.
    loadBalancerId String
    The ID of a load balancer.
    domain String
    The domain of content forward matching fields. path and domain cannot coexist. path and domain must be filled in one.
    lbRuleId String
    The ID of the resource lb rule.
    path String
    The path of Content forward matching fields. path and domain cannot coexist. path and domain must be filled in one.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the LbRule 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 LbRule Resource

    Get an existing LbRule 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?: LbRuleState, opts?: CustomResourceOptions): LbRule
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            backend_ids: Optional[Sequence[str]] = None,
            domain: Optional[str] = None,
            lb_rule_id: Optional[str] = None,
            listener_id: Optional[str] = None,
            load_balancer_id: Optional[str] = None,
            path: Optional[str] = None) -> LbRule
    func GetLbRule(ctx *Context, name string, id IDInput, state *LbRuleState, opts ...ResourceOption) (*LbRule, error)
    public static LbRule Get(string name, Input<string> id, LbRuleState? state, CustomResourceOptions? opts = null)
    public static LbRule get(String name, Output<String> id, LbRuleState state, CustomResourceOptions options)
    resources:  _:    type: ucloud:LbRule    get:      id: ${id}
    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:
    BackendIds List<string>
    The IDs of the backend servers where rule applies, this argument is populated base on the backend_id responded from lb_attachment create.


    Domain string
    The domain of content forward matching fields. path and domain cannot coexist. path and domain must be filled in one.
    LbRuleId string
    The ID of the resource lb rule.
    ListenerId string
    The ID of a listener server.
    LoadBalancerId string
    The ID of a load balancer.
    Path string
    The path of Content forward matching fields. path and domain cannot coexist. path and domain must be filled in one.
    BackendIds []string
    The IDs of the backend servers where rule applies, this argument is populated base on the backend_id responded from lb_attachment create.


    Domain string
    The domain of content forward matching fields. path and domain cannot coexist. path and domain must be filled in one.
    LbRuleId string
    The ID of the resource lb rule.
    ListenerId string
    The ID of a listener server.
    LoadBalancerId string
    The ID of a load balancer.
    Path string
    The path of Content forward matching fields. path and domain cannot coexist. path and domain must be filled in one.
    backendIds List<String>
    The IDs of the backend servers where rule applies, this argument is populated base on the backend_id responded from lb_attachment create.


    domain String
    The domain of content forward matching fields. path and domain cannot coexist. path and domain must be filled in one.
    lbRuleId String
    The ID of the resource lb rule.
    listenerId String
    The ID of a listener server.
    loadBalancerId String
    The ID of a load balancer.
    path String
    The path of Content forward matching fields. path and domain cannot coexist. path and domain must be filled in one.
    backendIds string[]
    The IDs of the backend servers where rule applies, this argument is populated base on the backend_id responded from lb_attachment create.


    domain string
    The domain of content forward matching fields. path and domain cannot coexist. path and domain must be filled in one.
    lbRuleId string
    The ID of the resource lb rule.
    listenerId string
    The ID of a listener server.
    loadBalancerId string
    The ID of a load balancer.
    path string
    The path of Content forward matching fields. path and domain cannot coexist. path and domain must be filled in one.
    backend_ids Sequence[str]
    The IDs of the backend servers where rule applies, this argument is populated base on the backend_id responded from lb_attachment create.


    domain str
    The domain of content forward matching fields. path and domain cannot coexist. path and domain must be filled in one.
    lb_rule_id str
    The ID of the resource lb rule.
    listener_id str
    The ID of a listener server.
    load_balancer_id str
    The ID of a load balancer.
    path str
    The path of Content forward matching fields. path and domain cannot coexist. path and domain must be filled in one.
    backendIds List<String>
    The IDs of the backend servers where rule applies, this argument is populated base on the backend_id responded from lb_attachment create.


    domain String
    The domain of content forward matching fields. path and domain cannot coexist. path and domain must be filled in one.
    lbRuleId String
    The ID of the resource lb rule.
    listenerId String
    The ID of a listener server.
    loadBalancerId String
    The ID of a load balancer.
    path String
    The path of Content forward matching fields. path and domain cannot coexist. path and domain must be filled in one.

    Import

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

    $ pulumi import ucloud:index/lbRule:LbRule example rule-abcdefg
    

    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.
    ucloud logo
    ucloud 1.39.1 published on Monday, Apr 14, 2025 by ucloud