Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # EMR Cluster
- #
- # Launch and configure an EMR cluster, configures metastore on RDS DB
- #
- ### Security Groups
- resource "aws_security_group" "emr_sg" {
- name = "${var.environment["resourceprefix"]}emr-sg"
- description = "Allow inbound traffic from VPC subnets only"
- vpc_id = "${aws_vpc.default.id}"
- ingress {
- from_port = 0
- to_port = 0
- protocol = "-1"
- cidr_blocks = ["${var.vpc["public_subnet.cidr_block"]}","${var.vpc["private_subnet1.cidr_block"]}","${var.vpc["private_subnet2.cidr_block"]}"]
- }
- ingress {
- from_port = 22
- to_port = 22
- protocol = "tcp"
- cidr_blocks = ["0.0.0.0/0"]
- }
- egress {
- from_port = 0
- to_port = 0
- protocol = "-1"
- cidr_blocks = ["0.0.0.0/0"]
- }
- tags {
- Name = "${var.environment["resourceprefix"]}emr-sg"
- }
- }
- resource "aws_security_group" "emr_svc_sg" {
- name = "${var.environment["resourceprefix"]}emr-svc-sg"
- description = "Allow inbound traffic from VPC subnets only"
- vpc_id = "${aws_vpc.default.id}"
- ingress {
- from_port = 0
- to_port = 0
- protocol = "-1"
- cidr_blocks = ["${var.vpc["public_subnet.cidr_block"]}","${var.vpc["private_subnet1.cidr_block"]}","${var.vpc["private_subnet2.cidr_block"]}"]
- }
- egress {
- from_port = 0
- to_port = 0
- protocol = "-1"
- cidr_blocks = ["0.0.0.0/0"]
- }
- tags {
- Name = "${var.environment["resourceprefix"]}emr-svc-sg"
- }
- }
- ## Metastore Config
- data "template_file" "emr-config" {
- template = "${file("config/emr_configuration.json.tpl")}"
- vars {
- rds_endpoint = "${aws_db_instance.rds_metastore_instance.endpoint}"
- rds_password = "${var.rds_master_pwd}"
- rds_username = "${var.rds["username"]}"
- }
- }
- ## IAM Instance Profile
- data "aws_iam_instance_profile" "emr_profile" {
- name = "EMR_EC2_DefaultRole"
- }
- ## IAM Instance Profile
- data "aws_iam_role" "iam_emr_service_role" {
- name = "EMR_DefaultRole"
- }
- ## EMR Cluster
- resource "aws_emr_cluster" "emr-cluster" {
- name = "${var.environment["resourceprefix"]}emr-cluster"
- release_label = "emr-5.8.0"
- applications = ["Hadoop","Tez","Hive","Spark","HCatalog"]
- termination_protection = false
- keep_job_flow_alive_when_no_steps = true
- log_uri = "s3n://aws-logs-091701061543-ap-southeast-2/elasticmapreduce/"
- ec2_attributes {
- key_name = "${var.ec2["ec2_keypair"]}"
- subnet_id = "${aws_subnet.private_subnet1.id}"
- emr_managed_master_security_group = "${aws_security_group.emr_sg.id}"
- emr_managed_slave_security_group = "${aws_security_group.emr_sg.id}"
- instance_profile = "${data.aws_iam_instance_profile.emr_profile.arn}"
- service_access_security_group = "${aws_security_group.emr_svc_sg.id}"
- }
- master_instance_type = "m3.xlarge"
- core_instance_type = "m1.medium"
- core_instance_count = 1
- # configure hive-site.xml for RDS metastore
- configurations = "${data.template_file.emr-config.rendered}"
- service_role = "${data.aws_iam_role.iam_emr_service_role.arn}"
- depends_on = ["aws_db_instance.rds_metastore_instance"]
- }
- ### config
- [
- {
- "Classification": "hive-site",
- "Properties": {
- "javax.jdo.option.ConnectionURL": "jdbc:mysql://${rds_endpoint}/hive?createDatabaseIfNotExist=true",
- "javax.jdo.option.ConnectionUserName": "${rds_username}",
- "javax.jdo.option.ConnectionPassword": "${rds_password}"
- }
- }
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement