I want to create multiple EC2 with single userdata

I want to create two ec2 machines with the same userdata. The first ec2 is getting created but the second is failing. The instance profile is same for both. Do you all think that I am missing something obvious ?

resource "aws_instance" "testnode" {
 instance_type = "t2.micro"
 ami           = "ami-0b0af3577fe5e3532"
 tags = {
   Name = join("-", ["xnode", "test"])
 iam_instance_profile = aws_iam_instance_profile.test_instance_profile.name
ubnet_id            = aws_subnet.test_public_subnet.id
 user_data            = file("userdata.tpl")
 root_block_device {
  volume_size = 10

I would like to add that even if I add count=2 the first is getting created fine but the second ec2 is getting created without the userdata.

What’s the resource config for your second instance? What’s the error that you get?

@grimm26 it was identical. I changed my AMI ( from RH to Amazon linux2) and the problem resolved. I also tweaked my userdata. must be some typo. Thanks!