Added support for EMR AutoScalingRole (#12823)
credit to @tolis-sisiaridis for changes Addresses https://github.com/hashicorp/terraform/issues/11126
This commit is contained in:
parent
f36195849e
commit
ba9434d741
|
@ -157,6 +157,11 @@ func resourceAwsEMRCluster() *schema.Resource {
|
|||
ForceNew: true,
|
||||
Required: true,
|
||||
},
|
||||
"autoscaling_role": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
ForceNew: true,
|
||||
Optional: true,
|
||||
},
|
||||
"visible_to_all_users": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
|
@ -259,6 +264,9 @@ func resourceAwsEMRClusterCreate(d *schema.ResourceData, meta interface{}) error
|
|||
if v, ok := d.GetOk("log_uri"); ok {
|
||||
params.LogUri = aws.String(v.(string))
|
||||
}
|
||||
if v, ok := d.GetOk("autoscaling_role"); ok {
|
||||
params.AutoScalingRole = aws.String(v.(string))
|
||||
}
|
||||
|
||||
if instanceProfile != "" {
|
||||
params.JobFlowRole = aws.String(instanceProfile)
|
||||
|
@ -353,6 +361,7 @@ func resourceAwsEMRClusterRead(d *schema.ResourceData, meta interface{}) error {
|
|||
|
||||
d.Set("name", cluster.Name)
|
||||
d.Set("service_role", cluster.ServiceRole)
|
||||
d.Set("autoscaling_role", cluster.AutoScalingRole)
|
||||
d.Set("release_label", cluster.ReleaseLabel)
|
||||
d.Set("log_uri", cluster.LogUri)
|
||||
d.Set("master_public_dns", cluster.MasterPublicDnsName)
|
||||
|
|
|
@ -237,6 +237,7 @@ resource "aws_emr_cluster" "tf-test-cluster" {
|
|||
depends_on = ["aws_main_route_table_association.a"]
|
||||
|
||||
service_role = "${aws_iam_role.iam_emr_default_role.arn}"
|
||||
autoscaling_role = "${aws_iam_role.emr-autoscaling-role.arn}"
|
||||
}
|
||||
|
||||
resource "aws_security_group" "allow_all" {
|
||||
|
@ -474,6 +475,29 @@ resource "aws_iam_policy" "iam_emr_profile_policy" {
|
|||
}
|
||||
EOT
|
||||
}
|
||||
|
||||
# IAM Role for autoscaling
|
||||
resource "aws_iam_role" "emr-autoscaling-role" {
|
||||
name = "EMR_AutoScaling_DefaultRole"
|
||||
assume_role_policy = "${data.aws_iam_policy_document.emr-autoscaling-role-policy.json}"
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "emr-autoscaling-role-policy" {
|
||||
statement {
|
||||
effect = "Allow"
|
||||
actions = ["sts:AssumeRole"]
|
||||
|
||||
principals = {
|
||||
type = "Service"
|
||||
identifiers = ["elasticmapreduce.amazonaws.com","application-autoscaling.amazonaws.com"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_iam_role_policy_attachment" "emr-autoscaling-role" {
|
||||
role = "${aws_iam_role.emr-autoscaling-role.name}"
|
||||
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceforAutoScalingRole"
|
||||
}
|
||||
`, r, r, r, r, r, r)
|
||||
}
|
||||
|
||||
|
@ -520,6 +544,7 @@ resource "aws_emr_cluster" "tf-test-cluster" {
|
|||
depends_on = ["aws_main_route_table_association.a"]
|
||||
|
||||
service_role = "${aws_iam_role.iam_emr_default_role.arn}"
|
||||
autoscaling_role = "${aws_iam_role.emr-autoscaling-role.arn}"
|
||||
}
|
||||
|
||||
resource "aws_security_group" "allow_all" {
|
||||
|
@ -757,6 +782,29 @@ resource "aws_iam_policy" "iam_emr_profile_policy" {
|
|||
}
|
||||
EOT
|
||||
}
|
||||
|
||||
# IAM Role for autoscaling
|
||||
resource "aws_iam_role" "emr-autoscaling-role" {
|
||||
name = "EMR_AutoScaling_DefaultRole"
|
||||
assume_role_policy = "${data.aws_iam_policy_document.emr-autoscaling-role-policy.json}"
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "emr-autoscaling-role-policy" {
|
||||
statement {
|
||||
effect = "Allow"
|
||||
actions = ["sts:AssumeRole"]
|
||||
|
||||
principals = {
|
||||
type = "Service"
|
||||
identifiers = ["elasticmapreduce.amazonaws.com","application-autoscaling.amazonaws.com"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_iam_role_policy_attachment" "emr-autoscaling-role" {
|
||||
role = "${aws_iam_role.emr-autoscaling-role.name}"
|
||||
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceforAutoScalingRole"
|
||||
}
|
||||
`, r, r, r, r, r, r)
|
||||
}
|
||||
|
||||
|
@ -803,6 +851,7 @@ resource "aws_emr_cluster" "tf-test-cluster" {
|
|||
depends_on = ["aws_main_route_table_association.a"]
|
||||
|
||||
service_role = "${aws_iam_role.iam_emr_default_role.arn}"
|
||||
autoscaling_role = "${aws_iam_role.emr-autoscaling-role.arn}"
|
||||
}
|
||||
|
||||
resource "aws_security_group" "allow_all" {
|
||||
|
@ -1040,6 +1089,29 @@ resource "aws_iam_policy" "iam_emr_profile_policy" {
|
|||
}
|
||||
EOT
|
||||
}
|
||||
|
||||
# IAM Role for autoscaling
|
||||
resource "aws_iam_role" "emr-autoscaling-role" {
|
||||
name = "EMR_AutoScaling_DefaultRole"
|
||||
assume_role_policy = "${data.aws_iam_policy_document.emr-autoscaling-role-policy.json}"
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "emr-autoscaling-role-policy" {
|
||||
statement {
|
||||
effect = "Allow"
|
||||
actions = ["sts:AssumeRole"]
|
||||
|
||||
principals = {
|
||||
type = "Service"
|
||||
identifiers = ["elasticmapreduce.amazonaws.com","application-autoscaling.amazonaws.com"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_iam_role_policy_attachment" "emr-autoscaling-role" {
|
||||
role = "${aws_iam_role.emr-autoscaling-role.name}"
|
||||
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceforAutoScalingRole"
|
||||
}
|
||||
`, r, r, r, r, r, r)
|
||||
}
|
||||
|
||||
|
@ -1085,6 +1157,7 @@ resource "aws_emr_cluster" "tf-test-cluster" {
|
|||
depends_on = ["aws_main_route_table_association.a"]
|
||||
|
||||
service_role = "${aws_iam_role.iam_emr_default_role.arn}"
|
||||
autoscaling_role = "${aws_iam_role.emr-autoscaling-role.arn}"
|
||||
}
|
||||
|
||||
resource "aws_security_group" "allow_all" {
|
||||
|
@ -1322,5 +1395,28 @@ resource "aws_iam_policy" "iam_emr_profile_policy" {
|
|||
}
|
||||
EOT
|
||||
}
|
||||
|
||||
# IAM Role for autoscaling
|
||||
resource "aws_iam_role" "emr-autoscaling-role" {
|
||||
name = "EMR_AutoScaling_DefaultRole"
|
||||
assume_role_policy = "${data.aws_iam_policy_document.emr-autoscaling-role-policy.json}"
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "emr-autoscaling-role-policy" {
|
||||
statement {
|
||||
effect = "Allow"
|
||||
actions = ["sts:AssumeRole"]
|
||||
|
||||
principals = {
|
||||
type = "Service"
|
||||
identifiers = ["elasticmapreduce.amazonaws.com","application-autoscaling.amazonaws.com"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_iam_role_policy_attachment" "emr-autoscaling-role" {
|
||||
role = "${aws_iam_role.emr-autoscaling-role.name}"
|
||||
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceforAutoScalingRole"
|
||||
}
|
||||
`, r, r, r, r, r, r)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue