getRules

This data source provides the rules associated with a server load balancer listener.

Example Usage

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 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
        {
            VpcId = defaultNetwork.Id,
            CidrBlock = "172.16.0.0/16",
            ZoneId = defaultZones.Apply(defaultZones => defaultZones.Zones?[0]?.Id),
            VswitchName = name,
        });
        var defaultApplicationLoadBalancer = new AliCloud.Slb.ApplicationLoadBalancer("defaultApplicationLoadBalancer", new AliCloud.Slb.ApplicationLoadBalancerArgs
        {
            LoadBalancerName = name,
            VswitchId = defaultSwitch.Id,
        });
        var defaultListener = new AliCloud.Slb.Listener("defaultListener", new AliCloud.Slb.ListenerArgs
        {
            LoadBalancerId = defaultApplicationLoadBalancer.Id,
            BackendPort = 22,
            FrontendPort = 22,
            Protocol = "http",
            Bandwidth = 5,
            HealthCheckConnectPort = 20,
        });
        var defaultServerGroup = new AliCloud.Slb.ServerGroup("defaultServerGroup", new AliCloud.Slb.ServerGroupArgs
        {
            LoadBalancerId = defaultApplicationLoadBalancer.Id,
        });
        var defaultRule = new AliCloud.Slb.Rule("defaultRule", new AliCloud.Slb.RuleArgs
        {
            LoadBalancerId = defaultApplicationLoadBalancer.Id,
            FrontendPort = defaultListener.FrontendPort,
            Domain = "*.aliyun.com",
            Url = "/image",
            ServerGroupId = defaultServerGroup.Id,
        });
        var sampleDs = defaultApplicationLoadBalancer.Id.Apply(id => AliCloud.Slb.GetRules.Invoke(new AliCloud.Slb.GetRulesInvokeArgs
        {
            LoadBalancerId = id,
            FrontendPort = 22,
        }));
        this.FirstSlbRuleId = sampleDs.Apply(sampleDs => sampleDs.SlbRules?[0]?.Id);
    }

    [Output("firstSlbRuleId")]
    public Output<string> FirstSlbRuleId { get; set; }
}
package main

import (
	"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud"
	"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/slb"
	"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/vpc"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		cfg := config.New(ctx, "")
		name := "slbrulebasicconfig"
		if param := cfg.Get("name"); param != "" {
			name = param
		}
		defaultZones, err := alicloud.GetZones(ctx, &GetZonesArgs{
			AvailableDiskCategory:     pulumi.StringRef("cloud_efficiency"),
			AvailableResourceCreation: pulumi.StringRef("VSwitch"),
		}, nil)
		if err != nil {
			return err
		}
		defaultNetwork, err := vpc.NewNetwork(ctx, "defaultNetwork", &vpc.NetworkArgs{
			CidrBlock: pulumi.String("172.16.0.0/16"),
		})
		if err != nil {
			return err
		}
		defaultSwitch, err := vpc.NewSwitch(ctx, "defaultSwitch", &vpc.SwitchArgs{
			VpcId:       defaultNetwork.ID(),
			CidrBlock:   pulumi.String("172.16.0.0/16"),
			ZoneId:      pulumi.String(defaultZones.Zones[0].Id),
			VswitchName: pulumi.String(name),
		})
		if err != nil {
			return err
		}
		defaultApplicationLoadBalancer, err := slb.NewApplicationLoadBalancer(ctx, "defaultApplicationLoadBalancer", &slb.ApplicationLoadBalancerArgs{
			LoadBalancerName: pulumi.String(name),
			VswitchId:        defaultSwitch.ID(),
		})
		if err != nil {
			return err
		}
		defaultListener, err := slb.NewListener(ctx, "defaultListener", &slb.ListenerArgs{
			LoadBalancerId:         defaultApplicationLoadBalancer.ID(),
			BackendPort:            pulumi.Int(22),
			FrontendPort:           pulumi.Int(22),
			Protocol:               pulumi.String("http"),
			Bandwidth:              pulumi.Int(5),
			HealthCheckConnectPort: pulumi.Int(20),
		})
		if err != nil {
			return err
		}
		defaultServerGroup, err := slb.NewServerGroup(ctx, "defaultServerGroup", &slb.ServerGroupArgs{
			LoadBalancerId: defaultApplicationLoadBalancer.ID(),
		})
		if err != nil {
			return err
		}
		_, err = slb.NewRule(ctx, "defaultRule", &slb.RuleArgs{
			LoadBalancerId: defaultApplicationLoadBalancer.ID(),
			FrontendPort:   defaultListener.FrontendPort,
			Domain:         pulumi.String("*.aliyun.com"),
			Url:            pulumi.String("/image"),
			ServerGroupId:  defaultServerGroup.ID(),
		})
		if err != nil {
			return err
		}
		ctx.Export("firstSlbRuleId", sampleDs.ApplyT(func(sampleDs slb.GetRulesResult) (string, error) {
			return sampleDs.SlbRules[0].Id, nil
		}).(pulumi.StringOutput))
		return nil
	})
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.alicloud.AlicloudFunctions;
import com.pulumi.alicloud.adb.inputs.GetZonesArgs;
import com.pulumi.alicloud.vpc.Network;
import com.pulumi.alicloud.vpc.NetworkArgs;
import com.pulumi.alicloud.vpc.Switch;
import com.pulumi.alicloud.vpc.SwitchArgs;
import com.pulumi.alicloud.slb.ApplicationLoadBalancer;
import com.pulumi.alicloud.slb.ApplicationLoadBalancerArgs;
import com.pulumi.alicloud.slb.Listener;
import com.pulumi.alicloud.slb.ListenerArgs;
import com.pulumi.alicloud.slb.ServerGroup;
import com.pulumi.alicloud.slb.ServerGroupArgs;
import com.pulumi.alicloud.slb.Rule;
import com.pulumi.alicloud.slb.RuleArgs;
import com.pulumi.alicloud.slb.SlbFunctions;
import com.pulumi.alicloud.alb.inputs.GetRulesArgs;
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 config = ctx.config();
        final var name = config.get("name").orElse("slbrulebasicconfig");
        final var defaultZones = AlicloudFunctions.getZones(GetZonesArgs.builder()
            .availableDiskCategory("cloud_efficiency")
            .availableResourceCreation("VSwitch")
            .build());

        var defaultNetwork = new Network("defaultNetwork", NetworkArgs.builder()        
            .cidrBlock("172.16.0.0/16")
            .build());

        var defaultSwitch = new Switch("defaultSwitch", SwitchArgs.builder()        
            .vpcId(defaultNetwork.id())
            .cidrBlock("172.16.0.0/16")
            .zoneId(defaultZones.applyValue(getZonesResult -> getZonesResult.zones()[0].id()))
            .vswitchName(name)
            .build());

        var defaultApplicationLoadBalancer = new ApplicationLoadBalancer("defaultApplicationLoadBalancer", ApplicationLoadBalancerArgs.builder()        
            .loadBalancerName(name)
            .vswitchId(defaultSwitch.id())
            .build());

        var defaultListener = new Listener("defaultListener", ListenerArgs.builder()        
            .loadBalancerId(defaultApplicationLoadBalancer.id())
            .backendPort(22)
            .frontendPort(22)
            .protocol("http")
            .bandwidth(5)
            .healthCheckConnectPort("20")
            .build());

        var defaultServerGroup = new ServerGroup("defaultServerGroup", ServerGroupArgs.builder()        
            .loadBalancerId(defaultApplicationLoadBalancer.id())
            .build());

        var defaultRule = new Rule("defaultRule", RuleArgs.builder()        
            .loadBalancerId(defaultApplicationLoadBalancer.id())
            .frontendPort(defaultListener.frontendPort())
            .domain("*.aliyun.com")
            .url("/image")
            .serverGroupId(defaultServerGroup.id())
            .build());

        final var sampleDs = SlbFunctions.getRules(GetRulesArgs.builder()
            .loadBalancerId(defaultApplicationLoadBalancer.id())
            .frontendPort(22)
            .build());

        ctx.export("firstSlbRuleId", sampleDs.applyValue(getRulesResult -> getRulesResult).applyValue(sampleDs -> sampleDs.applyValue(getRulesResult -> getRulesResult.slbRules()[0].id())));
    }
}
import pulumi
import pulumi_alicloud as alicloud

config = pulumi.Config()
name = config.get("name")
if name is None:
    name = "slbrulebasicconfig"
default_zones = alicloud.get_zones(available_disk_category="cloud_efficiency",
    available_resource_creation="VSwitch")
default_network = alicloud.vpc.Network("defaultNetwork", cidr_block="172.16.0.0/16")
default_switch = alicloud.vpc.Switch("defaultSwitch",
    vpc_id=default_network.id,
    cidr_block="172.16.0.0/16",
    zone_id=default_zones.zones[0].id,
    vswitch_name=name)
default_application_load_balancer = alicloud.slb.ApplicationLoadBalancer("defaultApplicationLoadBalancer",
    load_balancer_name=name,
    vswitch_id=default_switch.id)
default_listener = alicloud.slb.Listener("defaultListener",
    load_balancer_id=default_application_load_balancer.id,
    backend_port=22,
    frontend_port=22,
    protocol="http",
    bandwidth=5,
    health_check_connect_port=20)
default_server_group = alicloud.slb.ServerGroup("defaultServerGroup", load_balancer_id=default_application_load_balancer.id)
default_rule = alicloud.slb.Rule("defaultRule",
    load_balancer_id=default_application_load_balancer.id,
    frontend_port=default_listener.frontend_port,
    domain="*.aliyun.com",
    url="/image",
    server_group_id=default_server_group.id)
sample_ds = default_application_load_balancer.id.apply(lambda id: alicloud.slb.get_rules_output(load_balancer_id=id,
    frontend_port=22))
pulumi.export("firstSlbRuleId", sample_ds.slb_rules[0].id)
import * as pulumi from "@pulumi/pulumi";
import * as alicloud from "@pulumi/alicloud";

const config = new pulumi.Config();
const name = config.get("name") || "slbrulebasicconfig";
const defaultZones = alicloud.getZones({
    availableDiskCategory: "cloud_efficiency",
    availableResourceCreation: "VSwitch",
});
const defaultNetwork = new alicloud.vpc.Network("defaultNetwork", {cidrBlock: "172.16.0.0/16"});
const defaultSwitch = new alicloud.vpc.Switch("defaultSwitch", {
    vpcId: defaultNetwork.id,
    cidrBlock: "172.16.0.0/16",
    zoneId: defaultZones.then(defaultZones => defaultZones.zones?[0]?.id),
    vswitchName: name,
});
const defaultApplicationLoadBalancer = new alicloud.slb.ApplicationLoadBalancer("defaultApplicationLoadBalancer", {
    loadBalancerName: name,
    vswitchId: defaultSwitch.id,
});
const defaultListener = new alicloud.slb.Listener("defaultListener", {
    loadBalancerId: defaultApplicationLoadBalancer.id,
    backendPort: 22,
    frontendPort: 22,
    protocol: "http",
    bandwidth: 5,
    healthCheckConnectPort: 20,
});
const defaultServerGroup = new alicloud.slb.ServerGroup("defaultServerGroup", {loadBalancerId: defaultApplicationLoadBalancer.id});
const defaultRule = new alicloud.slb.Rule("defaultRule", {
    loadBalancerId: defaultApplicationLoadBalancer.id,
    frontendPort: defaultListener.frontendPort,
    domain: "*.aliyun.com",
    url: "/image",
    serverGroupId: defaultServerGroup.id,
});
const sampleDs = defaultApplicationLoadBalancer.id.apply(id => alicloud.slb.getRulesOutput({
    loadBalancerId: id,
    frontendPort: 22,
}));
export const firstSlbRuleId = sampleDs.apply(sampleDs => sampleDs.slbRules?[0]?.id);
configuration:
  name:
    type: string
    default: slbrulebasicconfig
resources:
  defaultNetwork:
    type: alicloud:vpc:Network
    properties:
      cidrBlock: 172.16.0.0/16
  defaultSwitch:
    type: alicloud:vpc:Switch
    properties:
      vpcId: ${defaultNetwork.id}
      cidrBlock: 172.16.0.0/16
      zoneId: ${defaultZones.zones[0].id}
      vswitchName: ${name}
  defaultApplicationLoadBalancer:
    type: alicloud:slb:ApplicationLoadBalancer
    properties:
      loadBalancerName: ${name}
      vswitchId: ${defaultSwitch.id}
  defaultListener:
    type: alicloud:slb:Listener
    properties:
      loadBalancerId: ${defaultApplicationLoadBalancer.id}
      backendPort: 22
      frontendPort: 22
      protocol: http
      bandwidth: 5
      healthCheckConnectPort: 20
  defaultServerGroup:
    type: alicloud:slb:ServerGroup
    properties:
      loadBalancerId: ${defaultApplicationLoadBalancer.id}
  defaultRule:
    type: alicloud:slb:Rule
    properties:
      loadBalancerId: ${defaultApplicationLoadBalancer.id}
      frontendPort: ${defaultListener.frontendPort}
      domain: '*.aliyun.com'
      url: /image
      serverGroupId: ${defaultServerGroup.id}
variables:
  defaultZones:
    Fn::Invoke:
      Function: alicloud:getZones
      Arguments:
        availableDiskCategory: cloud_efficiency
        availableResourceCreation: VSwitch
  sampleDs:
    Fn::Invoke:
      Function: alicloud:slb:getRules
      Arguments:
        loadBalancerId: ${defaultApplicationLoadBalancer.id}
        frontendPort: 22
outputs:
  firstSlbRuleId: ${sampleDs.slbRules[0].id}

Using getRules

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 getRules(args: GetRulesArgs, opts?: InvokeOptions): Promise<GetRulesResult>
function getRulesOutput(args: GetRulesOutputArgs, opts?: InvokeOptions): Output<GetRulesResult>
def get_rules(frontend_port: Optional[int] = None,
              ids: Optional[Sequence[str]] = None,
              load_balancer_id: Optional[str] = None,
              name_regex: Optional[str] = None,
              output_file: Optional[str] = None,
              opts: Optional[InvokeOptions] = None) -> GetRulesResult
def get_rules_output(frontend_port: Optional[pulumi.Input[int]] = None,
              ids: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None,
              load_balancer_id: Optional[pulumi.Input[str]] = None,
              name_regex: Optional[pulumi.Input[str]] = None,
              output_file: Optional[pulumi.Input[str]] = None,
              opts: Optional[InvokeOptions] = None) -> Output[GetRulesResult]
func GetRules(ctx *Context, args *GetRulesArgs, opts ...InvokeOption) (*GetRulesResult, error)
func GetRulesOutput(ctx *Context, args *GetRulesOutputArgs, opts ...InvokeOption) GetRulesResultOutput

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

public static class GetRules 
{
    public static Task<GetRulesResult> InvokeAsync(GetRulesArgs args, InvokeOptions? opts = null)
    public static Output<GetRulesResult> Invoke(GetRulesInvokeArgs args, InvokeOptions? opts = null)
}
public static CompletableFuture<GetRulesResult> getRules(GetRulesArgs args, InvokeOptions options)
// Output-based functions aren't available in Java yet
fn::invoke:
  function: alicloud:slb/getRules:getRules
  arguments:
    # arguments dictionary

The following arguments are supported:

FrontendPort int

SLB listener port.

LoadBalancerId string

ID of the SLB with listener rules.

Ids List<string>

A list of rules IDs to filter results.

NameRegex string

A regex string to filter results by rule name.

OutputFile string
FrontendPort int

SLB listener port.

LoadBalancerId string

ID of the SLB with listener rules.

Ids []string

A list of rules IDs to filter results.

NameRegex string

A regex string to filter results by rule name.

OutputFile string
frontendPort Integer

SLB listener port.

loadBalancerId String

ID of the SLB with listener rules.

ids List<String>

A list of rules IDs to filter results.

nameRegex String

A regex string to filter results by rule name.

outputFile String
frontendPort number

SLB listener port.

loadBalancerId string

ID of the SLB with listener rules.

ids string[]

A list of rules IDs to filter results.

nameRegex string

A regex string to filter results by rule name.

outputFile string
frontend_port int

SLB listener port.

load_balancer_id str

ID of the SLB with listener rules.

ids Sequence[str]

A list of rules IDs to filter results.

name_regex str

A regex string to filter results by rule name.

output_file str
frontendPort Number

SLB listener port.

loadBalancerId String

ID of the SLB with listener rules.

ids List<String>

A list of rules IDs to filter results.

nameRegex String

A regex string to filter results by rule name.

outputFile String

getRules Result

The following output properties are available:

FrontendPort int
Id string

The provider-assigned unique ID for this managed resource.

Ids List<string>

A list of SLB listener rules IDs.

LoadBalancerId string
Names List<string>

A list of SLB listener rules names.

SlbRules List<Pulumi.AliCloud.Slb.Outputs.GetRulesSlbRule>

A list of SLB listener rules. Each element contains the following attributes:

NameRegex string
OutputFile string
FrontendPort int
Id string

The provider-assigned unique ID for this managed resource.

Ids []string

A list of SLB listener rules IDs.

LoadBalancerId string
Names []string

A list of SLB listener rules names.

SlbRules []GetRulesSlbRule

A list of SLB listener rules. Each element contains the following attributes:

NameRegex string
OutputFile string
frontendPort Integer
id String

The provider-assigned unique ID for this managed resource.

ids List<String>

A list of SLB listener rules IDs.

loadBalancerId String
names List<String>

A list of SLB listener rules names.

slbRules List<GetRulesSlbRule>

A list of SLB listener rules. Each element contains the following attributes:

nameRegex String
outputFile String
frontendPort number
id string

The provider-assigned unique ID for this managed resource.

ids string[]

A list of SLB listener rules IDs.

loadBalancerId string
names string[]

A list of SLB listener rules names.

slbRules GetRulesSlbRule[]

A list of SLB listener rules. Each element contains the following attributes:

nameRegex string
outputFile string
frontend_port int
id str

The provider-assigned unique ID for this managed resource.

ids Sequence[str]

A list of SLB listener rules IDs.

load_balancer_id str
names Sequence[str]

A list of SLB listener rules names.

slb_rules Sequence[GetRulesSlbRule]

A list of SLB listener rules. Each element contains the following attributes:

name_regex str
output_file str
frontendPort Number
id String

The provider-assigned unique ID for this managed resource.

ids List<String>

A list of SLB listener rules IDs.

loadBalancerId String
names List<String>

A list of SLB listener rules names.

slbRules List<Property Map>

A list of SLB listener rules. Each element contains the following attributes:

nameRegex String
outputFile String

Supporting Types

GetRulesSlbRule

Domain string

Domain name in the HTTP request where the rule applies (e.g. "*.aliyun.com").

Id string

Rule ID.

Name string

Rule name.

ServerGroupId string

ID of the linked VServer group.

Url string

Path in the HTTP request where the rule applies (e.g. "/image").

Domain string

Domain name in the HTTP request where the rule applies (e.g. "*.aliyun.com").

Id string

Rule ID.

Name string

Rule name.

ServerGroupId string

ID of the linked VServer group.

Url string

Path in the HTTP request where the rule applies (e.g. "/image").

domain String

Domain name in the HTTP request where the rule applies (e.g. "*.aliyun.com").

id String

Rule ID.

name String

Rule name.

serverGroupId String

ID of the linked VServer group.

url String

Path in the HTTP request where the rule applies (e.g. "/image").

domain string

Domain name in the HTTP request where the rule applies (e.g. "*.aliyun.com").

id string

Rule ID.

name string

Rule name.

serverGroupId string

ID of the linked VServer group.

url string

Path in the HTTP request where the rule applies (e.g. "/image").

domain str

Domain name in the HTTP request where the rule applies (e.g. "*.aliyun.com").

id str

Rule ID.

name str

Rule name.

server_group_id str

ID of the linked VServer group.

url str

Path in the HTTP request where the rule applies (e.g. "/image").

domain String

Domain name in the HTTP request where the rule applies (e.g. "*.aliyun.com").

id String

Rule ID.

name String

Rule name.

serverGroupId String

ID of the linked VServer group.

url String

Path in the HTTP request where the rule applies (e.g. "/image").

Package Details

Repository
https://github.com/pulumi/pulumi-alicloud
License
Apache-2.0
Notes

This Pulumi package is based on the alicloud Terraform Provider.