I have created network setup, vpc flow logs and 2 ec2 instance by terraform script. I have checked whether all the resources are created what I have mentioned in the script. I have ensured all resources are created but terraform is still showing like below.
aws_instance.web_server[“subnet-09d3c3fa5f034b57c”]: Still creating… [4m40s elapsed]
aws_instance.web_server[“subnet-0a734b152f56f4b5b”]: Still creating… [4m40s elapsed]
Can you explain about why terraform behaving like this. How to solve this.
Please use the below repo that has all the code the I have used to provision infrastructure. It will help you to find the root cause.
Thanks in advance
There are several reasons why creating an EC2 instance might run for a long time, some of which are situational such as EC2 itself having an outage.
Based on your configuration though I would guess that the most likely reason is that you are using a remote-exec provisioner, which means that the computer where Terraform is running must be able to connect to the EC2 instance directly, which requires you to correctly configure your instance’s security groups, make sure its VPC has a functioning internet gateway, and that your route tables are correctly configured.
All of this complexity is one reason why provisioners are a last resort. That documentation recommends an alternative which I would suggest you use instead of a provisioner: Provision infrastructure with cloud-init. Cloud-init is some software that is usually preinstalled in generic Linux EC2 images which fetches data from the EC2 user data API and can execute that data as a script when your EC2 instance boots.
Thanks for your reply. But the provisioner done the installation what I have mentioned in the provisioner block. Eventhough terraform is showing like creating the resource. I could not find the cause. Can you please help to find it.