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
}