Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module 2 Terraform: "Error creating launch configuration: UnsupportedOperation" #71

Open
ic32k opened this issue Oct 11, 2024 · 1 comment

Comments

@ic32k
Copy link

ic32k commented Oct 11, 2024

Hello,

Yesterday installed AWSGoat module1 without issues, but today I wanted to run the module2 and this error is shown at Terraform run:

aws_ecs_service.worker: Creation complete after 1s [id=arn:aws:ecs:us-east-1:318030154911:service/ecs-lab-cluster/ecs_service_worker] ╷ │ Error: Error creating launch configuration: UnsupportedOperation: The Launch Configuration creation operation is not available in your account. Use launch templates to create configuration templates for your Auto Scaling groups. │ status code: 400, request id: 2e6cb191-b4b8-48a0-b7f8-46be0044fa81 │ │ with aws_launch_configuration.ecs_launch_config, │ on main.tf line 351, in resource "aws_launch_configuration" "ecs_launch_config": │ 351: resource "aws_launch_configuration" "ecs_launch_config" { │ ╵ Error: Process completed with exit code 1.

@d0rk1s
Copy link

d0rk1s commented Nov 4, 2024

Change this:

resource "aws_launch_configuration" "ecs_launch_config" {
  image_id             = data.aws_ami.ecs_optimized_ami.id
  iam_instance_profile = aws_iam_instance_profile.ecs-instance-profile.name
  security_groups      = [aws_security_group.ecs_sg.id]
  user_data            = data.template_file.user_data.rendered
  instance_type        = "t2.micro"
}

resource "aws_autoscaling_group" "ecs_asg" {
  name                 = "ECS-lab-asg"
  vpc_zone_identifier  = [aws_subnet.lab-subnet-public-1.id]
  launch_configuration = aws_launch_configuration.ecs_launch_config.name
  desired_capacity     = 1
  min_size             = 0
  max_size             = 1
}

For this:

resource "aws_launch_template" "ecs_launch_template" {
  name_prefix            = "ecs-lab-launch-template-"
  image_id               = data.aws_ami.ecs_optimized_ami.id
  instance_type          = "t2.micro"
  iam_instance_profile {
    name                = aws_iam_instance_profile.ecs-instance-profile.name
  }
  vpc_security_group_ids     = [aws_security_group.ecs_sg.id]
  
  # Encode the user_data in base64
  user_data              = base64encode(data.template_file.user_data.rendered)
}

resource "aws_autoscaling_group" "ecs_asg" {
  name                   = "ECS-lab-asg"
  vpc_zone_identifier    = [aws_subnet.lab-subnet-public-1.id]
  desired_capacity       = 1
  min_size               = 0
  max_size               = 1

  # Reference the launch template instead of the launch configuration
  launch_template {
    id                   = aws_launch_template.ecs_launch_template.id
    version              = "$Latest"
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants