AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / server / Perguntas / 1143908
Accepted
scene
scene
Asked: 2023-09-12 03:29:36 +0800 CST2023-09-12 03:29:36 +0800 CST 2023-09-12 03:29:36 +0800 CST

InvalidConfigurationRequest: um balanceador de carga não pode ser anexado a várias sub-redes na mesma zona de disponibilidade

  • 772
Esta questão foi migrada do Stack Overflow porque pode ser respondida em Server Fault. Migrado há 8 horas .

Copio e colo a parte do meu main.tfarquivo:

resource "aws_security_group" "servers" {
  name        = "allowservers"
  description = "Allow TCP:8080 inbound traffic to servers"
  vpc_id      = module.vpc.vpc_id

  ingress {
    from_port   = 8080
    to_port     = 8080
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

resource "aws_launch_configuration" "ubuntu" {
  image_id        = "ami-053b0d53c279acc90"
  instance_type   = "t2.micro"
  associate_public_ip_address = true
  security_groups = [aws_security_group.servers.id]

  user_data = <<-EOF
              #!/bin/bash
              echo "Hello, World" > index.html
              nohup busybox httpd -f -p ${var.server_port} &
              EOF
   # Required when using a launch configuration with an ASG.
  lifecycle {
    create_before_destroy = true
  }
}

data "aws_vpc" "my-vpc" {
}

data "aws_subnets" "my-vpc-subnets" {
    filter {
      name = "vpc-id"
      values = [data.aws_vpc.my-vpc.id]
    }
}

resource "aws_autoscaling_group" "ubuntu_scaling" {
  launch_configuration = aws_launch_configuration.ubuntu.name
  vpc_zone_identifier = data.aws_subnets.my-vpc-subnets.ids

  target_group_arns = [aws_lb_target_group.asg.arn]
  health_check_type = "ELB"

  min_size = 2
  max_size = 10

  tag {
    key                 = "Name"
    value               = "terraform-asg-ubuntu"
    propagate_at_launch = true
  }
}

resource "aws_lb" "ubuntu-lb" {
    name = "terraform-asg-ubuntu"
    load_balancer_type = "application"
    subnets = data.aws_subnets.my-vpc-subnets.ids
    security_groups = [aws_security_group.alb.id]
}

resource "aws_lb_listener" "ubuntu-lb-listener" {
    load_balancer_arn = aws_lb.ubuntu-lb.arn
    port = 80
    protocol = "HTTP"

    #By default, return a simple 404 page
    default_action {
      type = "fixed-response"

      fixed_response {
        content_type = "text/plain"
        message_body = "404:ups"
        status_code = 404
      }
    }
}

resource "aws_security_group" "alb" {
  name = "terraform-asg-ubuntu"
  vpc_id   = data.aws_vpc.my-vpc.id
  # Allow inbound HTTP requests
  ingress {
    from_port   = 80
    to_port     = 80
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  # Allow all outbound requests
  egress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

resource "aws_lb_target_group" "asg" {
  name     = "terraform-asg-example"
  port     = var.server_port
  protocol = "HTTP"
  vpc_id   = data.aws_vpc.my-vpc.id

  health_check {
    path                = "/"
    protocol            = "HTTP"
    matcher             = "200"
    interval            = 15
    timeout             = 3
    healthy_threshold   = 2
    unhealthy_threshold = 2
  }
}

resource "aws_lb_listener_rule" "asg" {
    listener_arn = aws_lb_listener.ubuntu-lb-listener.arn
    priority = 100

    condition {
      path_pattern {
        values = ["*"]
      }
    }
    action {
      type = "forward"
      target_group_arn = aws_lb_target_group.asg.arn
    }
}

Ele gera - quando executo terraform apply- o erro abaixo:

│ Error: creating ELBv2 application Load Balancer (terraform-asg-ubuntu): InvalidConfigurationRequest: A load balancer cannot be attached to multiple subnets in the same Availability Zone
│       status code: 400, request id: 44b2abdb-a321-4f1e-bd6f-4b87aa943477
│
│   with aws_lb.ubuntu-lb,
│   on main.tf line 172, in resource "aws_lb" "ubuntu-lb":
│  172: resource "aws_lb" "ubuntu-lb" {

Estou usando também vpco módulo no modules.tfarquivo:

module "vpc" {
  source = "terraform-aws-modules/vpc/aws"
  version = "5.0.0"
  name = "my-vpc"
  cidr = "10.0.0.0/16"

  azs             = ["us-east-1a", "us-east-1f"]
  private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
  public_subnets  = ["10.0.101.0/24", "10.0.102.0/24"]

  enable_nat_gateway = true
  enable_vpn_gateway = true

  tags = {
    Terraform = "true"
    Environment = "dev"
  }
}

Com muita depuração ainda não sei como resolver esse problema.

amazon-web-services
  • 1 1 respostas
  • 15 Views

1 respostas

  • Voted
  1. Best Answer
    Marcin
    2023-09-12T11:36:44+08:002023-09-12T11:36:44+08:00

    Você deve usar public_subnetso vpcmódulo em seu aws_lb:

    resource "aws_lb" "ubuntu-lb" {
        name = "terraform-asg-ubuntu"
        load_balancer_type = "application"
        subnets = module.vpc.public_subnets
        security_groups = [aws_security_group.alb.id]
    }
    
    • 0

relate perguntas

  • Como os preços de rede funcionam exatamente em plataformas de nuvem? E como devo evitar ataques de preços dedicados?

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Você pode passar usuário/passar para autenticação básica HTTP em parâmetros de URL?

    • 5 respostas
  • Marko Smith

    Ping uma porta específica

    • 18 respostas
  • Marko Smith

    Verifique se a porta está aberta ou fechada em um servidor Linux?

    • 7 respostas
  • Marko Smith

    Como automatizar o login SSH com senha?

    • 10 respostas
  • Marko Smith

    Como posso dizer ao Git para Windows onde encontrar minha chave RSA privada?

    • 30 respostas
  • Marko Smith

    Qual é o nome de usuário/senha de superusuário padrão para postgres após uma nova instalação?

    • 5 respostas
  • Marko Smith

    Qual porta o SFTP usa?

    • 6 respostas
  • Marko Smith

    Linha de comando para listar usuários em um grupo do Windows Active Directory?

    • 9 respostas
  • Marko Smith

    O que é um arquivo Pem e como ele difere de outros formatos de arquivo de chave gerada pelo OpenSSL?

    • 3 respostas
  • Marko Smith

    Como determinar se uma variável bash está vazia?

    • 15 respostas
  • Martin Hope
    Davie Ping uma porta específica 2009-10-09 01:57:50 +0800 CST
  • Martin Hope
    kernel O scp pode copiar diretórios recursivamente? 2011-04-29 20:24:45 +0800 CST
  • Martin Hope
    Robert ssh retorna "Proprietário incorreto ou permissões em ~/.ssh/config" 2011-03-30 10:15:48 +0800 CST
  • Martin Hope
    Eonil Como automatizar o login SSH com senha? 2011-03-02 03:07:12 +0800 CST
  • Martin Hope
    gunwin Como lidar com um servidor comprometido? 2011-01-03 13:31:27 +0800 CST
  • Martin Hope
    Tom Feiner Como posso classificar a saída du -h por tamanho 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich O que é um arquivo Pem e como ele difere de outros formatos de arquivo de chave gerada pelo OpenSSL? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent Como determinar se uma variável bash está vazia? 2009-05-13 09:54:48 +0800 CST

Hot tag

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve