Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

[Bug] Error: creating Auto Scaling Policy (terraform-escala): ValidationError: Group Prod not found

Erro ao rodar o terraform, favor ajudar. meu recurso terraform

resource "aws_autoscaling_policy" "escala-Producao" { name = "terraform-escala" autoscaling_group_name = var.nomeGrupo policy_type = "TargetTrackingScaling" target_tracking_configuration { predefined_metric_specification { predefined_metric_type = "ASGAverageCPUUtilization" } target_value = 50.0 } }

creating Auto Scaling Policy (terraform-escala): ValidationError: Group Prod not found │ status code: 400, request id: 202b477c-e2e9-4114-af2b-bb6709d5664f │ │ with module.aws-prod.aws_autoscaling_policy.escala-Producao, │ on ../../infra/main.tf line 79, in resource "aws_autoscaling_policy" "escala-Producao": │ 79: resource "aws_autoscaling_policy" "escala-Producao" {

3 respostas

Oi, Cledson. Tudo bem?

Poderia postar o código do Terraform para que a gente consiga ver o que pode estar atrapalhando?

terraform { required_providers { aws = { source = "hashicorp/aws" version = "~> 4.16" } }

required_version = ">= 1.2.0" }

provider "aws" { region = var.regiao_aws }

resource "aws_launch_template" "maquina" { image_id = "ami-830c94e3" instance_type = var.instancia key_name = var.chave tags = { Name = "Terraform aws" } security_group_names = [ var.grupoDeSeguranca ] user_data = var.producao ? filebase64("ansible.sh") : "" }

resource "aws_key_pair" "chaveSSH" { key_name = var.chave public_key = file("${var.chave}.pub") }

resource "aws_autoscaling_group" "grupo" { availability_zones = [ "${var.regiao_aws}a", "${var.regiao_aws}b" ] name = var.nomeGrupo min.size = var.minimo max.size = var.maximo target_group_arns = var.producao ? [ aws_lb_target_group.alvoLB[0].arn ] : [] launch_template { id = aws_launch_template.maquina.id version = "$Latest" } }

resource "aws_autoscaling_schedule" "liga" { scheduled_action_name = "liga" min_size = 0 max_size = 1 desired_capacity = 1 start_time = timeadd(timestamp, "10m") recurrence = = "0 10 * * MON-FRI" autoscaling_group_name = aws_autoscaling_group.grupo.name }

resource "aws_autoscaling_schedule" "desliga" { scheduled_action_name = "desliga" min_size = 0 max_size = 1 desired_capacity = 0 start_time = timeadd(timestamp, "11m") recurrence = = "0 21 * * MON-FRI" autoscaling_group_name = aws_autoscaling_group.grupo.name }

resource "aws_default_subnet" "subnet_1" { availability_zones = "${var.regiao_aws}a" }

resource "aws_default_subnet" "subnet_2" { availability_zones = "${var.regiao_aws}b" }

resource "aws_lb" "loadBalancer" { internal = false subnets = [ aws_default_subnet.subnet_1.id, aws_default_subnet.subnet_2.id ] count = var.producao ? 1 : 0 }

resource "aws_lb_target_group" "alvoLB" { name = "maquinasAlvo" port = "8000" protocol = "HTTP" vpc_id = aws_default_vpc.default.id count = var.producao ? 1 : 0 }

resource "aws_default_vpc" "default" { }

resource "aws_lb_listener" "entradaLB" { load_balancer_arn = aws_lb.loadBalancer[0].arn port = "8000" protocol = "HTTP" default_action { type = "forward" target_group_arn = aws_lb_target_group.alvoLB[0].arn } count = var.producao ? 1 : 0 }

resource "aws_autoscaling_policy" "escala-producao" { name = "terraform-escala" autoscaling_group_name = var.nomeGrupo policy_type = "TargetTrackingScaling" target_tracking_configuration { predefined_metric_specification { predefined_metric_type = "ASGAverageCPUUtilization" } target_value = 50.0 } count = var.producao ? 1 : 0 }

solução!

Bom dia,

Então, o erro persiste no terminal, porém e o target_group está Healthy ok. Eu inserir no recurso aws_lb o security_groups e funcionou.

resource "aws_lb" "loadBalancer" { internal = false subnets = [ aws_default_subnet.subnet_1.id, aws_default_subnet.subnet_2.id ] security_groups = [ aws_security_group.acesso_geral.id ] count = var.producao ? 1 : 0 }