Open CliffRoberson opened 5 days ago
Looks like as of October 1, 2024, AWS no longer supports using launch configurations for new accounts: https://docs.aws.amazon.com/autoscaling/ec2/userguide/launch-configurations.html.
That means you need to replace the aws_launch_configuration
resource with the aws_launch_template
resource. It'll look something like this:
resource "aws_launch_template" "example" {
image_id = "ami-0fb653ca2d3203ac1"
instance_type = "t2.micro"
vpc_security_group_ids = [aws_security_group.instance.id]
user_data = base64encode(
<<-EOF
#!/bin/bash
echo "Hello, World" > index.html
nohup busybox httpd -f -p ${var.server_port} &
EOF
)
}
And to use it with the auto scaling group:
resource "aws_autoscaling_group" "example" {
launch_template {
id = aws_launch_template.example.id
version = "$Latest"
}
vpc_zone_identifier = data.aws_subnets.default.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-example"
propagate_at_launch = true
}
}
I copied and pasted the book code into three files and ran the following commands and the apply failed. Error at the end was about the auto scaling launch configuration. Googling it looks like this is deprecated. What should I use instead?
PS C:\Users\cliff\Desktop\TerraformUpAndRunning\Chp2> terraform init Initializing the backend... Initializing provider plugins...
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure. All Terraform commands should now work.
If you ever set or change modules or backend configuration for Terraform, rerun this command to reinitialize your working directory. If you forget, other commands will detect it and remind you to do so if necessary. PS C:\Users\cliff\Desktop\TerraformUpAndRunning\Chp2> terraform apply data.aws_vpc.default: Reading... data.aws_vpc.default: Read complete after 1s [id=vpc-0118d7f9580308e88] data.aws_subnets.default: Reading... data.aws_subnets.default: Read complete after 0s [id=us-east-2]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
Terraform will perform the following actions:
aws_autoscaling_group.example will be created
resource "aws_autoscaling_group" "example" {
arn = (known after apply)
availability_zones = (known after apply)
default_cooldown = (known after apply)
desired_capacity = (known after apply)
force_delete = false
force_delete_warm_pool = false
health_check_grace_period = 300
health_check_type = "ELB"
id = (known after apply)
launch_configuration = (known after apply)
max_size = 10
metrics_granularity = "1Minute"
min_size = 2
name = (known after apply)
name_prefix = (known after apply)
predicted_capacity = (known after apply)
protect_from_scale_in = false
service_linked_role_arn = (known after apply)
target_group_arns = (known after apply)
vpc_zone_identifier = [
wait_for_capacity_timeout = "10m"
warm_pool_size = (known after apply)
tag {
aws_launch_configuration.example will be created
resource "aws_launch_configuration" "example" {
arn = (known after apply)
associate_public_ip_address = (known after apply)
ebs_optimized = (known after apply)
enable_monitoring = true
id = (known after apply)
image_id = "ami-0fb653ca2d3203ac1"
instance_type = "t2.micro"
key_name = (known after apply)
name = (known after apply)
name_prefix = (known after apply)
security_groups = (known after apply)
user_data = "67e34b406ab639a606a64fe06965b26bf8036a9c"
ebs_block_device (known after apply)
metadata_options (known after apply)
root_block_device (known after apply) }
aws_lb.example will be created
resource "aws_lb" "example" {
arn = (known after apply)
arn_suffix = (known after apply)
desync_mitigation_mode = "defensive"
dns_name = (known after apply)
drop_invalid_header_fields = false
enable_deletion_protection = false
enable_http2 = true
enable_tls_version_and_cipher_suite_headers = false
enable_waf_fail_open = false
enable_xff_client_port = false
id = (known after apply)
idle_timeout = 60
internal = (known after apply)
ip_address_type = (known after apply)
load_balancer_type = "application"
name = "terraform-asg-example"
preserve_host_header = false
security_groups = (known after apply)
subnets = [
tags_all = (known after apply)
vpc_id = (known after apply)
xff_header_processing_mode = "append"
zone_id = (known after apply)
subnet_mapping (known after apply) }
aws_lb_listener.http will be created
resource "aws_lb_listener" "http" {
arn = (known after apply)
id = (known after apply)
load_balancer_arn = (known after apply)
port = 80
protocol = "HTTP"
ssl_policy = (known after apply)
tags_all = (known after apply)
default_action {
order = (known after apply)
type = "fixed-response"
fixed_response {
aws_lb_listener_rule.asg will be created
resource "aws_lb_listener_rule" "asg" {
arn = (known after apply)
id = (known after apply)
listener_arn = (known after apply)
priority = 100
tags_all = (known after apply)
action {
condition {
aws_lb_target_group.asg will be created
resource "aws_lb_target_group" "asg" {
arn = (known after apply)
arn_suffix = (known after apply)
connection_termination = false
deregistration_delay = "300"
id = (known after apply)
ip_address_type = (known after apply)
lambda_multi_value_headers_enabled = false
load_balancing_algorithm_type = (known after apply)
load_balancing_cross_zone_enabled = (known after apply)
name = "terraform-asg-example"
port = 8080
preserve_client_ip = (known after apply)
protocol = "HTTP"
protocol_version = (known after apply)
proxy_protocol_v2 = false
slow_start = 0
tags_all = (known after apply)
target_type = "instance"
vpc_id = "vpc-0118d7f9580308e88"
health_check {
stickiness (known after apply)
target_failover (known after apply) }
aws_security_group.alb will be created
resource "aws_security_group" "alb" {
(1 unchanged attribute hidden)
}, ]
(1 unchanged attribute hidden)
}, ]
aws_security_group.instance will be created
(1 unchanged attribute hidden)
}, ]
Plan: 8 to add, 0 to change, 0 to destroy.
Changes to Outputs:
Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve.
Enter a value: yes
aws_lb_target_group.asg: Creating... aws_security_group.instance: Creating... aws_security_group.alb: Creating... aws_lb_target_group.asg: Creation complete after 1s [id=arn:aws:elasticloadbalancing:us-east-2:043309363086:targetgroup/terraform-asg-example/c7b53e0db5b9c21a] aws_security_group.instance: Creation complete after 2s [id=sg-06de222277c569059] aws_launch_configuration.example: Creating... aws_security_group.alb: Creation complete after 3s [id=sg-043099eacdec032e5] aws_lb.example: Creating... aws_lb.example: Still creating... [10s elapsed] aws_lb.example: Still creating... [20s elapsed] aws_lb.example: Still creating... [30s elapsed] aws_lb.example: Still creating... [40s elapsed] aws_lb.example: Still creating... [50s elapsed] aws_lb.example: Still creating... [1m0s elapsed] aws_lb.example: Still creating... [1m10s elapsed] aws_lb.example: Still creating... [1m20s elapsed] aws_lb.example: Still creating... [1m30s elapsed] aws_lb.example: Still creating... [1m40s elapsed] aws_lb.example: Still creating... [1m50s elapsed] aws_lb.example: Still creating... [2m0s elapsed] aws_lb.example: Still creating... [2m10s elapsed] aws_lb.example: Still creating... [2m20s elapsed] aws_lb.example: Still creating... [2m30s elapsed] aws_lb.example: Still creating... [2m40s elapsed] aws_lb.example: Still creating... [2m50s elapsed] aws_lb.example: Creation complete after 2m52s [id=arn:aws:elasticloadbalancing:us-east-2:043309363086:loadbalancer/app/terraform-asg-example/d1a655f2186fdd51] aws_lb_listener.http: Creating... aws_lb_listener.http: Creation complete after 0s [id=arn:aws:elasticloadbalancing:us-east-2:043309363086:listener/app/terraform-asg-example/d1a655f2186fdd51/7b44a3efd8898dbc] aws_lb_listener_rule.asg: Creating... aws_lb_listener_rule.asg: Creation complete after 0s [id=arn:aws:elasticloadbalancing:us-east-2:043309363086:listener-rule/app/terraform-asg-example/d1a655f2186fdd51/7b44a3efd8898dbc/632188ec1b6c47bb] ╷ │ Error: creating Auto Scaling Launch Configuration (terraform-20241113002735313500000001): UnsupportedOperation: The Launch Configuration creation operation is not available in your account. Use launch templates to create configura tion templates for your Auto Scaling groups. │ status code: 400, request id: 5ad8d31c-9281-49b1-857e-f979a388e989 │ │ with aws_launch_configuration.example, │ on main.tf line 16, in resource "aws_launch_configuration" "example": │ 16: resource "aws_launch_configuration" "example" { │ ╵