Resource: aws_vpclattice_listener

Terraform resource for managing an AWS VPC Lattice Listener.

Example Usage

Fixed response action

resource "aws_vpclattice_service" "example" {
  name = "example"
}

resource "aws_vpclattice_listener" "example" {
  name               = "example"
  protocol           = "HTTPS"
  service_identifier = aws_vpclattice_service.example.id
  default_action {
    fixed_response {
      status_code = 404
    }
  }
}

Forward action

resource "aws_vpclattice_service" "example" {
  name = "example"
}

resource "aws_vpclattice_target_group" "example" {
  name = "example-target-group-1"
  type = "INSTANCE"

  config {
    port           = 80
    protocol       = "HTTP"
    vpc_identifier = aws_vpc.example.id
  }
}

resource "aws_vpclattice_listener" "example" {
  name               = "example"
  protocol           = "HTTP"
  service_identifier = aws_vpclattice_service.example.id
  default_action {
    forward {
      target_groups {
        target_group_identifier = aws_vpclattice_target_group.example.id
      }
    }
  }
}

Forward action with weighted target groups

resource "aws_vpclattice_service" "example" {
  name = "example"
}

resource "aws_vpclattice_target_group" "example1" {
  name = "example-target-group-1"
  type = "INSTANCE"

  config {
    port           = 80
    protocol       = "HTTP"
    vpc_identifier = aws_vpc.example.id
  }
}

resource "aws_vpclattice_target_group" "example2" {
  name = "example-target-group-2"
  type = "INSTANCE"

  config {
    port           = 8080
    protocol       = "HTTP"
    vpc_identifier = aws_vpc.example.id
  }
}

resource "aws_vpclattice_listener" "example" {
  name               = "example"
  protocol           = "HTTP"
  service_identifier = aws_vpclattice_service.example.id
  default_action {
    forward {
      target_groups {
        target_group_identifier = aws_vpclattice_target_group.example1.id
        weight                  = 80
      }
      target_groups {
        target_group_identifier = aws_vpclattice_target_group.example2.id
        weight                  = 20
      }
    }
  }
}

Argument Reference

This resource supports the following arguments:

Default Action

Default action blocks (for default_action) must include at least one of the following argument blocks:

Fixed Response

Fixed response blocks (for fixed-response) must include the following argument:

Forward

Forward blocks (for forward) must include the following arguments:

Target Groups

Target group blocks (for target_group) must include the following arguments:

Attribute Reference

This resource exports the following attributes in addition to the arguments above:

Import

In Terraform v1.5.0 and later, use an import block to import VPC Lattice Listener using the listener_id of the listener and the id of the VPC Lattice service combined with a / character. For example:

import {
  to = aws_vpclattice_listener.example
  id = "svc-1a2b3c4d/listener-987654321"
}

Using terraform import, import VPC Lattice Listener using the listener_id of the listener and the id of the VPC Lattice service combined with a / character. For example:

% terraform import aws_vpclattice_listener.example svc-1a2b3c4d/listener-987654321