provider/aws: Add support for termination protection and autotermination to EMR.

This commit is contained in:
Evgeny Chuvpilo 2016-11-18 16:58:20 +03:00 committed by stack72
parent e014cf3d83
commit 8586e323dc
No known key found for this signature in database
GPG Key ID: 8619A619B085CB16
3 changed files with 33 additions and 4 deletions

View File

@ -70,6 +70,18 @@ func resourceAwsEMRCluster() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
"termination_protection": &schema.Schema{
Type: schema.TypeBool,
ForceNew: true,
Optional: true,
Computed: true,
},
"keep_job_flow_alive_when_no_steps": &schema.Schema{
Type: schema.TypeBool,
ForceNew: true,
Optional: true,
Computed: true,
},
"ec2_attributes": &schema.Schema{
Type: schema.TypeList,
MaxItems: 1,
@ -169,13 +181,22 @@ func resourceAwsEMRClusterCreate(d *schema.ResourceData, meta interface{}) error
applications := d.Get("applications").(*schema.Set).List()
keepJobFlowAliveWhenNoSteps := true
if v, ok := d.GetOk("keep_job_flow_alive_when_no_steps"); ok {
keepJobFlowAliveWhenNoSteps = v.(bool)
}
terminationProtection := false
if v, ok := d.GetOk("termination_protection"); ok {
terminationProtection = v.(bool)
}
instanceConfig := &emr.JobFlowInstancesConfig{
MasterInstanceType: aws.String(masterInstanceType),
SlaveInstanceType: aws.String(coreInstanceType),
InstanceCount: aws.Int64(int64(coreInstanceCount)),
// Default values that we can open up in the future
KeepJobFlowAliveWhenNoSteps: aws.Bool(true),
TerminationProtected: aws.Bool(false),
KeepJobFlowAliveWhenNoSteps: aws.Bool(keepJobFlowAliveWhenNoSteps),
TerminationProtected: aws.Bool(terminationProtection),
}
var instanceProfile string
@ -275,7 +296,7 @@ func resourceAwsEMRClusterCreate(d *schema.ResourceData, meta interface{}) error
Pending: []string{"STARTING", "BOOTSTRAPPING"},
Target: []string{"WAITING", "RUNNING"},
Refresh: resourceAwsEMRClusterStateRefreshFunc(d, meta),
Timeout: 75 * time.Minute,
Timeout: 40 * time.Minute,
MinTimeout: 10 * time.Second,
Delay: 30 * time.Second, // Wait 30 secs before starting
}

View File

@ -121,6 +121,9 @@ resource "aws_emr_cluster" "tf-test-cluster" {
name = "name-env"
}
keep_job_flow_alive_when_no_steps = true
termination_protection = false
bootstrap_action {
path = "s3://elasticmapreduce/bootstrap-actions/run-if"
name = "runif"

View File

@ -20,6 +20,9 @@ resource "aws_emr_cluster" "emr-test-cluster" {
release_label = "emr-4.6.0"
applications = ["Spark"]
termination_protection = false
keep_job_flow_alive_when_no_steps = true
ec2_attributes {
subnet_id = "${aws_subnet.main.id}"
emr_managed_master_security_group = "${aws_security_group.sg.id}"
@ -68,6 +71,8 @@ The following arguments are supported:
* `log_uri` - (Optional) S3 bucket to write the log files of the job flow. If a value
is not provided, logs are not created
* `applications` - (Optional) A list of applications for the cluster. Valid values are: `Hadoop`, `Hive`,
* `termination_protection` - (Optional) Switch on/off termination protection (default is off)
* `keep_job_flow_alive_when_no_steps` - (Optional) Switch on/off run cluster with no steps or when all steps are complete (default is on)
`Mahout`, `Pig`, and `Spark.` Case insensitive
* `ec2_attributes` - (Optional) Attributes for the EC2 instances running the job
flow. Defined below