You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create security group allowing SSH and HTTP traffic
resource"aws_security_group""instance_sg" {
name="instance_sg"description="Security group for instances"ingress {
from_port=22to_port=22protocol="tcp"cidr_blocks=["0.0.0.0/0"]
}
ingress {
from_port=80to_port=80protocol="tcp"cidr_blocks=["0.0.0.0/0"]
}
}
Create an EC2 instance for Jenkins
resource"aws_instance""jenkins_instance" {
ami="ami-0123456789"# Replace with the desired Jenkins AMI IDinstance_type="t2.micro"# Replace with the desired instance typekey_name="your_key_pair"# Replace with your key pair namesecurity_group_names=[aws_security_group.instance_sg.name]
tags={
Name ="Jenkins Instance"
}
provisioner"remote-exec" {
connection {
type="ssh"user="ubuntu"# Replace with the appropriate username for your AMIprivate_key=file("path to your private key file") # Replace with the path to your private key filehost=aws_instance.jenkins_instance.public_ip# Connect using the public IP of the instance
}
inline=[
"sudo apt-get update",
"sudo apt install openjdk-11-jdk",
"sudo wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null",
"sudo echo deb https://pkg.jenkins.io/debian-stable binary/ >> /etc/apt/sources.list.d/jenkins.list echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null",
"sudo apt-get update",
"sudo apt-get install -y jenkins",
"sudo systemctl start Jenkins"
]
}
}
Create an EC2 instance for Docker
resource"aws_instance""docker_instance" {
ami="ami-0123456789"# Replace with the desired Docker AMI IDinstance_type="t2.micro"# Replace with the desired instance typekey_name="your_key_pair"# Replace with your key pair namesecurity_group_names=[aws_security_group.instance_sg.name]
tags={
Name ="Docker Instance"
}
provisioner"remote-exec" {
connection {
type="ssh"user="ubuntu"# Replace with the appropriate username for your AMIprivate_key=file("path to your private key file") # Replace with the path to your private key filehost=aws_instance.docker_instance.public_ip# Connect using the public IP of the instance
}
inline=[
"sudo apt update",
"sudo apt install docker.io -y"
]
}
}
Create an EC2 instance for Ansible
resource"aws_instance""ansible_instance" {
ami="ami-0123456789"# Replace with the desired Ansible AMI IDinstance_type="t2.micro"# Replace with the desired instance typekey_name="your_key_pair"# Replace with your key pair namesecurity_group_names=[aws_security_group.instance_sg.name]
tags={
Name ="Ansible Instance"
}
provisioner"remote-exec" {
connection {
type="ssh"user="ubuntu"# Replace with the appropriate username for your AMIprivate_key=file("path to your private key file") # Replace with the path to your private key filehost=aws_instance.ansible_instance.public_ip# Connect using the public IP of the instance
}
inline=[
"sudo apt-get update",
"sudo apt-get install -y ansible"
]
}
}