Skip to content

Commit

Permalink
fix: Properly normalize allocation_strategy values for aws_emr_cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
acwwat committed Nov 13, 2023
1 parent 1afa91e commit c6f7570
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
12 changes: 6 additions & 6 deletions internal/service/emr/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2082,9 +2082,9 @@ func flattenOnDemandSpecification(onDemandSpecification *emr.OnDemandProvisionin
return []interface{}{}
}
m := map[string]interface{}{
// The return value from api is wrong. it return "LOWEST_PRICE" instead of "lowest-price"
// "allocation_strategy": aws.StringValue(onDemandSpecification.AllocationStrategy),
"allocation_strategy": emr.OnDemandProvisioningAllocationStrategyLowestPrice,
// The return value from api is wrong. it return the value with uppercase letters and '_' vs. '-'
// The value needs to be normalized to avoid perpetual difference in the Terraform plan
"allocation_strategy": strings.Replace(strings.ToLower(aws.StringValue(onDemandSpecification.AllocationStrategy)), "_", "-", -1),
}
return []interface{}{m}
}
Expand All @@ -2101,9 +2101,9 @@ func flattenSpotSpecification(spotSpecification *emr.SpotProvisioningSpecificati
m["block_duration_minutes"] = aws.Int64Value(spotSpecification.BlockDurationMinutes)
}
if spotSpecification.AllocationStrategy != nil {
// The return value from api is wrong. It return "CAPACITY_OPTIMIZED" instead of "capacity-optimized"
// m["allocation_strategy"] = aws.StringValue(spotSpecification.AllocationStrategy)
m["allocation_strategy"] = emr.SpotProvisioningAllocationStrategyCapacityOptimized
// The return value from api is wrong. it return the value with uppercase letters and '_' vs. '-'
// The value needs to be normalized to avoid perpetual difference in the Terraform plan
m["allocation_strategy"] = strings.Replace(strings.ToLower(aws.StringValue(spotSpecification.AllocationStrategy)), "_", "-", -1)
}

return []interface{}{m}
Expand Down
4 changes: 3 additions & 1 deletion internal/service/emr/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1622,6 +1622,7 @@ func TestAccEMRCluster_InstanceFleet_basic(t *testing.T) {
resource.TestCheckTypeSetElemAttrPair(resourceName, "ec2_attributes.0.subnet_ids.*", subnetResourceName, "id"),
resource.TestCheckResourceAttr(resourceName, "master_instance_group.#", "0"),
resource.TestCheckResourceAttr(resourceName, "core_instance_group.#", "0"),
resource.TestCheckResourceAttr(resourceName, "core_instance_fleet.0.launch_specifications.0.spot_specification.0.allocation_strategy", "capacity-optimized"),
),
},
{
Expand All @@ -1647,6 +1648,7 @@ func TestAccEMRCluster_InstanceFleet_basic(t *testing.T) {
resource.TestCheckTypeSetElemAttrPair(resourceName, "ec2_attributes.0.subnet_ids.*", subnet2ResourceName, "id"),
resource.TestCheckResourceAttr(resourceName, "master_instance_group.#", "0"),
resource.TestCheckResourceAttr(resourceName, "core_instance_group.#", "0"),
resource.TestCheckResourceAttr(resourceName, "core_instance_fleet.0.launch_specifications.0.spot_specification.0.allocation_strategy", "price-capacity-optimized"),
),
},
{
Expand Down Expand Up @@ -3980,7 +3982,7 @@ resource "aws_emr_cluster" "test" {
}
launch_specifications {
spot_specification {
allocation_strategy = "capacity-optimized"
allocation_strategy = "price-capacity-optimized"
block_duration_minutes = 0
timeout_action = "SWITCH_TO_ON_DEMAND"
timeout_duration_minutes = 10
Expand Down
6 changes: 3 additions & 3 deletions website/docs/r/emr_instance_fleet.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,18 @@ Attributes for the EBS volumes attached to each EC2 instance in the `master_inst
* `on_demand_specification` - (Optional) Configuration block for on demand instances launch specifications
* `spot_specification` - (Optional) Configuration block for spot instances launch specifications

## on_demand_specification Configuration Block
## on_demand_specification Configuration Block

The launch specification for On-Demand instances in the instance fleet, which determines the allocation strategy.
The instance fleet configuration is available only in Amazon EMR versions 4.8.0 and later, excluding 5.0.x versions. On-Demand instances allocation strategy is available in Amazon EMR version 5.12.1 and later.

* `allocation_strategy` - (Required) Specifies the strategy to use in launching On-Demand instance fleets. Currently, the only option is `lowest-price` (the default), which launches the lowest price first.

## spot_specification Configuration Block
## spot_specification Configuration Block

The launch specification for Spot instances in the fleet, which determines the defined duration, provisioning timeout behavior, and allocation strategy.

* `allocation_strategy` - (Required) Specifies the strategy to use in launching Spot instance fleets. Currently, the only option is `capacity-optimized` (the default), which launches instances from Spot instance pools with optimal capacity for the number of instances that are launching.
* `allocation_strategy` - (Required) Specifies one of the following strategies to launch Spot Instance fleets: `price-capacity-optimized`, `capacity-optimized`, `lowest-price`, or `diversified`. For more information on the provisioning strategies, see [Allocation strategies for Spot Instances](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet-allocation-strategy.html).
* `block_duration_minutes` - (Optional) The defined duration for Spot instances (also known as Spot blocks) in minutes. When specified, the Spot instance does not terminate before the defined duration expires, and defined duration pricing for Spot instances applies. Valid values are 60, 120, 180, 240, 300, or 360. The duration period starts as soon as a Spot instance receives its instance ID. At the end of the duration, Amazon EC2 marks the Spot instance for termination and provides a Spot instance termination notice, which gives the instance a two-minute warning before it terminates.
* `timeout_action` - (Required) The action to take when TargetSpotCapacity has not been fulfilled when the TimeoutDurationMinutes has expired; that is, when all Spot instances could not be provisioned within the Spot provisioning timeout. Valid values are `TERMINATE_CLUSTER` and `SWITCH_TO_ON_DEMAND`. SWITCH_TO_ON_DEMAND specifies that if no Spot instances are available, On-Demand Instances should be provisioned to fulfill any remaining Spot capacity.
* `timeout_duration_minutes` - (Required) The spot provisioning timeout period in minutes. If Spot instances are not provisioned within this time period, the TimeOutAction is taken. Minimum value is 5 and maximum value is 1440. The timeout applies only during initial provisioning, when the cluster is first created.
Expand Down

0 comments on commit c6f7570

Please sign in to comment.