Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws_emr_cluster importer #4488

Merged
merged 7 commits into from
Jan 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions aws/resource_aws_emr_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func resourceAwsEMRCluster() *schema.Resource {
Read: resourceAwsEMRClusterRead,
Update: resourceAwsEMRClusterUpdate,
Delete: resourceAwsEMRClusterDelete,
Importer: &schema.ResourceImporter{
bflad marked this conversation as resolved.
Show resolved Hide resolved
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -451,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), ",")
Expand Down Expand Up @@ -664,6 +665,11 @@ func resourceAwsEMRClusterRead(d *schema.ResourceData, meta interface{}) error {
coreGroup := emrCoreInstanceGroup(instanceGroups)
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)
Expand All @@ -682,6 +688,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)
Expand Down
6 changes: 6 additions & 0 deletions aws/resource_aws_emr_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ 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,
ImportStateVerifyIgnore: []string{"configurations", "keep_job_flow_alive_when_no_steps", "core_instance_type", "core_instance_count"},
},
},
})
}
Expand Down
18 changes: 13 additions & 5 deletions website/docs/r/emr_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ for more information.
## Example Usage

```hcl
resource "aws_emr_cluster" "emr-test-cluster" {
name = "emr-test-arn"
release_label = "emr-4.6.0"
applications = ["Spark"]
resource "aws_emr_cluster" "cluster" {
name = "emr-test-arn"
release_label = "emr-4.6.0"
applications = ["Spark"]
additional_info = <<EOF
{
"instanceAwsClientConfiguration": {
Expand Down Expand Up @@ -333,7 +333,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"]
Expand Down Expand Up @@ -622,3 +622,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
```
2 changes: 1 addition & 1 deletion website/docs/r/emr_security_configuration.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
```