Skip to content

Instantly share code, notes, and snippets.

@kluu1
Created October 6, 2020 17:54
Show Gist options
  • Save kluu1/aae5a896fb02b9706c018cb45bc8348d to your computer and use it in GitHub Desktop.
Save kluu1/aae5a896fb02b9706c018cb45bc8348d to your computer and use it in GitHub Desktop.
...
resource "aws_instance" "jenkins" {
ami = data.aws_ami.ubuntu.id
instance_type = "t2.micro"
security_groups = [aws_security_group.web_traffic.name]
key_name = "kluu"
provisioner "remote-exec" {
inline = [
"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 -qq",
"sudo apt install -y default-jre",
"sudo apt install -y jenkins",
"sudo systemctl start jenkins",
"sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080",
"sudo sh -c \"iptables-save > /etc/iptables.rules\"",
"echo iptables-persistent iptables-persistent/autosave_v4 boolean true | sudo debconf-set-selections",
"echo iptables-persistent iptables-persistent/autosave_v6 boolean true | sudo debconf-set-selections",
"sudo apt-get -y install iptables-persistent",
"sudo ufw allow 8080",
]
}
connection {
type = "ssh"
host = self.public_ip
user = "ubuntu"
private_key = file("~/kluu.pem")
}
tags = {
"Name" = "Jenkins_Server"
"Terraform" = "true"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment