Skip to content

Commit a49e2fc

Browse files
committed
fix: Properly normalize allocation_strategy values for aws_emr_cluster
1 parent 1afa91e commit a49e2fc

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

.changelog/34367.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/aws_emr_cluster: Properly normalize `allocation_strategy` values to fix perpetual state differences
3+
```

internal/service/emr/cluster.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -2082,9 +2082,9 @@ func flattenOnDemandSpecification(onDemandSpecification *emr.OnDemandProvisionin
20822082
return []interface{}{}
20832083
}
20842084
m := map[string]interface{}{
2085-
// The return value from api is wrong. it return "LOWEST_PRICE" instead of "lowest-price"
2086-
// "allocation_strategy": aws.StringValue(onDemandSpecification.AllocationStrategy),
2087-
"allocation_strategy": emr.OnDemandProvisioningAllocationStrategyLowestPrice,
2085+
// The return value from api is wrong. it return the value with uppercase letters and '_' vs. '-'
2086+
// The value needs to be normalized to avoid perpetual difference in the Terraform plan
2087+
"allocation_strategy": strings.Replace(strings.ToLower(aws.StringValue(onDemandSpecification.AllocationStrategy)), "_", "-", -1),
20882088
}
20892089
return []interface{}{m}
20902090
}
@@ -2101,9 +2101,9 @@ func flattenSpotSpecification(spotSpecification *emr.SpotProvisioningSpecificati
21012101
m["block_duration_minutes"] = aws.Int64Value(spotSpecification.BlockDurationMinutes)
21022102
}
21032103
if spotSpecification.AllocationStrategy != nil {
2104-
// The return value from api is wrong. It return "CAPACITY_OPTIMIZED" instead of "capacity-optimized"
2105-
// m["allocation_strategy"] = aws.StringValue(spotSpecification.AllocationStrategy)
2106-
m["allocation_strategy"] = emr.SpotProvisioningAllocationStrategyCapacityOptimized
2104+
// The return value from api is wrong. it return the value with uppercase letters and '_' vs. '-'
2105+
// The value needs to be normalized to avoid perpetual difference in the Terraform plan
2106+
m["allocation_strategy"] = strings.Replace(strings.ToLower(aws.StringValue(spotSpecification.AllocationStrategy)), "_", "-", -1)
21072107
}
21082108

21092109
return []interface{}{m}

internal/service/emr/cluster_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,7 @@ func TestAccEMRCluster_InstanceFleet_basic(t *testing.T) {
16221622
resource.TestCheckTypeSetElemAttrPair(resourceName, "ec2_attributes.0.subnet_ids.*", subnetResourceName, "id"),
16231623
resource.TestCheckResourceAttr(resourceName, "master_instance_group.#", "0"),
16241624
resource.TestCheckResourceAttr(resourceName, "core_instance_group.#", "0"),
1625+
resource.TestCheckResourceAttr(resourceName, "core_instance_fleet.0.launch_specifications.0.spot_specification.0.allocation_strategy", "capacity-optimized"),
16251626
),
16261627
},
16271628
{
@@ -1647,6 +1648,7 @@ func TestAccEMRCluster_InstanceFleet_basic(t *testing.T) {
16471648
resource.TestCheckTypeSetElemAttrPair(resourceName, "ec2_attributes.0.subnet_ids.*", subnet2ResourceName, "id"),
16481649
resource.TestCheckResourceAttr(resourceName, "master_instance_group.#", "0"),
16491650
resource.TestCheckResourceAttr(resourceName, "core_instance_group.#", "0"),
1651+
resource.TestCheckResourceAttr(resourceName, "core_instance_fleet.0.launch_specifications.0.spot_specification.0.allocation_strategy", "price-capacity-optimized"),
16501652
),
16511653
},
16521654
{
@@ -3980,7 +3982,7 @@ resource "aws_emr_cluster" "test" {
39803982
}
39813983
launch_specifications {
39823984
spot_specification {
3983-
allocation_strategy = "capacity-optimized"
3985+
allocation_strategy = "price-capacity-optimized"
39843986
block_duration_minutes = 0
39853987
timeout_action = "SWITCH_TO_ON_DEMAND"
39863988
timeout_duration_minutes = 10

website/docs/r/emr_instance_fleet.html.markdown

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,18 @@ Attributes for the EBS volumes attached to each EC2 instance in the `master_inst
9595
* `on_demand_specification` - (Optional) Configuration block for on demand instances launch specifications
9696
* `spot_specification` - (Optional) Configuration block for spot instances launch specifications
9797

98-
## on_demand_specification Configuration Block
98+
## on_demand_specification Configuration Block
9999

100100
The launch specification for On-Demand instances in the instance fleet, which determines the allocation strategy.
101101
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.
102102

103103
* `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.
104104

105-
## spot_specification Configuration Block
105+
## spot_specification Configuration Block
106106

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

109-
* `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.
109+
* `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).
110110
* `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.
111111
* `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.
112112
* `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.

0 commit comments

Comments
 (0)