Skip to content

Commit

Permalink
Merge pull request #8228 from terraform-providers/td-aws_emr_cluster-…
Browse files Browse the repository at this point in the history
…ConfigMode

resource/aws_emr_cluster: Set SchemaConfigModeAttr on step configuration block attribute
  • Loading branch information
bflad authored Apr 9, 2019
2 parents 35e7062 + 468536d commit 27c8a8b
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 9 deletions.
18 changes: 10 additions & 8 deletions aws/resource_aws_emr_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,11 @@ func resourceAwsEMRCluster() *schema.Resource {
},
},
"step": {
Type: schema.TypeList,
Optional: true,
Computed: true,
ForceNew: true,
Type: schema.TypeList,
Optional: true,
Computed: true,
ForceNew: true,
ConfigMode: schema.SchemaConfigModeAttr,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"action_on_failure": {
Expand All @@ -370,10 +371,11 @@ func resourceAwsEMRCluster() *schema.Resource {
}, false),
},
"hadoop_jar_step": {
Type: schema.TypeList,
MaxItems: 1,
Required: true,
ForceNew: true,
Type: schema.TypeList,
MaxItems: 1,
Required: true,
ForceNew: true,
ConfigMode: schema.SchemaConfigModeAttr,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"args": {
Expand Down
61 changes: 61 additions & 0 deletions aws/resource_aws_emr_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,59 @@ func TestAccAWSEMRCluster_Step_Basic(t *testing.T) {
})
}

func TestAccAWSEMRCluster_Step_ConfigMode(t *testing.T) {
var cluster1, cluster2, cluster3 emr.Cluster
rInt := acctest.RandInt()
resourceName := "aws_emr_cluster.tf-test-cluster"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEmrDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSEmrClusterConfig_Step_Single(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEmrClusterExists(resourceName, &cluster1),
resource.TestCheckResourceAttr(resourceName, "step.#", "1"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"cluster_state", "configurations", "keep_job_flow_alive_when_no_steps"},
},
{
Config: testAccAWSEmrClusterConfig_Step_NoBlocks(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEmrClusterExists(resourceName, &cluster2),
resource.TestCheckResourceAttr(resourceName, "step.#", "1"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"cluster_state", "configurations", "keep_job_flow_alive_when_no_steps"},
},
{
Config: testAccAWSEmrClusterConfig_Step_Zeroed(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEmrClusterExists(resourceName, &cluster3),
resource.TestCheckResourceAttr(resourceName, "step.#", "0"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"cluster_state", "configurations", "keep_job_flow_alive_when_no_steps"},
},
},
})
}

func TestAccAWSEMRCluster_Step_Multiple(t *testing.T) {
var cluster emr.Cluster
rInt := acctest.RandInt()
Expand Down Expand Up @@ -2504,10 +2557,18 @@ func testAccAWSEmrClusterConfig_Step_Multiple(rInt int) string {
return testAccAWSEmrClusterConfig_Step(rInt, stepConfig)
}

func testAccAWSEmrClusterConfig_Step_NoBlocks(rInt int) string {
return testAccAWSEmrClusterConfig_Step(rInt, "")
}

func testAccAWSEmrClusterConfig_Step_Single(rInt int) string {
return testAccAWSEmrClusterConfig_Step(rInt, testAccAWSEmrClusterConfig_Step_DebugLoggingStep)
}

func testAccAWSEmrClusterConfig_Step_Zeroed(rInt int) string {
return testAccAWSEmrClusterConfig_Step(rInt, "step = []")
}

func testAccAWSEmrClusterConfig_Step(rInt int, stepConfig string) string {
return fmt.Sprintf(`
provider "aws" {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/emr_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ EOF

* `visible_to_all_users` - (Optional) Whether the job flow is visible to all IAM users of the AWS account associated with the job flow. Default `true`
* `autoscaling_role` - (Optional) An IAM role for automatic scaling policies. The IAM role provides permissions that the automatic scaling feature requires to launch and terminate EC2 instances in an instance group.
* `step` - (Optional) List of steps to run when creating the cluster. Defined below. It is highly recommended to utilize the [lifecycle configuration block](/docs/configuration/resources.html) with `ignore_changes` if other steps are being managed outside of Terraform.
* `step` - (Optional) List of steps to run when creating the cluster. Defined below. It is highly recommended to utilize the [lifecycle configuration block](/docs/configuration/resources.html) with `ignore_changes` if other steps are being managed outside of Terraform. This argument is processed in [attribute-as-blocks mode](/docs/configuration/attr-as-blocks.html).
* `tags` - (Optional) list of tags to apply to the EMR Cluster

## ec2_attributes
Expand Down

0 comments on commit 27c8a8b

Please sign in to comment.