-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
resource/aws_instance: Add check for empty credit_specification block #9003
Merged
Merged
Changes from all commits
Commits
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 |
---|---|---|
|
@@ -1693,6 +1693,50 @@ func TestAccAWSInstance_creditSpecification_unlimitedCpuCredits(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccAWSInstance_creditSpecification_unknownCpuCredits_t2(t *testing.T) { | ||
var instance ec2.Instance | ||
rInt := acctest.RandInt() | ||
resName := "aws_instance.foo" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckInstanceDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccInstanceConfig_creditSpecification_unknownCpuCredits(rInt, "t2.micro"), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckInstanceExists(resName, &instance), | ||
resource.TestCheckResourceAttr(resName, "credit_specification.#", "1"), | ||
resource.TestCheckResourceAttr(resName, "credit_specification.0.cpu_credits", "standard"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAWSInstance_creditSpecification_unknownCpuCredits_t3(t *testing.T) { | ||
var instance ec2.Instance | ||
rInt := acctest.RandInt() | ||
resName := "aws_instance.foo" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckInstanceDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccInstanceConfig_creditSpecification_unknownCpuCredits(rInt, "t3.micro"), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckInstanceExists(resName, &instance), | ||
resource.TestCheckResourceAttr(resName, "credit_specification.#", "1"), | ||
resource.TestCheckResourceAttr(resName, "credit_specification.0.cpu_credits", "unlimited"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAWSInstance_creditSpecification_updateCpuCredits(t *testing.T) { | ||
var first, second, third ec2.Instance | ||
resName := "aws_instance.foo" | ||
|
@@ -3827,6 +3871,7 @@ resource "aws_instance" "foo" { | |
ami = "ami-51537029" # us-west-2 | ||
instance_type = "t3.micro" | ||
subnet_id = "${aws_subnet.my_subnet.id}" | ||
|
||
} | ||
`, rInt) | ||
} | ||
|
@@ -3971,6 +4016,33 @@ resource "aws_instance" "foo" { | |
`, rInt) | ||
} | ||
|
||
func testAccInstanceConfig_creditSpecification_unknownCpuCredits(rInt int, instanceType string) 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 | ||
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. Same note and references here about being AWS region agnostic. We can handle AMI lookup via the data "aws_ami" "amzn-ami-minimal-hvm-ebs" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["amzn-ami-minimal-hvm-*"]
}
filter {
name = "root-device-type"
values = ["ebs"]
}
}
resource "aws_instance" "foo" {
ami = "${data.aws_ami.amzn-ami-minimal-hvm-ebs.id}" |
||
instance_type = %q | ||
subnet_id = "${aws_subnet.my_subnet.id}" | ||
|
||
credit_specification { | ||
} | ||
} | ||
`, rInt, instanceType) | ||
} | ||
|
||
func testAccInstanceConfig_UserData_Base(rInt int) string { | ||
return fmt.Sprintf(` | ||
data "aws_ami" "amzn-ami-minimal-hvm-ebs" { | ||
|
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.
Our acceptance testing should prefer to remain AWS region and availability zone agnostic so it can be used against multiple AWS partitions or otherwise be redirected for region/AZ outages. See also: #4987 and this section under https://github.com/terraform-providers/terraform-provider-aws/blob/master/.github/CONTRIBUTING.md#acceptance-testing-guidelines
In this case, we can either allow EC2 to automatically select the subnet availability zone by omitting the argument or use the
aws_availability_zones
data source to select one in the available state, e.g.