Skip to content

Commit

Permalink
removed field instance_interruption_behaviour from spot_instance_request
Browse files Browse the repository at this point in the history
Signed-off-by: dirk39 <andreaquin1990@gmail.com>
  • Loading branch information
dirk39 authored and anGie44 committed Jan 26, 2022
1 parent 040b407 commit 9389ed3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 146 deletions.
38 changes: 5 additions & 33 deletions internal/service/ec2/spot_instance_request.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ec2

import (
"context"
"fmt"
"log"
"math/big"
Expand Down Expand Up @@ -101,23 +100,12 @@ func ResourceSpotInstanceRequest() *schema.Resource {
ForceNew: true,
ValidateFunc: validation.IntDivisibleBy(60),
}
s["instance_interruption_behaviour"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(ec2.InstanceInterruptionBehavior_Values(), false),
Deprecated: "Use the parameter \"instance_interruption_behavior\" instead.",
ConflictsWith: []string{"instance_interruption_behavior"},
}
s["instance_interruption_behavior"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true, // Only during `instance_interruption_behaviour` deprecation period
// Default: ec2.InstanceInterruptionBehaviorTerminate,
ForceNew: true,
ValidateFunc: validation.StringInSlice(ec2.InstanceInterruptionBehavior_Values(), false),
ConflictsWith: []string{"instance_interruption_behaviour"},
Type: schema.TypeString,
Optional: true,
Default: ec2.InstanceInterruptionBehaviorTerminate,
ForceNew: true,
ValidateFunc: validation.StringInSlice(ec2.InstanceInterruptionBehavior_Values(), false),
}
s["valid_from"] = &schema.Schema{
Type: schema.TypeString,
Expand All @@ -138,21 +126,6 @@ func ResourceSpotInstanceRequest() *schema.Resource {

CustomizeDiff: customdiff.All(
verify.SetTagsDiff,
// This function exists to apply a default value to `instance_interruption_behavior` while
// accounting for the deprecated parameter `instance_interruption_behaviour`. It can be removed
// in favor of setting a `Default` on the parameter once `instance_interruption_behaviour` is removed.
// https://github.com/hashicorp/terraform-provider-aws/issues/20101
func(_ context.Context, diff *schema.ResourceDiff, meta interface{}) error {
if v, ok := diff.GetOk("instance_interruption_behavior"); ok && v != "" {
return nil
}
if v, ok := diff.GetOk("instance_interruption_behaviour"); ok && v != "" {
diff.SetNew("instance_interruption_behavior", v)
return nil
}
diff.SetNew("instance_interruption_behavior", ec2.InstanceInterruptionBehaviorTerminate)
return nil
},
),
}
}
Expand Down Expand Up @@ -373,7 +346,6 @@ func resourceSpotInstanceRequestRead(d *schema.ResourceData, meta interface{}) e
}

d.Set("instance_interruption_behavior", request.InstanceInterruptionBehavior)
d.Set("instance_interruption_behaviour", request.InstanceInterruptionBehavior)
d.Set("valid_from", aws.TimeValue(request.ValidFrom).Format(time.RFC3339))
d.Set("valid_until", aws.TimeValue(request.ValidUntil).Format(time.RFC3339))
d.Set("spot_type", request.Type)
Expand Down
112 changes: 0 additions & 112 deletions internal/service/ec2/spot_instance_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func TestAccEC2SpotInstanceRequest_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "spot_bid_status", "fulfilled"),
resource.TestCheckResourceAttr(resourceName, "spot_request_state", "active"),
resource.TestCheckResourceAttr(resourceName, "instance_interruption_behavior", "terminate"),
resource.TestCheckResourceAttr(resourceName, "instance_interruption_behaviour", "terminate"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
),
},
Expand Down Expand Up @@ -616,7 +615,6 @@ func TestAccEC2SpotInstanceRequest_interruptStop(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "spot_bid_status", "fulfilled"),
resource.TestCheckResourceAttr(resourceName, "spot_request_state", "active"),
resource.TestCheckResourceAttr(resourceName, "instance_interruption_behavior", "stop"),
resource.TestCheckResourceAttr(resourceName, "instance_interruption_behaviour", "stop"),
),
},
{
Expand Down Expand Up @@ -646,7 +644,6 @@ func TestAccEC2SpotInstanceRequest_interruptHibernate(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "spot_bid_status", "fulfilled"),
resource.TestCheckResourceAttr(resourceName, "spot_request_state", "active"),
resource.TestCheckResourceAttr(resourceName, "instance_interruption_behavior", "hibernate"),
resource.TestCheckResourceAttr(resourceName, "instance_interruption_behaviour", "hibernate"),
),
},
{
Expand Down Expand Up @@ -674,7 +671,6 @@ func TestAccEC2SpotInstanceRequest_interruptUpdate(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckSpotInstanceRequestExists(resourceName, &sir1),
resource.TestCheckResourceAttr(resourceName, "instance_interruption_behavior", "hibernate"),
resource.TestCheckResourceAttr(resourceName, "instance_interruption_behaviour", "hibernate"),
),
},
{
Expand All @@ -683,99 +679,6 @@ func TestAccEC2SpotInstanceRequest_interruptUpdate(t *testing.T) {
testAccCheckSpotInstanceRequestExists(resourceName, &sir2),
testAccCheckSpotInstanceRequestRecreated(&sir1, &sir2),
resource.TestCheckResourceAttr(resourceName, "instance_interruption_behavior", "terminate"),
resource.TestCheckResourceAttr(resourceName, "instance_interruption_behaviour", "terminate"),
),
},
},
})
}

func TestAccEC2SpotInstanceRequest_interruptDeprecated(t *testing.T) {
var sir ec2.SpotInstanceRequest
resourceName := "aws_spot_instance_request.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckSpotInstanceRequestDestroy,
Steps: []resource.TestStep{
{
Config: testAccSpotInstanceRequestInterruptConfig_Deprecated("hibernate"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckSpotInstanceRequestExists(resourceName, &sir),
resource.TestCheckResourceAttr(resourceName, "spot_bid_status", "fulfilled"),
resource.TestCheckResourceAttr(resourceName, "spot_request_state", "active"),
resource.TestCheckResourceAttr(resourceName, "instance_interruption_behavior", "hibernate"),
resource.TestCheckResourceAttr(resourceName, "instance_interruption_behaviour", "hibernate"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait_for_fulfillment"},
},
},
})
}

func TestAccEC2SpotInstanceRequest_interruptFixDeprecated(t *testing.T) {
var sir1, sir2 ec2.SpotInstanceRequest
resourceName := "aws_spot_instance_request.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckSpotInstanceRequestDestroy,
Steps: []resource.TestStep{
{
Config: testAccSpotInstanceRequestInterruptConfig_Deprecated("hibernate"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckSpotInstanceRequestExists(resourceName, &sir1),
resource.TestCheckResourceAttr(resourceName, "instance_interruption_behavior", "hibernate"),
resource.TestCheckResourceAttr(resourceName, "instance_interruption_behaviour", "hibernate"),
),
},
{
Config: testAccSpotInstanceRequestInterruptConfig("hibernate"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckSpotInstanceRequestExists(resourceName, &sir2),
testAccCheckSpotInstanceRequestNotRecreated(&sir1, &sir2),
resource.TestCheckResourceAttr(resourceName, "instance_interruption_behavior", "hibernate"),
resource.TestCheckResourceAttr(resourceName, "instance_interruption_behaviour", "hibernate"),
),
},
},
})
}

func TestAccEC2SpotInstanceRequest_interruptUpdateFromDeprecated(t *testing.T) {
var sir1, sir2 ec2.SpotInstanceRequest
resourceName := "aws_spot_instance_request.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckSpotInstanceRequestDestroy,
Steps: []resource.TestStep{
{
Config: testAccSpotInstanceRequestInterruptConfig_Deprecated("hibernate"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckSpotInstanceRequestExists(resourceName, &sir1),
resource.TestCheckResourceAttr(resourceName, "instance_interruption_behavior", "hibernate"),
resource.TestCheckResourceAttr(resourceName, "instance_interruption_behaviour", "hibernate"),
),
},
{
Config: testAccSpotInstanceRequestInterruptConfig("stop"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckSpotInstanceRequestExists(resourceName, &sir2),
testAccCheckSpotInstanceRequestRecreated(&sir1, &sir2),
resource.TestCheckResourceAttr(resourceName, "instance_interruption_behavior", "stop"),
resource.TestCheckResourceAttr(resourceName, "instance_interruption_behaviour", "stop"),
),
},
},
Expand Down Expand Up @@ -1079,18 +982,3 @@ resource "aws_spot_instance_request" "test" {
}
`, interruptionBehavior))
}

func testAccSpotInstanceRequestInterruptConfig_Deprecated(interruptionBehavior string) string {
return acctest.ConfigCompose(
acctest.ConfigLatestAmazonLinuxHvmEbsAmi(),
acctest.AvailableEC2InstanceTypeForRegion("c5.large", "c4.large"),
fmt.Sprintf(`
resource "aws_spot_instance_request" "test" {
ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id
instance_type = data.aws_ec2_instance_type_offering.available.instance_type
spot_price = "0.07"
wait_for_fulfillment = true
instance_interruption_behaviour = %[1]q
}
`, interruptionBehavior))
}
1 change: 0 additions & 1 deletion website/docs/r/spot_instance_request.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ Spot Instance Requests support all the same arguments as
The duration period starts as soon as your Spot instance receives its instance ID. At the end of the duration period, 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.
Note that you can't specify an Availability Zone group or a launch group if you specify a duration.
* `instance_interruption_behavior` - (Optional) Indicates Spot instance behavior when it is interrupted. Valid values are `terminate`, `stop`, or `hibernate`. Default value is `terminate`.
* `instance_interruption_behaviour` - (Optional, **Deprecated**) Indicates Spot instance behavior when it is interrupted. Valid values are `terminate`, `stop`, or `hibernate`. Default value is `terminate`. Use the argument `instance_interruption_behavior` instead.
* `valid_until` - (Optional) The end date and time of the request, in UTC [RFC3339](https://tools.ietf.org/html/rfc3339#section-5.8) format(for example, YYYY-MM-DDTHH:MM:SSZ). At this point, no new Spot instance requests are placed or enabled to fulfill the request. The default end date is 7 days from the current date.
* `valid_from` - (Optional) The start date and time of the request, in UTC [RFC3339](https://tools.ietf.org/html/rfc3339#section-5.8) format(for example, YYYY-MM-DDTHH:MM:SSZ). The default is to start fulfilling the request immediately.
* `tags` - (Optional) A map of tags to assign to the Spot Instance Request. These tags are not automatically applied to the launched Instance. If configured with a provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.
Expand Down

0 comments on commit 9389ed3

Please sign in to comment.