-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
credit_specification issues in aws_instance (T3) #5805
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1602,6 +1602,99 @@ func TestAccAWSInstance_creditSpecification_isNotAppliedToNonBurstable(t *testin | |
}) | ||
} | ||
|
||
func TestAccAWSInstance_creditSpecificationT3_unspecifiedDefaultsToUnlimited(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you so much for adding all the tests! 💯 |
||
var instance ec2.Instance | ||
resName := "aws_instance.foo" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckInstanceDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccInstanceConfig_creditSpecification_unspecified_t3(acctest.RandInt()), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckInstanceExists(resName, &instance), | ||
resource.TestCheckResourceAttr(resName, "credit_specification.#", "1"), | ||
resource.TestCheckResourceAttr(resName, "credit_specification.0.cpu_credits", "unlimited"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAWSInstance_creditSpecificationT3_standardCpuCredits(t *testing.T) { | ||
var instance ec2.Instance | ||
resName := "aws_instance.foo" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckInstanceDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccInstanceConfig_creditSpecification_standardCpuCredits_t3(acctest.RandInt()), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckInstanceExists(resName, &instance), | ||
resource.TestCheckResourceAttr(resName, "credit_specification.#", "1"), | ||
resource.TestCheckResourceAttr(resName, "credit_specification.0.cpu_credits", "standard"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAWSInstance_creditSpecificationT3_unlimitedCpuCredits(t *testing.T) { | ||
var instance ec2.Instance | ||
resName := "aws_instance.foo" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckInstanceDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccInstanceConfig_creditSpecification_unlimitedCpuCredits_t3(acctest.RandInt()), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckInstanceExists(resName, &instance), | ||
resource.TestCheckResourceAttr(resName, "credit_specification.#", "1"), | ||
resource.TestCheckResourceAttr(resName, "credit_specification.0.cpu_credits", "unlimited"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAWSInstance_creditSpecificationT3_updateCpuCredits(t *testing.T) { | ||
var before ec2.Instance | ||
var after ec2.Instance | ||
resName := "aws_instance.foo" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckInstanceDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccInstanceConfig_creditSpecification_standardCpuCredits_t3(acctest.RandInt()), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckInstanceExists(resName, &before), | ||
resource.TestCheckResourceAttr(resName, "credit_specification.#", "1"), | ||
resource.TestCheckResourceAttr(resName, "credit_specification.0.cpu_credits", "standard"), | ||
), | ||
}, | ||
{ | ||
Config: testAccInstanceConfig_creditSpecification_unlimitedCpuCredits_t3(acctest.RandInt()), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckInstanceExists(resName, &after), | ||
resource.TestCheckResourceAttr(resName, "credit_specification.#", "1"), | ||
resource.TestCheckResourceAttr(resName, "credit_specification.0.cpu_credits", "unlimited"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAWSInstance_UserData_EmptyStringToUnspecified(t *testing.T) { | ||
var instance ec2.Instance | ||
rInt := acctest.RandInt() | ||
|
@@ -3283,6 +3376,29 @@ resource "aws_instance" "foo" { | |
`, rInt) | ||
} | ||
|
||
func testAccInstanceConfig_creditSpecification_unspecified_t3(rInt int) string { | ||
return fmt.Sprintf(` | ||
resource "aws_vpc" "my_vpc" { | ||
cidr_block = "172.16.0.0/16" | ||
tags { | ||
Name = "tf-acctest-%d" | ||
} | ||
} | ||
|
||
resource "aws_subnet" "my_subnet" { | ||
vpc_id = "${aws_vpc.my_vpc.id}" | ||
cidr_block = "172.16.20.0/24" | ||
availability_zone = "us-west-2a" | ||
} | ||
|
||
resource "aws_instance" "foo" { | ||
ami = "ami-51537029" # us-west-2 | ||
instance_type = "t3.micro" | ||
subnet_id = "${aws_subnet.my_subnet.id}" | ||
} | ||
`, rInt) | ||
} | ||
|
||
func testAccInstanceConfig_creditSpecification_standardCpuCredits(rInt int) string { | ||
return fmt.Sprintf(` | ||
resource "aws_vpc" "my_vpc" { | ||
|
@@ -3309,6 +3425,32 @@ resource "aws_instance" "foo" { | |
`, rInt) | ||
} | ||
|
||
func testAccInstanceConfig_creditSpecification_standardCpuCredits_t3(rInt int) string { | ||
return fmt.Sprintf(` | ||
resource "aws_vpc" "my_vpc" { | ||
cidr_block = "172.16.0.0/16" | ||
tags { | ||
Name = "tf-acctest-%d" | ||
} | ||
} | ||
|
||
resource "aws_subnet" "my_subnet" { | ||
vpc_id = "${aws_vpc.my_vpc.id}" | ||
cidr_block = "172.16.20.0/24" | ||
availability_zone = "us-west-2a" | ||
} | ||
|
||
resource "aws_instance" "foo" { | ||
ami = "ami-51537029" # us-west-2 | ||
instance_type = "t3.micro" | ||
subnet_id = "${aws_subnet.my_subnet.id}" | ||
credit_specification { | ||
cpu_credits = "standard" | ||
} | ||
} | ||
`, rInt) | ||
} | ||
|
||
func testAccInstanceConfig_creditSpecification_unlimitedCpuCredits(rInt int) string { | ||
return fmt.Sprintf(` | ||
resource "aws_vpc" "my_vpc" { | ||
|
@@ -3335,6 +3477,32 @@ resource "aws_instance" "foo" { | |
`, rInt) | ||
} | ||
|
||
func testAccInstanceConfig_creditSpecification_unlimitedCpuCredits_t3(rInt int) string { | ||
return fmt.Sprintf(` | ||
resource "aws_vpc" "my_vpc" { | ||
cidr_block = "172.16.0.0/16" | ||
tags { | ||
Name = "tf-acctest-%d" | ||
} | ||
} | ||
|
||
resource "aws_subnet" "my_subnet" { | ||
vpc_id = "${aws_vpc.my_vpc.id}" | ||
cidr_block = "172.16.20.0/24" | ||
availability_zone = "us-west-2a" | ||
} | ||
|
||
resource "aws_instance" "foo" { | ||
ami = "ami-51537029" # us-west-2 | ||
instance_type = "t3.micro" | ||
subnet_id = "${aws_subnet.my_subnet.id}" | ||
credit_specification { | ||
cpu_credits = "unlimited" | ||
} | ||
} | ||
`, rInt) | ||
} | ||
|
||
func testAccInstanceConfig_creditSpecification_isNotAppliedToNonBurstable(rInt int) string { | ||
return fmt.Sprintf(` | ||
resource "aws_vpc" "my_vpc" { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suppressing the
unlimited
tostandard
difference has the unfortunate side effect of preventing a successful update fromunlimited
tostandard
for T3 instance types, which is a valid change. I was able to tease this out by adding a newTestStep
toTestAccAWSInstance_creditSpecificationT3_updateCpuCredits
:And its failure during run:
To encourage the correct behavior for this attribute, we needed to remove the
Default: "standard"
(since there is no singular default value for the attribute now) and have theDiffSuppressFunc
only concern itself with scenarios wherenew
is empty (e.g. it is not in the Terraform configuration):This does however cause a change in behavior of the resource with regards to removing the
credit_specification
configuration for existing instances. Previously, we were "resetting" the credits back tostandard
for T2 instance types when the configuration was removed. The new behavior is leaving the credits as-is when removing the configuration since the Update function no longer sees the difference. I added a note in the documentation, but given how its more important that we support T3 overall versus that odd scenario (debatable whether we should actually support it), I'm opting to change this until we can potentially revisit in the future.