From ba9434d74110603a18ccc98b288aec8d60ab4ce0 Mon Sep 17 00:00:00 2001 From: Jesse Collier Date: Sat, 18 Mar 2017 10:12:43 -0400 Subject: [PATCH] Added support for EMR AutoScalingRole (#12823) credit to @tolis-sisiaridis for changes Addresses https://github.com/hashicorp/terraform/issues/11126 --- .../providers/aws/resource_aws_emr_cluster.go | 9 ++ .../aws/resource_aws_emr_cluster_test.go | 96 +++++++++++++++++++ 2 files changed, 105 insertions(+) diff --git a/builtin/providers/aws/resource_aws_emr_cluster.go b/builtin/providers/aws/resource_aws_emr_cluster.go index 3017e1087..9217d0ed7 100644 --- a/builtin/providers/aws/resource_aws_emr_cluster.go +++ b/builtin/providers/aws/resource_aws_emr_cluster.go @@ -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) diff --git a/builtin/providers/aws/resource_aws_emr_cluster_test.go b/builtin/providers/aws/resource_aws_emr_cluster_test.go index ad8b16a1f..a0bac7fcf 100644 --- a/builtin/providers/aws/resource_aws_emr_cluster_test.go +++ b/builtin/providers/aws/resource_aws_emr_cluster_test.go @@ -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) }