alicloud_alb_rule

Provides a Application Load Balancer (ALB) Rule resource.

For information about Application Load Balancer (ALB) Rule and how to use it, see What is Rule.

Example Usage

Basic Usage

variable "name" {
  default = "tf_example"
}

data "alicloud_alb_zones" "default" {
}

data "alicloud_resource_manager_resource_groups" "default" {
}

resource "alicloud_vpc" "default" {
  vpc_name   = var.name
  cidr_block = "10.4.0.0/16"
}

resource "alicloud_vswitch" "default" {
  count        = 2
  vpc_id       = alicloud_vpc.default.id
  cidr_block   = format("10.4.%d.0/24", count.index + 1)
  zone_id      = data.alicloud_alb_zones.default.zones[count.index].id
  vswitch_name = format("${var.name}_%d", count.index + 1)
}

resource "alicloud_alb_load_balancer" "default" {
  vpc_id                 = alicloud_vpc.default.id
  address_type           = "Internet"
  address_allocated_mode = "Fixed"
  load_balancer_name     = var.name
  load_balancer_edition  = "Standard"
  resource_group_id      = data.alicloud_resource_manager_resource_groups.default.groups.0.id
  load_balancer_billing_config {
    pay_type = "PayAsYouGo"
  }
  tags = {
    Created = "TF"
  }
  zone_mappings {
    vswitch_id = alicloud_vswitch.default.0.id
    zone_id    = data.alicloud_alb_zones.default.zones.0.id
  }
  zone_mappings {
    vswitch_id = alicloud_vswitch.default.1.id
    zone_id    = data.alicloud_alb_zones.default.zones.1.id
  }
}

resource "alicloud_alb_server_group" "default" {
  protocol          = "HTTP"
  vpc_id            = alicloud_vpc.default.id
  server_group_name = var.name
  resource_group_id = data.alicloud_resource_manager_resource_groups.default.groups.0.id
  health_check_config {
    health_check_enabled = "false"
  }
  sticky_session_config {
    sticky_session_enabled = "false"
  }
  tags = {
    Created = "TF"
  }
}

resource "alicloud_alb_listener" "default" {
  load_balancer_id     = alicloud_alb_load_balancer.default.id
  listener_protocol    = "HTTP"
  listener_port        = 80
  listener_description = var.name
  default_actions {
    type = "ForwardGroup"
    forward_group_config {
      server_group_tuples {
        server_group_id = alicloud_alb_server_group.default.id
      }
    }
  }
}

resource "alicloud_alb_rule" "default" {
  rule_name   = var.name
  listener_id = alicloud_alb_listener.default.id
  priority    = "555"
  rule_conditions {
    cookie_config {
      values {
        key   = "created"
        value = "tf"
      }
    }
    type = "Cookie"
  }

  rule_actions {
    forward_group_config {
      server_group_tuples {
        server_group_id = alicloud_alb_server_group.default.id
      }
    }
    order = "9"
    type  = "ForwardGroup"
  }
}

Argument Reference

The following arguments are supported:

rule_actions

The rule_actions supports the following:

rule_actions-fixed_response_config

The fixed_response_config supports the following:

rule_actions-forward_group_config

The forward_group_config supports the following:

rule_actions-forward_group_config-server_group_tuples

The server_group_tuples supports the following:

rule_actions-forward_group_config-server_group_sticky_session

The server_group_sticky_session supports the following:

rule_actions-insert_header_config

The insert_header_config supports the following:

rule_actions-remove_header_config

The remove_header_config supports the following:

rule_actions-redirect_config

The redirect_config supports the following:

rule_actions-rewrite_config

The rewrite_config supports the following:

rule_actions-traffic_limit_config

The traffic_limit_config supports the following:

rule_actions-traffic_mirror_config

The traffic_mirror_config supports the following:

rule_actions-traffic_mirror_config-mirror_group_config

The mirror_group_config supports the following:

rule_actions-traffic_mirror_config-mirror_group_config-server_group_tuples

The server_group_tuples supports the following:

rule_actions-cors_config

The cors_config supports the following:

rule_conditions

The rule_conditions supports the following:

The cookie_config supports the following:

The values supports the following:

rule_conditions-header_config

The header_config supports the following:

rule_conditions-response_header_config

The response_header_config supports the following:

rule_conditions-response_status_code_config

The response_status_code_config supports the following:

rule_conditions-host_config

The host_config supports the following:

rule_conditions-method_config

The method_config supports the following:

rule_conditions-path_config

The path_config supports the following:

rule_conditions-query_string_config

The query_string_config supports the following:

rule_conditions-query_string_config-values

The values supports the following:

rule_conditions-source_ip_config

The source_ip_config supports the following:

Attributes Reference

The following attributes are exported:

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

Import

Application Load Balancer (ALB) Rule can be imported using the id, e.g.

$ terraform import alicloud_alb_rule.example <id>