From 4fc98275b00e45501981c449b3d92daeba7ff5d8 Mon Sep 17 00:00:00 2001 From: Stefan Sundin Date: Tue, 8 May 2018 18:26:52 -0700 Subject: [PATCH 1/6] Add Importer to aws_emr_cluster. --- aws/resource_aws_emr_cluster.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/aws/resource_aws_emr_cluster.go b/aws/resource_aws_emr_cluster.go index 06e380b8bbdd..c82c582d9cf3 100644 --- a/aws/resource_aws_emr_cluster.go +++ b/aws/resource_aws_emr_cluster.go @@ -26,6 +26,10 @@ func resourceAwsEMRCluster() *schema.Resource { Read: resourceAwsEMRClusterRead, Update: resourceAwsEMRClusterUpdate, Delete: resourceAwsEMRClusterDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, From 8c548959b7c2170ef2b4f27efa23932f5842d874 Mon Sep 17 00:00:00 2001 From: Stefan Sundin Date: Tue, 8 May 2018 18:27:43 -0700 Subject: [PATCH 2/6] Add import help to aws_emr_cluster documentation. Plus other minor changes. --- website/docs/r/emr_cluster.html.markdown | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/website/docs/r/emr_cluster.html.markdown b/website/docs/r/emr_cluster.html.markdown index fceda7a067cb..83c9826bf763 100644 --- a/website/docs/r/emr_cluster.html.markdown +++ b/website/docs/r/emr_cluster.html.markdown @@ -15,7 +15,7 @@ for more information. ## Example Usage ```hcl -resource "aws_emr_cluster" "emr-test-cluster" { +resource "aws_emr_cluster" "cluster" { name = "emr-test-arn" release_label = "emr-4.6.0" applications = ["Spark"] @@ -37,7 +37,7 @@ EOF emr_managed_slave_security_group = "${aws_security_group.sg.id}" instance_profile = "${aws_iam_instance_profile.emr_profile.arn}" } - + instance_group { instance_role = "CORE" instance_type = "c4.large" @@ -175,7 +175,7 @@ The following arguments are supported: * `name` - (Required) The name of the job flow * `release_label` - (Required) The release label for the Amazon EMR release * `master_instance_type` - (Optional) The EC2 instance type of the master node. Exactly one of `master_instance_type` and `instance_group` must be specified. -* `scale_down_behavior` - (Optional) The way that individual Amazon EC2 instances terminate when an automatic scale-in activity occurs or an `instance group` is resized. +* `scale_down_behavior` - (Optional) The way that individual Amazon EC2 instances terminate when an automatic scale-in activity occurs or an `instance group` is resized. * `additional_info` - (Optional) A 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 Terraform. * `service_role` - (Required) IAM role that will be assumed by the Amazon EMR service to access AWS resources * `security_configuration` - (Optional) The security configuration name to attach to the EMR cluster. Only valid for EMR clusters with `release_label` 4.8.0 or greater @@ -343,7 +343,7 @@ provider "aws" { region = "us-west-2" } -resource "aws_emr_cluster" "tf-test-cluster" { +resource "aws_emr_cluster" "cluster" { name = "emr-test-arn" release_label = "emr-4.6.0" applications = ["Spark"] @@ -632,3 +632,11 @@ resource "aws_iam_role_policy" "iam_emr_profile_policy" { EOF } ``` + +## Import + +EMR clusters can be imported using the `id`, e.g. + +``` +$ terraform import aws_emr_cluster.cluster j-123456ABCDEF +``` From 1637bb3e2756f159ac4ae1d41782e9902aedcd47 Mon Sep 17 00:00:00 2001 From: Stefan Sundin Date: Tue, 8 May 2018 18:28:12 -0700 Subject: [PATCH 3/6] Fix typos in aws_emr_security_configuration documentation. --- website/docs/r/emr_security_configuration.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/docs/r/emr_security_configuration.html.markdown b/website/docs/r/emr_security_configuration.html.markdown index 856fe93df5a2..c9f4b1292d8c 100644 --- a/website/docs/r/emr_security_configuration.html.markdown +++ b/website/docs/r/emr_security_configuration.html.markdown @@ -1,6 +1,6 @@ --- layout: "aws" -page_title: "AWS: aws_emr_security_configuraiton" +page_title: "AWS: aws_emr_security_configuration" sidebar_current: "docs-aws-resource-emr-security-configuration" description: |- Provides a resource to manage AWS EMR Security Configurations @@ -59,5 +59,5 @@ In addition to all arguments above, the following attributes are exported: EMR Security Configurations can be imported using the `name`, e.g. ``` -$ terraform import aws_emr_security_configuraiton.sc example-sc-name +$ terraform import aws_emr_security_configuration.sc example-sc-name ``` From 6cbb601cfcbfbdb2255fba82a8c9079e617cb9b2 Mon Sep 17 00:00:00 2001 From: Stefan Sundin Date: Wed, 9 May 2018 09:05:07 -0700 Subject: [PATCH 4/6] Add acceptance test for import. --- aws/resource_aws_emr_cluster_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/aws/resource_aws_emr_cluster_test.go b/aws/resource_aws_emr_cluster_test.go index ab60c887da74..389e5d59ccfe 100644 --- a/aws/resource_aws_emr_cluster_test.go +++ b/aws/resource_aws_emr_cluster_test.go @@ -31,6 +31,11 @@ func TestAccAWSEMRCluster_basic(t *testing.T) { resource.TestCheckResourceAttr("aws_emr_cluster.tf-test-cluster", "step.#", "0"), ), }, + { + ResourceName: "aws_emr_cluster.tf-test-cluster", + ImportState: true, + ImportStateVerify: true, + }, }, }) } From 2c1c04e8901655cff4a07a6a68996f5d823dcfc8 Mon Sep 17 00:00:00 2001 From: Stefan Sundin Date: Mon, 4 Jun 2018 15:49:15 -0700 Subject: [PATCH 5/6] Make TestAccAWSEMRCluster_basic pass. --- aws/resource_aws_emr_cluster.go | 6 ++++++ aws/resource_aws_emr_cluster_test.go | 7 ++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/aws/resource_aws_emr_cluster.go b/aws/resource_aws_emr_cluster.go index c82c582d9cf3..594135c552bf 100644 --- a/aws/resource_aws_emr_cluster.go +++ b/aws/resource_aws_emr_cluster.go @@ -662,6 +662,11 @@ func resourceAwsEMRClusterRead(d *schema.ResourceData, meta interface{}) error { coreGroup := findGroup(instanceGroups, "CORE") if coreGroup != nil { d.Set("core_instance_type", coreGroup.InstanceType) + d.Set("core_instance_count", coreGroup.RequestedInstanceCount) + } + masterGroup := findGroup(instanceGroups, "MASTER") + if masterGroup != nil { + d.Set("master_instance_type", masterGroup.InstanceType) } if err := d.Set("instance_group", flattenInstanceGroups(instanceGroups)); err != nil { log.Printf("[ERR] Error setting EMR instance groups: %s", err) @@ -680,6 +685,7 @@ func resourceAwsEMRClusterRead(d *schema.ResourceData, meta interface{}) error { d.Set("tags", tagsToMapEMR(cluster.Tags)) d.Set("ebs_root_volume_size", cluster.EbsRootVolumeSize) d.Set("scale_down_behavior", cluster.ScaleDownBehavior) + d.Set("termination_protection", cluster.TerminationProtected) if cluster.CustomAmiId != nil { d.Set("custom_ami_id", cluster.CustomAmiId) diff --git a/aws/resource_aws_emr_cluster_test.go b/aws/resource_aws_emr_cluster_test.go index 389e5d59ccfe..90bdb560152c 100644 --- a/aws/resource_aws_emr_cluster_test.go +++ b/aws/resource_aws_emr_cluster_test.go @@ -32,9 +32,10 @@ func TestAccAWSEMRCluster_basic(t *testing.T) { ), }, { - ResourceName: "aws_emr_cluster.tf-test-cluster", - ImportState: true, - ImportStateVerify: true, + ResourceName: "aws_emr_cluster.tf-test-cluster", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"configurations", "keep_job_flow_alive_when_no_steps", "core_instance_type", "core_instance_count"}, }, }, }) From 015ae93029866c5c57117773a97c896a37a60361 Mon Sep 17 00:00:00 2001 From: Stefan Sundin Date: Sun, 12 Aug 2018 16:10:14 -0700 Subject: [PATCH 6/6] Remove duplicate code. --- aws/resource_aws_emr_cluster.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/aws/resource_aws_emr_cluster.go b/aws/resource_aws_emr_cluster.go index 594135c552bf..26b9b5bbe0df 100644 --- a/aws/resource_aws_emr_cluster.go +++ b/aws/resource_aws_emr_cluster.go @@ -455,9 +455,6 @@ func resourceAwsEMRClusterCreate(d *schema.ResourceData, meta interface{}) error if v, ok := attributes["subnet_id"]; ok { instanceConfig.Ec2SubnetId = aws.String(v.(string)) } - if v, ok := attributes["subnet_id"]; ok { - instanceConfig.Ec2SubnetId = aws.String(v.(string)) - } if v, ok := attributes["additional_master_security_groups"]; ok { strSlice := strings.Split(v.(string), ",")