Show / Hide Table of Contents

Class Rule

A forwarding rule is configured in HTTP/HTTPS listener and it used to listen a list of backend servers which in one specified virtual backend server group. You can add forwarding rules to a listener to forward requests based on the domain names or the URL in the request.

NOTE: One virtual backend server group can be attached in multiple forwarding rules.

NOTE: At least one "Domain" or "Url" must be specified when creating a new rule.

NOTE: Having the same 'Domain' and 'Url' rule can not be created repeatedly in the one listener.

NOTE: Rule only be created in the HTTP or HTTPS listener.

NOTE: Only rule's virtual server group can be modified.

Example Usage

using System.Linq;
using Pulumi;
using AliCloud = Pulumi.AliCloud;

class MyStack : Stack
{
public MyStack()
{
    var config = new Config();
    var name = config.Get("name") ?? "slbrulebasicconfig";
    var defaultZones = Output.Create(AliCloud.GetZones.InvokeAsync(new AliCloud.GetZonesArgs
    {
        AvailableDiskCategory = "cloud_efficiency",
        AvailableResourceCreation = "VSwitch",
    }));
    var defaultInstanceTypes = defaultZones.Apply(defaultZones => Output.Create(AliCloud.Ecs.GetInstanceTypes.InvokeAsync(new AliCloud.Ecs.GetInstanceTypesArgs
    {
        AvailabilityZone = defaultZones.Zones[0].Id,
        CpuCoreCount = 1,
        MemorySize = 2,
    })));
    var defaultImages = Output.Create(AliCloud.Ecs.GetImages.InvokeAsync(new AliCloud.Ecs.GetImagesArgs
    {
        MostRecent = true,
        NameRegex = "^ubuntu_18.*64",
        Owners = "system",
    }));
    var defaultNetwork = new AliCloud.Vpc.Network("defaultNetwork", new AliCloud.Vpc.NetworkArgs
    {
        CidrBlock = "172.16.0.0/16",
    });
    var defaultSwitch = new AliCloud.Vpc.Switch("defaultSwitch", new AliCloud.Vpc.SwitchArgs
    {
        AvailabilityZone = defaultZones.Apply(defaultZones => defaultZones.Zones[0].Id),
        CidrBlock = "172.16.0.0/16",
        VpcId = defaultNetwork.Id,
    });
    var defaultSecurityGroup = new AliCloud.Ecs.SecurityGroup("defaultSecurityGroup", new AliCloud.Ecs.SecurityGroupArgs
    {
        VpcId = defaultNetwork.Id,
    });
    var defaultInstance = new AliCloud.Ecs.Instance("defaultInstance", new AliCloud.Ecs.InstanceArgs
    {
        AvailabilityZone = defaultZones.Apply(defaultZones => defaultZones.Zones[0].Id),
        ImageId = defaultImages.Apply(defaultImages => defaultImages.Images[0].Id),
        InstanceChargeType = "PostPaid",
        InstanceName = name,
        InstanceType = defaultInstanceTypes.Apply(defaultInstanceTypes => defaultInstanceTypes.InstanceTypes[0].Id),
        InternetChargeType = "PayByTraffic",
        InternetMaxBandwidthOut = "10",
        SecurityGroups = 
        {
            defaultSecurityGroup,
        }.Select(__item => __item.Id).ToList(),
        SystemDiskCategory = "cloud_efficiency",
        VswitchId = defaultSwitch.Id,
    });
    var defaultLoadBalancer = new AliCloud.Slb.LoadBalancer("defaultLoadBalancer", new AliCloud.Slb.LoadBalancerArgs
    {
        VswitchId = defaultSwitch.Id,
    });
    var defaultListener = new AliCloud.Slb.Listener("defaultListener", new AliCloud.Slb.ListenerArgs
    {
        BackendPort = 22,
        Bandwidth = 5,
        FrontendPort = 22,
        HealthCheckConnectPort = "20",
        LoadBalancerId = defaultLoadBalancer.Id,
        Protocol = "http",
    });
    var defaultServerGroup = new AliCloud.Slb.ServerGroup("defaultServerGroup", new AliCloud.Slb.ServerGroupArgs
    {
        LoadBalancerId = defaultLoadBalancer.Id,
        Servers = 
        {
            new AliCloud.Slb.Inputs.ServerGroupServerArgs
            {
                Port = 80,
                ServerIds = 
                {
                    defaultInstance,
                }.Select(__item => __item.Id).ToList(),
                Weight = 100,
            },
        },
    });
    var defaultRule = new AliCloud.Slb.Rule("defaultRule", new AliCloud.Slb.RuleArgs
    {
        Cookie = "23ffsa",
        CookieTimeout = 100,
        Domain = "*.aliyun.com",
        FrontendPort = defaultListener.FrontendPort,
        HealthCheck = "on",
        HealthCheckConnectPort = 80,
        HealthCheckDomain = "test",
        HealthCheckHttpCode = "http_2xx",
        HealthCheckInterval = 10,
        HealthCheckTimeout = 30,
        HealthCheckUri = "/test",
        HealthyThreshold = 3,
        ListenerSync = "off",
        LoadBalancerId = defaultLoadBalancer.Id,
        Scheduler = "rr",
        ServerGroupId = defaultServerGroup.Id,
        StickySession = "on",
        StickySessionType = "server",
        UnhealthyThreshold = 5,
        Url = "/image",
    });
}

}
Inheritance
System.Object
Resource
CustomResource
Rule
Inherited Members
CustomResource.Id
Resource.GetResourceType()
Resource.GetResourceName()
Resource.Urn
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Pulumi.AliCloud.Slb
Assembly: Pulumi.AliCloud.dll
Syntax
public class Rule : CustomResource

Constructors

View Source

Rule(String, RuleArgs, CustomResourceOptions)

Create a Rule resource with the given unique name, arguments, and options.

Declaration
public Rule(string name, RuleArgs args, CustomResourceOptions options = null)
Parameters
Type Name Description
System.String name

The unique name of the resource

RuleArgs args

The arguments used to populate this resource's properties

CustomResourceOptions options

A bag of options that control this resource's behavior

Properties

View Source

Cookie

The cookie configured on the server. It is mandatory when sticky_session is "on" and sticky_session_type is "server". Otherwise, it will be ignored. Valid value:String in line with RFC 2965, with length being 1- 200. It only contains characters such as ASCII codes, English letters and digits instead of the comma, semicolon or spacing, and it cannot start with $.

Declaration
public Output<string> Cookie { get; }
Property Value
Type Description
Output<System.String>
View Source

CookieTimeout

Cookie timeout. It is mandatory when sticky_session is "on" and sticky_session_type is "insert". Otherwise, it will be ignored. Valid value range: [1-86400] in seconds.

Declaration
public Output<int?> CookieTimeout { get; }
Property Value
Type Description
Output<System.Nullable<System.Int32>>
View Source

DeleteProtectionValidation

Checking DeleteProtection of SLB instance before deleting. If true, this resource will not be deleted when its SLB instance enabled DeleteProtection. Default to false.

Declaration
public Output<bool?> DeleteProtectionValidation { get; }
Property Value
Type Description
Output<System.Nullable<System.Boolean>>
View Source

Domain

Domain name of the forwarding rule. It can contain letters a-z, numbers 0-9, hyphens (-), and periods (.), and wildcard characters. The following two domain name formats are supported:

  • Standard domain name: www.test.com
  • Wildcard domain name: .test.com. wildcard () must be the first character in the format of (*.)
Declaration
public Output<string> Domain { get; }
Property Value
Type Description
Output<System.String>
View Source

FrontendPort

The listener frontend port which is used to launch the new forwarding rule. Valid range: [1-65535].

Declaration
public Output<int> FrontendPort { get; }
Property Value
Type Description
Output<System.Int32>
View Source

HealthCheck

Whether to enable health check. Valid values areon and off. TCP and UDP listener's HealthCheck is always on, so it will be ignore when launching TCP or UDP listener. This parameter is required and takes effect only when ListenerSync is set to off.

Declaration
public Output<string> HealthCheck { get; }
Property Value
Type Description
Output<System.String>
View Source

HealthCheckConnectPort

Port used for health check. Valid value range: [1-65535]. Default to "None" means the backend server port is used.

Declaration
public Output<int> HealthCheckConnectPort { get; }
Property Value
Type Description
Output<System.Int32>
View Source

HealthCheckDomain

Domain name used for health check. When it used to launch TCP listener, health_check_type must be "http". Its length is limited to 1-80 and only characters such as letters, digits, ‘-‘ and ‘.’ are allowed. When it is not set or empty, Server Load Balancer uses the private network IP address of each backend server as Domain used for health check.

Declaration
public Output<string> HealthCheckDomain { get; }
Property Value
Type Description
Output<System.String>
View Source

HealthCheckHttpCode

Regular health check HTTP status code. Multiple codes are segmented by “,”. It is required when health_check is on. Default to http_2xx. Valid values are: http_2xx, http_3xx, http_4xx and http_5xx.

Declaration
public Output<string> HealthCheckHttpCode { get; }
Property Value
Type Description
Output<System.String>
View Source

HealthCheckInterval

Time interval of health checks. It is required when health_check is on. Valid value range: [1-50] in seconds. Default to 2.

Declaration
public Output<int?> HealthCheckInterval { get; }
Property Value
Type Description
Output<System.Nullable<System.Int32>>
View Source

HealthCheckTimeout

Maximum timeout of each health check response. It is required when health_check is on. Valid value range: [1-300] in seconds. Default to 5. Note: If health_check_timeout < health_check_interval, its will be replaced by health_check_interval.

Declaration
public Output<int?> HealthCheckTimeout { get; }
Property Value
Type Description
Output<System.Nullable<System.Int32>>
View Source

HealthCheckUri

URI used for health check. When it used to launch TCP listener, health_check_type must be "http". Its length is limited to 1-80 and it must start with /. Only characters such as letters, digits, ‘-’, ‘/’, ‘.’, ‘%’, ‘?’, #’ and ‘&’ are allowed.

Declaration
public Output<string> HealthCheckUri { get; }
Property Value
Type Description
Output<System.String>
View Source

HealthyThreshold

Threshold determining the result of the health check is success. It is required when health_check is on. Valid value range: [1-10] in seconds. Default to 3.

Declaration
public Output<int?> HealthyThreshold { get; }
Property Value
Type Description
Output<System.Nullable<System.Int32>>
View Source

ListenerSync

Indicates whether a forwarding rule inherits the settings of a health check , session persistence, and scheduling algorithm from a listener. Default to on.

Declaration
public Output<string> ListenerSync { get; }
Property Value
Type Description
Output<System.String>
View Source

LoadBalancerId

The Load Balancer ID which is used to launch the new forwarding rule.

Declaration
public Output<string> LoadBalancerId { get; }
Property Value
Type Description
Output<System.String>
View Source

Name

Name of the forwarding rule. Our plugin provides a default name: "tf-slb-rule".

Declaration
public Output<string> Name { get; }
Property Value
Type Description
Output<System.String>
View Source

Scheduler

Scheduling algorithm, Valid values are wrr, rr and wlc. Default to "wrr". This parameter is required and takes effect only when ListenerSync is set to off.

Declaration
public Output<string> Scheduler { get; }
Property Value
Type Description
Output<System.String>
View Source

ServerGroupId

ID of a virtual server group that will be forwarded.

Declaration
public Output<string> ServerGroupId { get; }
Property Value
Type Description
Output<System.String>
View Source

StickySession

Whether to enable session persistence, Valid values are on and off. Default to off. This parameter is required and takes effect only when ListenerSync is set to off.

Declaration
public Output<string> StickySession { get; }
Property Value
Type Description
Output<System.String>
View Source

StickySessionType

Mode for handling the cookie. If sticky_session is "on", it is mandatory. Otherwise, it will be ignored. Valid values are insert and server. insert means it is inserted from Server Load Balancer; server means the Server Load Balancer learns from the backend server.

Declaration
public Output<string> StickySessionType { get; }
Property Value
Type Description
Output<System.String>
View Source

UnhealthyThreshold

Threshold determining the result of the health check is fail. It is required when health_check is on. Valid value range: [1-10] in seconds. Default to 3.

Declaration
public Output<int?> UnhealthyThreshold { get; }
Property Value
Type Description
Output<System.Nullable<System.Int32>>
View Source

Url

Domain of the forwarding rule. It must be 2-80 characters in length. Only letters a-z, numbers 0-9, and characters '-' '/' '?' '%' '#' and '&' are allowed. URLs must be started with the character '/', but cannot be '/' alone.

Declaration
public Output<string> Url { get; }
Property Value
Type Description
Output<System.String>

Methods

View Source

Get(String, Input<String>, RuleState, CustomResourceOptions)

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

Declaration
public static Rule Get(string name, Input<string> id, RuleState state = null, CustomResourceOptions options = null)
Parameters
Type Name Description
System.String name

The unique name of the resulting resource.

Input<System.String> id

The unique provider ID of the resource to lookup.

RuleState state

Any extra arguments used during the lookup.

CustomResourceOptions options

A bag of options that control this resource's behavior

Returns
Type Description
Rule
  • View Source
Back to top Copyright 2016-2020, Pulumi Corporation.