main.tf 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. data "aws_ami" "ubuntu_pro" {
  2. # Ubuntu Pro 18.04 Product ID: fc15dd7b-2aa0-47e5-bb05-94c75950b5de
  3. most_recent = true
  4. owners = [ var.aws_marketplace_ubuntu_owner_id ]
  5. # sadly, it looks like the image isn't named correctly in govcloud. I've given
  6. # canonical feedback on this, but for now we'll use the ami id directly.
  7. #filter {
  8. # name = "name"
  9. # values = ["ubuntu-pro/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*", ]
  10. #}
  11. filter {
  12. name = "image-id"
  13. values = [ "ami-0a4050943619c0460" ]
  14. }
  15. filter {
  16. name = "root-device-type"
  17. values = ["ebs"]
  18. }
  19. filter {
  20. name = "virtualization-type"
  21. values = ["hvm"]
  22. }
  23. }
  24. module "vmray-server" {
  25. source = "terraform-aws-modules/ec2-instance/aws"
  26. version = "~> 2.0"
  27. name = "vmray-server"
  28. instance_count = 1
  29. disable_api_termination = var.instance_termination_protection
  30. ami = data.aws_ami.ubuntu_pro.image_id
  31. instance_type = var.vmray_server_instance_type
  32. key_name = var.vmray_key_name
  33. vpc_security_group_ids = [ aws_security_group.vmray_sg.id ]
  34. subnet_id = data.terraform_remote_state.standard_vpc.outputs.public_subnets[0]
  35. tags = merge(var.standard_tags, var.tags)
  36. ebs_optimized = true
  37. monitoring = false # Do we use this?
  38. user_data_base64 = data.template_cloudinit_config.cloud-init-vmray-server.rendered
  39. }
  40. #
  41. module "vmray-worker" {
  42. source = "terraform-aws-modules/ec2-instance/aws"
  43. version = "~> 2.0"
  44. name = "vmray-worker"
  45. instance_count = var.vmray_worker_instance_count
  46. disable_api_termination = var.instance_termination_protection
  47. ami = data.aws_ami.ubuntu_pro.image_id
  48. instance_type = var.vmray_worker_instance_type
  49. key_name = var.vmray_key_name
  50. vpc_security_group_ids = [ aws_security_group.vmray_sg.id ]
  51. subnet_ids = data.terraform_remote_state.standard_vpc.outputs.public_subnets
  52. tags = merge(var.standard_tags, var.tags)
  53. ebs_optimized = true
  54. monitoring = false
  55. #user_data_base64 = data.template_cloudinit_config.vmray-worker.*.rendered
  56. }
  57. data "template_file" "cloud-init-vmray-server" {
  58. # Should these be in a common directory? I suspect they'd be reusable
  59. template = file("${path.module}/cloud-init/cloud-init.tpl")
  60. vars = {
  61. hostname = "vmray_server"
  62. fqdn = "vmrayserver.TODO.makemeavariable"
  63. environment = var.environment
  64. }
  65. }
  66. # Render a multi-part cloud-init config making use of the part
  67. # above, and other source files
  68. data "template_cloudinit_config" "cloud-init-vmray-server" {
  69. gzip = true
  70. base64_encode = true
  71. # Main cloud-config configuration file.
  72. part {
  73. filename = "init.cfg"
  74. content_type = "text/cloud-config"
  75. content = data.template_file.cloud-init-vmray-server.rendered
  76. }
  77. # Additional parts as needed
  78. #part {
  79. # content_type = "text/x-shellscript"
  80. # content = "ffbaz"
  81. #}
  82. }