webserver.j 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. {% import 'variables.include' as var %}
  2. ###################
  3. # Web Server Instance
  4. resource "aws_instance" "webserver" {
  5. ami = "${data.aws_ami.ubuntu.id}"
  6. instance_type = "${var.Instance-Type}"
  7. availability_zone = "${data.aws_availability_zones.available.names[0]}"
  8. subnet_id = "${aws_subnet.subnet_public_a.id}"
  9. ebs_optimized = "${var.EBS-Optimized}"
  10. disable_api_termination = false
  11. associate_public_ip_address = true
  12. instance_initiated_shutdown_behavior = "terminate"
  13. key_name = "${var.AWS-Key-Pair-Name}"
  14. vpc_security_group_ids = ["${aws_security_group.sg_instance_access.id}"]
  15. depends_on = ["aws_internet_gateway.gw_primary"]
  16. tags {
  17. Name = "webserver"
  18. }
  19. root_block_device {
  20. volume_type = "standard"
  21. volume_size = "{{ var.Web_Volume_Size }}" # Gigabytes
  22. delete_on_termination = true
  23. }
  24. ebs_block_device {
  25. device_name = "/dev/sdd"
  26. volume_size = "${var.Swap-Volume-Size}"
  27. volume_type = "${var.Swap-Volume-Type}"
  28. delete_on_termination = true
  29. }
  30. user_data = <<EOF
  31. #cloud-config
  32. runcmd:
  33. - [ mkswap, /dev/xvdd ]
  34. - [ swapon, -a ]
  35. mounts:
  36. - [ xvdd, none, swap, sw, 0, 0 ]
  37. EOF
  38. # Fix issues with cached keys. Arguably less secure, but also way less annoying
  39. provisioner "local-exec" {
  40. command = "ssh-keygen -f ~/.ssh/known_hosts -R webserver.lab.${var.Domain-Name}"
  41. }
  42. }
  43. # Give me the IP Addresses
  44. output "webserver_ip" {
  45. value = "${aws_instance.webserver.public_ip}"
  46. }
  47. # Give me DNS entries
  48. resource "aws_route53_record" "webserver" {
  49. zone_id = "${var.Domain-Zone-ID}"
  50. name = "webserver.lab.${var.Domain-Name}"
  51. type = "A"
  52. ttl = "300"
  53. records = ["${aws_instance.webserver.public_ip}"]
  54. }
  55. resource "aws_route53_record" "webserver_pvt" {
  56. zone_id = "${var.Domain-Zone-ID}"
  57. name = "webserver_pvt.lab.${var.Domain-Name}"
  58. type = "A"
  59. ttl = "300"
  60. records = ["${aws_instance.webserver.private_ip}"]
  61. }
  62. output "webserver_dns" {
  63. value = "${aws_route53_record.webserver.name}"
  64. }