Advertisement
Guest User

Untitled

a guest
Nov 8th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. #
  2. # EMR Cluster
  3. #
  4. # Launch and configure an EMR cluster, configures metastore on RDS DB
  5. #
  6.  
  7. ### Security Groups
  8. resource "aws_security_group" "emr_sg" {
  9. name = "${var.environment["resourceprefix"]}emr-sg"
  10. description = "Allow inbound traffic from VPC subnets only"
  11. vpc_id = "${aws_vpc.default.id}"
  12. ingress {
  13. from_port = 0
  14. to_port = 0
  15. protocol = "-1"
  16. cidr_blocks = ["${var.vpc["public_subnet.cidr_block"]}","${var.vpc["private_subnet1.cidr_block"]}","${var.vpc["private_subnet2.cidr_block"]}"]
  17. }
  18. ingress {
  19. from_port = 22
  20. to_port = 22
  21. protocol = "tcp"
  22. cidr_blocks = ["0.0.0.0/0"]
  23. }
  24. egress {
  25. from_port = 0
  26. to_port = 0
  27. protocol = "-1"
  28. cidr_blocks = ["0.0.0.0/0"]
  29. }
  30. tags {
  31. Name = "${var.environment["resourceprefix"]}emr-sg"
  32. }
  33. }
  34.  
  35. resource "aws_security_group" "emr_svc_sg" {
  36. name = "${var.environment["resourceprefix"]}emr-svc-sg"
  37. description = "Allow inbound traffic from VPC subnets only"
  38. vpc_id = "${aws_vpc.default.id}"
  39. ingress {
  40. from_port = 0
  41. to_port = 0
  42. protocol = "-1"
  43. cidr_blocks = ["${var.vpc["public_subnet.cidr_block"]}","${var.vpc["private_subnet1.cidr_block"]}","${var.vpc["private_subnet2.cidr_block"]}"]
  44. }
  45. egress {
  46. from_port = 0
  47. to_port = 0
  48. protocol = "-1"
  49. cidr_blocks = ["0.0.0.0/0"]
  50. }
  51. tags {
  52. Name = "${var.environment["resourceprefix"]}emr-svc-sg"
  53. }
  54. }
  55.  
  56.  
  57. ## Metastore Config
  58. data "template_file" "emr-config" {
  59. template = "${file("config/emr_configuration.json.tpl")}"
  60. vars {
  61. rds_endpoint = "${aws_db_instance.rds_metastore_instance.endpoint}"
  62. rds_password = "${var.rds_master_pwd}"
  63. rds_username = "${var.rds["username"]}"
  64. }
  65. }
  66.  
  67. ## IAM Instance Profile
  68. data "aws_iam_instance_profile" "emr_profile" {
  69. name = "EMR_EC2_DefaultRole"
  70. }
  71.  
  72. ## IAM Instance Profile
  73. data "aws_iam_role" "iam_emr_service_role" {
  74. name = "EMR_DefaultRole"
  75. }
  76.  
  77.  
  78. ## EMR Cluster
  79. resource "aws_emr_cluster" "emr-cluster" {
  80. name = "${var.environment["resourceprefix"]}emr-cluster"
  81. release_label = "emr-5.8.0"
  82. applications = ["Hadoop","Tez","Hive","Spark","HCatalog"]
  83. termination_protection = false
  84. keep_job_flow_alive_when_no_steps = true
  85. log_uri = "s3n://aws-logs-091701061543-ap-southeast-2/elasticmapreduce/"
  86. ec2_attributes {
  87. key_name = "${var.ec2["ec2_keypair"]}"
  88. subnet_id = "${aws_subnet.private_subnet1.id}"
  89. emr_managed_master_security_group = "${aws_security_group.emr_sg.id}"
  90. emr_managed_slave_security_group = "${aws_security_group.emr_sg.id}"
  91. instance_profile = "${data.aws_iam_instance_profile.emr_profile.arn}"
  92. service_access_security_group = "${aws_security_group.emr_svc_sg.id}"
  93. }
  94.  
  95. master_instance_type = "m3.xlarge"
  96. core_instance_type = "m1.medium"
  97. core_instance_count = 1
  98.  
  99. # configure hive-site.xml for RDS metastore
  100. configurations = "${data.template_file.emr-config.rendered}"
  101. service_role = "${data.aws_iam_role.iam_emr_service_role.arn}"
  102. depends_on = ["aws_db_instance.rds_metastore_instance"]
  103. }
  104.  
  105. ### config
  106.  
  107. [
  108. {
  109. "Classification": "hive-site",
  110. "Properties": {
  111. "javax.jdo.option.ConnectionURL": "jdbc:mysql://${rds_endpoint}/hive?createDatabaseIfNotExist=true",
  112. "javax.jdo.option.ConnectionUserName": "${rds_username}",
  113. "javax.jdo.option.ConnectionPassword": "${rds_password}"
  114. }
  115. }
  116. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement