Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform Error launching source instance: timeout while waiting for state to become 'success' (timeout: 15s)

I have my terraform configured for AWS. I have automated 2 EC2 Instance and 2 ECS Optimized Instance.

I am getting **Error launching source instance: timeout while waiting for the state to become 'success' (timeout: 15s)** for all the 4 Instances while I do terraform apply.

I found on some blog that it may be because of inconsistent AMI or misspelled AMI id.

Hence, I have fixed the typo in my AMI id and able to launch 2 instances. However, still, I got the timeout error for the other two instances.

I am using terraform version: 0.9.6 My TF code for ec2 creation:

resource "aws_instance" "node1" {
  # ECS-optimized AMI for us-west-2
        ami = "ami-62d35c02"
        instance_type = "t2.medium"
    availability_zone = "us-west-2a"
    security_groups = [
        "${aws_security_group.sg.name}"
    ]
    key_name        = "key"
                tags {
            Name           = "Node Server 1"
        }
        user_data = <<EOF
        #!/bin/bash
        echo ECS_CLUSTER=uat >> /etc/ecs/ecs.config
        EOF
        iam_instance_profile = "${aws_iam_instance_profile.ecs.name}"
}

resource "aws_instance" "node2" {
  # ECS-optimized AMI for us-west-2
        ami = "ami-62d35c02"
        instance_type = "t2.medium"
        availability_zone = "us-west-2b"
        security_groups = [
                "${aws_security_group.sg.name}"
        ]
        key_name        = "key"
                tags {
                Name           = "Node Server 2"
        }
        user_data = <<EOF
                #!/bin/bash
                echo ECS_CLUSTER=uat >> /etc/ecs/ecs.config
                EOF
                iam_instance_profile = "${aws_iam_instance_profile.ecs.name}"
}

resource "aws_instance" "mongo" {
        ami = "ami-63ad4b1b"
        instance_type = "t2.medium"
        availability_zone = "us-west-2c"
        security_groups = [
                "${aws_security_group.sg.name}"
        ]
        key_name        = "key"
                tags {
                Name           = "MongoDB Server"
        }
}

resource "aws_instance" "mysql" {
        ami = "ami-22ac4a5a"
        instance_type = "t2.medium"
        availability_zone = "us-west-2c"
        security_groups = [
                "${aws_security_group.sg.name}"
        ]
        key_name        = "key"
                tags {
                Name           = "MySQL Server"
        }
}

Can someone please help me.

Thanks in advance.

like image 330
Arul Deepan Avatar asked Oct 20 '25 14:10

Arul Deepan


1 Answers

It is possible to identify the underlying issue using the Terraform Debug Logs. When I had this error, in my case the issue was that AWS did not have enough capacity for the instance type I was choosing in the availability zone I configured.

A good approach to debug this error would be the following:

  1. Set up the TF_LOG environment variable to enable Terraform Debug Logs. This can be done with the following command on Linux or Mac:
export TF_LOG=DEBUG
  1. Run the terraform apply command.
  2. When the prompt to apply changes appears write yes and hit Enter if the plan is okay for you.
  3. If you get the error, search for the [DEBUG] entries a few lines above it to identify the underlying issue. To give an example, in my case I found the following:
[DEBUG] plugin.terraform-provider-aws_v1.58.0_x4:
<Response>
  <Errors>
    <Error>
      <Code>InsufficientInstanceCapacity</Code>
      <Message>We currently do not have sufficient t3.medium capacity in the Availability Zone you requested (us-west-1a). Our system will be working on provisioning additional capacity. You can currently get t3.medium capacity by not specifying an
        Availability Zone in your request or choosing us-west-1b.</Message>
    </Error>
  </Errors>
  <RequestID>...</RequestID>
</Response>
  1. This should allow you to perform corrective actions in your infrastructure to deploy.
like image 181
Federico Damián Camarda Avatar answered Oct 23 '25 03:10

Federico Damián Camarda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!