Skip to main content

Module: emr-cluster

Terraform module to provision an Elastic MapReduce (EMR) cluster on AWS.

Usage

For a complete example, see examples/complete

For automated tests of the complete example using bats and Terratest (which tests and deploys the example on AWS), see test.

provider "aws" {
region = "us-east-2"
}

module "vpc" {
source = "cloudposse/vpc/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"

ipv4_primary_cidr_block = "172.19.0.0/16"

context = module.this.context
}

module "subnets" {
source = "cloudposse/dynamic-subnets/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"

availability_zones = var.availability_zones
vpc_id = module.vpc.vpc_id
igw_id = [module.vpc.igw_id]
ipv4_cidr_block = [module.vpc.vpc_cidr_block]
nat_gateway_enabled = false
nat_instance_enabled = false

context = module.this.context
}

module "s3_log_storage" {
source = "cloudposse/s3-log-storage/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"

region = var.region
namespace = var.namespace
stage = var.stage
name = var.name
attributes = ["logs"]
force_destroy = true
}

module "aws_key_pair" {
source = "cloudposse/key-pair/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"
namespace = var.namespace
stage = var.stage
name = var.name
attributes = ["ssh", "key"]
ssh_public_key_path = var.ssh_public_key_path
generate_ssh_key = var.generate_ssh_key
}

module "emr_cluster" {
source = "cloudposse/emr-cluster/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"

namespace = var.namespace
stage = var.stage
name = var.name
master_allowed_security_groups = [module.vpc.vpc_default_security_group_id]
slave_allowed_security_groups = [module.vpc.vpc_default_security_group_id]
region = var.region
vpc_id = module.vpc.vpc_id
subnet_id = module.subnets.private_subnet_ids[0]
route_table_id = module.subnets.private_route_table_ids[0]
subnet_type = "private"
ebs_root_volume_size = var.ebs_root_volume_size
visible_to_all_users = var.visible_to_all_users
release_label = var.release_label
applications = var.applications
configurations_json = var.configurations_json
core_instance_group_instance_type = var.core_instance_group_instance_type
core_instance_group_instance_count = var.core_instance_group_instance_count
core_instance_group_ebs_size = var.core_instance_group_ebs_size
core_instance_group_ebs_type = var.core_instance_group_ebs_type
core_instance_group_ebs_volumes_per_instance = var.core_instance_group_ebs_volumes_per_instance
master_instance_group_instance_type = var.master_instance_group_instance_type
master_instance_group_instance_count = var.master_instance_group_instance_count
master_instance_group_ebs_size = var.master_instance_group_ebs_size
master_instance_group_ebs_type = var.master_instance_group_ebs_type
master_instance_group_ebs_volumes_per_instance = var.master_instance_group_ebs_volumes_per_instance
create_task_instance_group = var.create_task_instance_group
log_uri = format("s3n://%s/", module.s3_log_storage.bucket_id)
key_name = module.aws_key_pair.key_name
}

Requirements

NameVersion
terraform>= 0.14.0
aws>= 3.5.0

Providers

NameVersion
aws>= 3.5.0

Modules

NameSourceVersion
dns_mastercloudposse/route53-cluster-hostname/aws0.12.2
label_corecloudposse/label/null0.25.0
label_ec2cloudposse/label/null0.25.0
label_ec2_autoscalingcloudposse/label/null0.25.0
label_emrcloudposse/label/null0.25.0
label_mastercloudposse/label/null0.25.0
label_master_managedcloudposse/label/null0.25.0
label_service_managedcloudposse/label/null0.25.0
label_slavecloudposse/label/null0.25.0
label_slave_managedcloudposse/label/null0.25.0
label_taskcloudposse/label/null0.25.0
thiscloudposse/label/null0.25.0

Resources

NameType
aws_emr_cluster.defaultresource
aws_emr_instance_group.taskresource
aws_iam_instance_profile.ec2resource
aws_iam_role.ec2resource
aws_iam_role.ec2_autoscalingresource
aws_iam_role.emrresource
aws_iam_role_policy_attachment.ec2resource
aws_iam_role_policy_attachment.ec2_autoscalingresource
aws_iam_role_policy_attachment.emrresource
aws_iam_role_policy_attachment.emr_ssm_accessresource
aws_security_group.managed_masterresource
aws_security_group.managed_service_accessresource
aws_security_group.managed_slaveresource
aws_security_group.masterresource
aws_security_group.slaveresource
aws_security_group_rule.managed_master_egressresource
aws_security_group_rule.managed_master_service_access_ingressresource
aws_security_group_rule.managed_service_access_egressresource
aws_security_group_rule.managed_slave_egressresource
aws_security_group_rule.master_egressresource
aws_security_group_rule.master_ingress_cidr_blocksresource
aws_security_group_rule.master_ingress_security_groupsresource
aws_security_group_rule.slave_egressresource
aws_security_group_rule.slave_ingress_cidr_blocksresource
aws_security_group_rule.slave_ingress_security_groupsresource
aws_vpc_endpoint.vpc_endpoint_s3resource
aws_iam_policy_document.assume_role_ec2data source
aws_iam_policy_document.assume_role_emrdata source
aws_partition.currentdata source

Inputs

NameDescriptionTypeDefaultRequired
additional_infoA JSON string for selecting additional features such as adding proxy information. Note: Currently there is no API to retrieve the value of this argument after EMR cluster creation from provider, therefore Terraform cannot detect drift from the actual EMR cluster if its value is changed outside Terraformstringnullno
additional_master_security_groupThe id of the existing additional security group that will be used for EMR master node. If empty, a new security group will be createdstring""no
additional_slave_security_groupThe id of the existing additional security group that will be used for EMR core & task nodes. If empty, a new security group will be createdstring""no
additional_tag_mapAdditional key-value pairs to add to each map in tags_as_list_of_maps. Not added to tags or id.
This is for some rare cases where resources want additional configuration of tags
and therefore take a list of maps with tag key, value, and additional configuration.
map(string){}no
applicationsA list of applications for the cluster. Valid values are: Flink, Ganglia, Hadoop, HBase, HCatalog, Hive, Hue, JupyterHub, Livy, Mahout, MXNet, Oozie, Phoenix, Pig, Presto, Spark, Sqoop, TensorFlow, Tez, Zeppelin, and ZooKeeper (as of EMR 5.25.0). Case insensitivelist(string)n/ayes
attributesID element. Additional attributes (e.g. workers or cluster) to add to id,
in the order they appear in the list. New attributes are appended to the
end of the list. The elements of the list are joined by the delimiter
and treated as a single ID element.
list(string)[]no
auto_termination_idle_timeoutAuto termination policy idle timeout in seconds (60 - 604800 supported)stringnullno
bootstrap_actionList of bootstrap actions that will be run before Hadoop is started on the cluster nodes
list(object({
path = string
name = string
args = list(string)
}))
[]no
configurations_jsonA JSON string for supplying list of configurations for the EMR cluster. See https://docs.aws.amazon.com/emr/latest/ReleaseGuide/emr-configure-apps.html for more detailsstring""no
contextSingle object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as null to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional_tag_map, which are merged.
any
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"descriptor_formats": {},
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"labels_as_tags": [
"unset"
],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {},
"tenant": null
}
no
core_instance_group_autoscaling_policyString containing the EMR Auto Scaling Policy JSON for the Core instance groupstringnullno
core_instance_group_bid_priceBid price for each EC2 instance in the Core instance group, expressed in USD. By setting this attribute, the instance group is being declared as a Spot Instance, and will implicitly create a Spot request. Leave this blank to use On-Demand Instancesstringnullno
core_instance_group_ebs_iopsThe number of I/O operations per second (IOPS) that the Core volume supportsnumbernullno
core_instance_group_ebs_sizeCore instances volume size, in gibibytes (GiB)numbern/ayes
core_instance_group_ebs_typeCore instances volume type. Valid options are gp2, io1, standard and st1string"gp2"no
core_instance_group_ebs_volumes_per_instanceThe number of EBS volumes with this configuration to attach to each EC2 instance in the Core instance groupnumber1no
core_instance_group_instance_countTarget number of instances for the Core instance group. Must be at least 1number1no
core_instance_group_instance_typeEC2 instance type for all instances in the Core instance groupstringn/ayes
create_task_instance_groupWhether to create an instance group for Task nodes. For more info: https://www.terraform.io/docs/providers/aws/r/emr_instance_group.html, https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-master-core-task-nodes.htmlboolfalseno
create_vpc_endpoint_s3Set to false to prevent the module from creating VPC S3 Endpointbooltrueno
custom_ami_idA custom Amazon Linux AMI for the cluster (instead of an EMR-owned AMI). Available in Amazon EMR version 5.7.0 and laterstringnullno
delimiterDelimiter to be used between ID elements.
Defaults to - (hyphen). Set to "" to use no delimiter at all.
stringnullno
descriptor_formatsDescribe additional descriptors to be output in the descriptors output map.
Map of maps. Keys are names of descriptors. Values are maps of the form
{<br/> format = string<br/> labels = list(string)<br/>}
(Type is any so the map values can later be enhanced to provide additional options.)
format is a Terraform format string to be passed to the format() function.
labels is a list of labels, in order, to pass to format() function.
Label values will be normalized before being passed to format() so they will be
identical to how they appear in id.
Default is {} (descriptors output will be empty).
any{}no
ebs_root_volume_sizeSize in GiB of the EBS root device volume of the Linux AMI that is used for each EC2 instance. Available in Amazon EMR version 4.x and laternumber10no
ec2_autoscaling_role_enabledIf set to false, will use existing_ec2_autoscaling_role_arn for an existing EC2 autoscaling IAM role that was created outside of this modulebooltrueno
ec2_autoscaling_role_permissions_boundaryThe Permissions Boundary ARN to apply to the EC2 Autoscaling Role.string""no
ec2_role_enabledIf set to false, will use existing_ec2_instance_profile_arn for an existing EC2 IAM role that was created outside of this modulebooltrueno
ec2_role_permissions_boundaryThe Permissions Boundary ARN to apply to the EC2 Role.string""no
emr_role_permissions_boundaryThe Permissions Boundary ARN to apply to the EMR Role.string""no
enable_ssm_accessIf set to true, attach the existing AmazonSSMManagedInstanceCore IAM policy to the EMR EC2 instance profile roleboolfalseno
enabledSet to false to prevent the module from creating any resourcesboolnullno
environmentID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT'stringnullno
existing_ec2_autoscaling_role_arnARN of an existing EC2 autoscaling role to attach to the clusterstring""no
existing_ec2_instance_profile_arnARN of an existing EC2 instance profilestring""no
existing_service_role_arnARN of an existing EMR service role to attach to the clusterstring""no
id_length_limitLimit id to this many characters (minimum 6).
Set to 0 for unlimited length.
Set to null for keep the existing setting, which defaults to 0.
Does not affect id_full.
numbernullno
keep_job_flow_alive_when_no_stepsSwitch on/off run cluster with no steps or when all steps are completebooltrueno
kerberos_ad_domain_join_passwordThe Active Directory password for ad_domain_join_user. Terraform cannot perform drift detection of this configuration.stringnullno
kerberos_ad_domain_join_userRequired only when establishing a cross-realm trust with an Active Directory domain. A user with sufficient privileges to join resources to the domain. Terraform cannot perform drift detection of this configuration.stringnullno
kerberos_cross_realm_trust_principal_passwordRequired only when establishing a cross-realm trust with a KDC in a different realm. The cross-realm principal password, which must be identical across realms. Terraform cannot perform drift detection of this configuration.stringnullno
kerberos_enabledSet to true if EMR cluster will use kerberos_attributesboolfalseno
kerberos_kdc_admin_passwordThe password used within the cluster for the kadmin service on the cluster-dedicated KDC, which maintains Kerberos principals, password policies, and keytabs for the cluster. Terraform cannot perform drift detection of this configuration.stringnullno
kerberos_realmThe name of the Kerberos realm to which all nodes in a cluster belong. For example, EC2.INTERNALstring"EC2.INTERNAL"no
key_nameAmazon EC2 key pair that can be used to ssh to the master node as the user called hadoopstringnullno
label_key_caseControls the letter case of the tags keys (label names) for tags generated by this module.
Does not affect keys of tags passed in via the tags input.
Possible values: lower, title, upper.
Default value: title.
stringnullno
label_orderThe order in which the labels (ID elements) appear in the id.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present.
list(string)nullno
label_value_caseControls the letter case of ID elements (labels) as included in id,
set as tag values, and output by this module individually.
Does not affect values of tags passed in via the tags input.
Possible values: lower, title, upper and none (no transformation).
Set this to title and set delimiter to "" to yield Pascal Case IDs.
Default value: lower.
stringnullno
labels_as_tagsSet of labels (ID elements) to include as tags in the tags output.
Default is to include all labels.
Tags with empty values will not be included in the tags output.
Set to [] to suppress all generated tags.
Notes:
The value of the name tag, if included, will be the id, not the name.
Unlike other null-label inputs, the initial setting of labels_as_tags cannot be
changed in later chained modules. Attempts to change it will be silently ignored.
set(string)
[
"default"
]
no
log_uriThe path to the Amazon S3 location where logs for this cluster are storedstringnullno
managed_master_security_groupThe id of the existing managed security group that will be used for EMR master node. If empty, a new security group will be createdstring""no
managed_slave_security_groupThe id of the existing managed security group that will be used for EMR core & task nodes. If empty, a new security group will be createdstring""no
master_allowed_cidr_blocksList of CIDR blocks to be allowed to access the master instanceslist(string)[]no
master_allowed_security_groupsList of security group ids to be allowed to connect to the master instanceslist(string)[]no
master_dns_nameName of the cluster CNAME record to create in the parent DNS zone specified by zone_id. If left empty, the name will be auto-asigned using the format emr-master-var.namestringnullno
master_instance_group_bid_priceBid price for each EC2 instance in the Master instance group, expressed in USD. By setting this attribute, the instance group is being declared as a Spot Instance, and will implicitly create a Spot request. Leave this blank to use On-Demand Instancesstringnullno
master_instance_group_ebs_iopsThe number of I/O operations per second (IOPS) that the Master volume supportsnumbernullno
master_instance_group_ebs_sizeMaster instances volume size, in gibibytes (GiB)numbern/ayes
master_instance_group_ebs_typeMaster instances volume type. Valid options are gp2, io1, standard and st1string"gp2"no
master_instance_group_ebs_volumes_per_instanceThe number of EBS volumes with this configuration to attach to each EC2 instance in the Master instance groupnumber1no
master_instance_group_instance_countTarget number of instances for the Master instance group. Must be at least 1number1no
master_instance_group_instance_typeEC2 instance type for all instances in the Master instance groupstringn/ayes
nameID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
This is the only ID element not also included as a tag.
The "name" tag is set to the full id string. There is no tag with the value of the name input.
stringnullno
namespaceID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally uniquestringnullno
regex_replace_charsTerraform regular expression (regex) string.
Characters matching the regex will be removed from the ID elements.
If not set, "/[^a-zA-Z0-9-]/" is used to remove all characters other than hyphens, letters and digits.
stringnullno
regionAWS regionstringn/ayes
release_labelThe release label for the Amazon EMR release. https://docs.aws.amazon.com/emr/latest/ReleaseGuide/emr-release-5x.htmlstring"emr-5.25.0"no
route_table_idRoute table ID for the VPC S3 Endpoint when launching the EMR cluster in a private subnet. Required when subnet_type is privatestring""no
scale_down_behaviorThe way that individual Amazon EC2 instances terminate when an automatic scale-in activity occurs or an instance group is resizedstringnullno
security_configurationThe security configuration name to attach to the EMR cluster. Only valid for EMR clusters with release_label 4.8.0 or greater. See https://www.terraform.io/docs/providers/aws/r/emr_security_configuration.html for more infostringnullno
service_access_security_groupThe id of the existing additional security group that will be used for EMR core & task nodes. If empty, a new security group will be createdstring""no
service_role_enabledIf set to false, will use existing_service_role_arn for an existing IAM role that was created outside of this modulebooltrueno
slave_allowed_cidr_blocksList of CIDR blocks to be allowed to access the slave instanceslist(string)[]no
slave_allowed_security_groupsList of security group ids to be allowed to connect to the slave instanceslist(string)[]no
stageID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release'stringnullno
step_concurrency_levelThe number of steps that can be executed concurrently. You can specify a maximum of 256 steps. Only valid for EMR clusters with release_label 5.28.0 or greater.numbernullno
stepsList of steps to run when creating the cluster.
list(object({
name = string
action_on_failure = string
hadoop_jar_step = object({
args = list(string)
jar = string
main_class = string
properties = map(string)
})
}))
[]no
subnet_idVPC subnet ID where you want the job flow to launch. Cannot specify the cc1.4xlarge instance type for nodes of a job flow launched in a Amazon VPCstringn/ayes
subnet_typeType of VPC subnet ID where you want the job flow to launch. Supported values are private or publicstring"private"no
tagsAdditional tags (e.g. {'BusinessUnit': 'XYZ'}).
Neither the tag keys nor the tag values will be modified by this module.
map(string){}no
task_instance_group_autoscaling_policyString containing the EMR Auto Scaling Policy JSON for the Task instance groupstringnullno
task_instance_group_bid_priceBid price for each EC2 instance in the Task instance group, expressed in USD. By setting this attribute, the instance group is being declared as a Spot Instance, and will implicitly create a Spot request. Leave this blank to use On-Demand Instancesstringnullno
task_instance_group_ebs_iopsThe number of I/O operations per second (IOPS) that the Task volume supportsnumbernullno
task_instance_group_ebs_optimizedIndicates whether an Amazon EBS volume in the Task instance group is EBS-optimized. Changing this forces a new resource to be createdboolfalseno
task_instance_group_ebs_sizeTask instances volume size, in gibibytes (GiB)number10no
task_instance_group_ebs_typeTask instances volume type. Valid options are gp2, io1, standard and st1string"gp2"no
task_instance_group_ebs_volumes_per_instanceThe number of EBS volumes with this configuration to attach to each EC2 instance in the Task instance groupnumber1no
task_instance_group_instance_countTarget number of instances for the Task instance group. Must be at least 1number1no
task_instance_group_instance_typeEC2 instance type for all instances in the Task instance groupstringnullno
tenantID element _(Rarely used, not included by default)_. A customer identifier, indicating who this instance of a resource is forstringnullno
termination_protectionSwitch on/off termination protection (default is false, except when using multiple master nodes). Before attempting to destroy the resource when termination protection is enabled, this configuration must be applied with its value set to falseboolfalseno
use_existing_additional_master_security_groupIf set to true, will use variable additional_master_security_group using an existing security group that was created outside of this moduleboolfalseno
use_existing_additional_slave_security_groupIf set to true, will use variable additional_slave_security_group using an existing security group that was created outside of this moduleboolfalseno
use_existing_managed_master_security_groupIf set to true, will use variable managed_master_security_group using an existing security group that was created outside of this moduleboolfalseno
use_existing_managed_slave_security_groupIf set to true, will use variable managed_slave_security_group using an existing security group that was created outside of this moduleboolfalseno
use_existing_service_access_security_groupIf set to true, will use variable service_access_security_group using an existing security group that was created outside of this moduleboolfalseno
visible_to_all_usersWhether the job flow is visible to all IAM users of the AWS account associated with the job flowbooltrueno
vpc_idVPC ID to create the cluster in (e.g. vpc-a22222ee)stringn/ayes
zone_idRoute53 parent zone ID. If provided (not empty), the module will create sub-domain DNS records for the masters and slavesstringnullno

Outputs

NameDescription
cluster_idEMR cluster ID
cluster_nameEMR cluster name
ec2_roleRole name of EMR EC2 instances so users can attach more policies
master_hostName of the cluster CNAME record for the master nodes in the parent DNS zone
master_public_dnsMaster public DNS
master_security_group_idMaster security group ID
slave_security_group_idSlave security group ID