User_data not executing in my code

terraform apply is not executing or even touching the user_data mentioned in the below code. My main goal is to launch an EC2 instance with Jenkins installed.
Even when I included and echo command under user_data it was not processed.

provider “aws” {
region = “ap-south-1”
}

resource “aws_instance” “jenkins_instance” {
ami = “ami-03bb6d83c60fc5f7c”
instance_type = “t3.micro”
key_name = “Pranav”
vpc_security_group_ids = [“sg-05d5516638a0e6f2d”]

user_data = <<-EOF
#!/bin/bash
sudo apt update
sudo apt install -y default-jdk
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sudo sh -c ‘echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list’
sudo apt update
sudo apt install -y jenkins

          EOF

tags = {
Name = “jenkins”
}
}

output “public_ip” {
value = aws_instance.jenkins_instance.public_ip
}

Hi @pranavatla,

Welcome to the HashiCorp Forums!

How did you confirm that the user_data isn’t being processed? Ensure you ssh to the VM and check the /var/log/cloud-init-output.log file. If it is anything related to the script, you will find the details of what went wrong in that file.

I tried the code you shared, and it works fine. So, it might be something specific to your environment.