Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. data "aws_ami" "jenkins_worker_linux" {
  2. most_recent = true
  3. owners = ["self"]
  4.  
  5. filter {
  6. name = "name"
  7. values = ["amazon-linux-for-jenkins*"]
  8. }
  9. }
  10.  
  11. resource "aws_key_pair" "jenkins_worker_linux" {
  12. key_name = "jenkins_worker_linux"
  13. public_key = "${file("jenkins_worker.pub")}"
  14. }
  15.  
  16. data "local_file" "jenkins_worker_pem" {
  17. filename = "${path.module}/jenkins_worker.pem"
  18. }
  19.  
  20. data "template_file" "userdata_jenkins_worker_linux" {
  21. template = "${file("scripts/jenkins_worker_linux.sh")}"
  22.  
  23. vars {
  24. env = "dev"
  25. region = "us-east-1"
  26. datacenter = "dev-us-east-1"
  27. node_name = "us-east-1-jenkins_worker_linux"
  28. domain = ""
  29. device_name = "eth0"
  30. server_ip = "${aws_instance.jenkins_server.private_ip}"
  31. worker_pem = "${data.local_file.jenkins_worker_pem.content}"
  32. jenkins_username = "admin"
  33. jenkins_password = "mysupersecretpassword"
  34. }
  35. }
  36.  
  37. # lookup the security group of the Jenkins Server
  38. data "aws_security_group" "jenkins_worker_linux" {
  39. filter {
  40. name = "group-name"
  41. values = ["dev_jenkins_worker_linux"]
  42. }
  43. }
  44.  
  45. resource "aws_launch_configuration" "jenkins_worker_linux" {
  46. name_prefix = "dev-jenkins-worker-linux"
  47. image_id = "${data.aws_ami.jenkins_worker_linux.image_id}"
  48. instance_type = "t3.medium"
  49. iam_instance_profile = "dev_jenkins_worker_linux"
  50. key_name = "${aws_key_pair.jenkins_worker_linux.key_name}"
  51. security_groups = ["${data.aws_security_group.jenkins_worker_linux.id}"]
  52. user_data = "${data.template_file.userdata_jenkins_worker_linux.rendered}"
  53. associate_public_ip_address = false
  54.  
  55. root_block_device {
  56. delete_on_termination = true
  57. volume_size = 100
  58. }
  59.  
  60. lifecycle {
  61. create_before_destroy = true
  62. }
  63. }
  64.  
  65. resource "aws_autoscaling_group" "jenkins_worker_linux" {
  66. name = "dev-jenkins-worker-linux"
  67. min_size = "1"
  68. max_size = "2"
  69. desired_capacity = "2"
  70. health_check_grace_period = 60
  71. health_check_type = "EC2"
  72. vpc_zone_identifier = ["${data.aws_subnet_ids.default_public.ids}"]
  73. launch_configuration = "${aws_launch_configuration.jenkins_worker_linux.name}"
  74. termination_policies = ["OldestLaunchConfiguration"]
  75. wait_for_capacity_timeout = "10m"
  76. default_cooldown = 60
  77.  
  78. tags = [
  79. {
  80. key = "Name"
  81. value = "dev_jenkins_worker_linux"
  82. propagate_at_launch = true
  83. },
  84. {
  85. key = "class"
  86. value = "dev_jenkins_worker_linux"
  87. propagate_at_launch = true
  88. },
  89. ]
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement