worker.tf 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. resource "aws_network_interface" "vmray-worker-interface" {
  2. count = var.vmray_worker_instance_count
  3. subnet_id = var.private_subnets[count.index % 3]
  4. security_groups = [ data.aws_security_group.typical-host.id, aws_security_group.vmray_worker_sg.id ]
  5. description = "vmray-worker"
  6. tags = merge(var.standard_tags, var.tags, { Name = "vmray-worker" })
  7. }
  8. resource "aws_instance" "vmray-worker-instance" {
  9. count = var.vmray_worker_instance_count
  10. tenancy = "default"
  11. ebs_optimized = true
  12. disable_api_termination = var.instance_termination_protection
  13. instance_initiated_shutdown_behavior = "stop"
  14. instance_type = var.instance_types["vmray-worker"]
  15. key_name = "msoc-build"
  16. monitoring = false
  17. iam_instance_profile = "msoc-default-instance-profile"
  18. ami = data.aws_ami.ubuntu2004.image_id
  19. # We need to ignore ebs_block_device changes, because if the AMI changes, so does the snapshot_id.
  20. # If they add a feature to block more specific changes (eg `ebs_block_devices[*].snapshot_id`), then
  21. # that could be removed.
  22. lifecycle { ignore_changes = [ ami, key_name, user_data, ebs_block_device ] }
  23. root_block_device {
  24. volume_type = "gp3"
  25. volume_size = "60"
  26. delete_on_termination = true
  27. encrypted = true
  28. kms_key_id = data.aws_kms_key.ebs-key.arn
  29. }
  30. network_interface {
  31. device_index = 0
  32. network_interface_id = aws_network_interface.vmray-worker-interface[count.index].id
  33. }
  34. user_data = data.template_cloudinit_config.cloud-init-vmray-worker[count.index].rendered
  35. tags = merge( var.standard_tags, var.tags, { Name = "vmray-worker-${ count.index }" })
  36. volume_tags = merge( var.standard_tags, var.tags, { Name = "vmray-worker-${ count.index }" })
  37. }
  38. # Render a multi-part cloud-init config making use of the part
  39. # above, and other source files
  40. data "template_cloudinit_config" "cloud-init-vmray-worker" {
  41. count = var.vmray_worker_instance_count
  42. gzip = true
  43. base64_encode = true
  44. # Main cloud-config configuration file.
  45. part {
  46. filename = "init.cfg"
  47. content_type = "text/cloud-config"
  48. content = templatefile("${path.module}/cloud-init/cloud-init.tpl",
  49. {
  50. hostname = "vmray-worker-${ count.index }"
  51. fqdn = "vmray-worker-${ count.index }.${var.dns_info["private"]["zone"]}"
  52. environment = var.environment
  53. salt_master = var.salt_master
  54. proxy = var.proxy
  55. aws_partition = var.aws_partition
  56. aws_partition_alias = var.aws_partition_alias
  57. aws_region = var.aws_region
  58. ua_key = local.secret_ubuntu["ua_key"] # This is gathered in server.tf
  59. }
  60. )
  61. }
  62. # Additional parts as needed
  63. #part {
  64. # content_type = "text/x-shellscript"
  65. # content = "ffbaz"
  66. #}
  67. }
  68. module "private_dns_record_vmray_worker" {
  69. count = var.vmray_worker_instance_count
  70. source = "../../submodules/dns/private_A_record"
  71. name = "vmray-worker-${ count.index }"
  72. ip_addresses = [ aws_instance.vmray-worker-instance[count.index].private_ip ]
  73. dns_info = var.dns_info
  74. reverse_enabled = true
  75. providers = {
  76. aws.c2 = aws.c2
  77. }
  78. }