dolphinscheduler-worker.tf 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. locals {
  18. alert_server_ip = var.ds_component_replicas.alert > 0 ? aws_instance.alert[0].private_ip : aws_instance.standalone_server[0].private_ip
  19. }
  20. resource "aws_security_group" "worker" {
  21. name = "worker_server_sg"
  22. description = "Allow incoming connections"
  23. vpc_id = aws_vpc._.id
  24. ingress {
  25. from_port = 1234
  26. to_port = 1234
  27. protocol = "tcp"
  28. security_groups = [aws_security_group.master.id, aws_security_group.api.id]
  29. description = "Allow incoming HTTP connections"
  30. }
  31. ingress {
  32. from_port = 22
  33. to_port = 22
  34. protocol = "tcp"
  35. cidr_blocks = ["0.0.0.0/0"]
  36. description = "Allow incoming SSH connections (Linux)"
  37. }
  38. egress {
  39. from_port = 0
  40. to_port = 0
  41. protocol = "-1"
  42. cidr_blocks = ["0.0.0.0/0"]
  43. }
  44. tags = merge(var.tags, {
  45. "Name" = "${var.name_prefix}-worker-sg"
  46. })
  47. }
  48. data "template_file" "worker_user_data" {
  49. template = file("templates/cloud-init.yaml")
  50. vars = {
  51. "ssh_public_key" = aws_key_pair.key_pair.public_key
  52. "dolphinscheduler_version" = var.ds_version
  53. "dolphinscheduler_component" = "worker-server"
  54. "database_address" = aws_db_instance.database.address
  55. "database_port" = aws_db_instance.database.port
  56. "database_name" = aws_db_instance.database.db_name
  57. "database_username" = aws_db_instance.database.username
  58. "database_password" = aws_db_instance.database.password
  59. "zookeeper_connect_string" = var.zookeeper_connect_string != "" ? var.zookeeper_connect_string : aws_instance.zookeeper[0].private_ip
  60. "alert_server_host" = local.alert_server_ip
  61. "s3_access_key_id" = aws_iam_access_key.s3.id
  62. "s3_secret_access_key" = aws_iam_access_key.s3.secret
  63. "s3_region" = var.aws_region
  64. "s3_bucket_name" = module.s3_bucket.s3_bucket_id
  65. "s3_endpoint" = ""
  66. }
  67. }
  68. resource "aws_instance" "worker" {
  69. count = var.ds_component_replicas.worker
  70. ami = data.aws_ami.dolphinscheduler.id
  71. instance_type = var.vm_instance_type.worker
  72. subnet_id = aws_subnet.public[0].id
  73. vpc_security_group_ids = [aws_security_group.worker.id]
  74. source_dest_check = false
  75. associate_public_ip_address = var.vm_associate_public_ip_address.worker
  76. user_data = data.template_file.worker_user_data.rendered
  77. root_block_device {
  78. volume_size = var.vm_root_volume_size.worker
  79. volume_type = var.vm_root_volume_type.worker
  80. delete_on_termination = true
  81. encrypted = true
  82. tags = merge(var.tags, {
  83. "Name" = "${var.name_prefix}-rbd"
  84. })
  85. }
  86. ebs_block_device {
  87. device_name = "/dev/xvda"
  88. volume_size = var.vm_data_volume_size.worker
  89. volume_type = var.vm_data_volume_type.worker
  90. encrypted = true
  91. delete_on_termination = true
  92. tags = merge(var.tags, {
  93. "Name" = "${var.name_prefix}-ebd"
  94. })
  95. }
  96. tags = merge(var.tags, {
  97. "Name" = "${var.name_prefix}-worker-${count.index}"
  98. })
  99. }