Skip to content
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

Replace 'testAccPreCheckOffersEc2InstanceType' with 'aws_ec2_instance_type_offering' data source #13076

Merged
merged 1 commit into from
Apr 29, 2020

Conversation

ewbankkit
Copy link
Contributor

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Following up from this comment:

Now that there is the aws_ec2_instance_type_offering data source, we can use that to selectively pick out of a list of preferred instance types.

Remove testAccPreCheckOffersEc2InstanceType and use the aws_ec2_instance_type_offering data source to select an EC2 instance type.

Relates #12491.

Release note for CHANGELOG:

NONE

Output from acceptance testing:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSInstanceDataSource_metadataOptions'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSInstanceDataSource_metadataOptions -timeout 120m
=== RUN   TestAccAWSInstanceDataSource_metadataOptions
=== PAUSE TestAccAWSInstanceDataSource_metadataOptions
=== CONT  TestAccAWSInstanceDataSource_metadataOptions
--- PASS: TestAccAWSInstanceDataSource_metadataOptions (130.99s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	131.023s
$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSInstance_metadataOptions'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSInstance_metadataOptions -timeout 120m
=== RUN   TestAccAWSInstance_metadataOptions
=== PAUSE TestAccAWSInstance_metadataOptions
=== CONT  TestAccAWSInstance_metadataOptions
--- PASS: TestAccAWSInstance_metadataOptions (113.99s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	114.045s

@ewbankkit ewbankkit requested a review from a team April 28, 2020 22:36
@ghost ghost added needs-triage Waiting for first response or review from a maintainer. size/M Managed by automation to categorize the size of a PR. service/ec2 Issues and PRs that pertain to the ec2 service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Apr 28, 2020
@bflad bflad added technical-debt Addresses areas of the codebase that need refactoring or redesign. and removed needs-triage Waiting for first response or review from a maintainer. labels Apr 29, 2020
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do it! 🚀 We can consider adding an AvailabilityZone equivalent, maybe something that takes it in as an argument that can take in a reference, e.g.

// testAccAvailableEc2InstanceTypeForAvailabilityZone returns the configuration for a data source that describes
// the first available EC2 instance type offering in the current availability zone from a list of preferred instance types.
// The first argument is either an Availability Zone name or Terraform configuration reference to one, e.g.
//   * data.aws_availability_zones.available.names[0]
//   * aws_subnet.test.availability_zone
//   * us-west-2a
// The data source is named 'available'.
func testAccAvailableEc2InstanceTypeForAvailabilityZone(availabilityZoneName string, preferredInstanceTypes ...string) string {
	if !string.Contains(availabilityZoneName, ".") {
		availabilityZoneName = strconv.Quote(availabilityZoneName)
	}

	return fmt.Sprintf(`
data "aws_ec2_instance_type_offering" "available" {
  filter {
    name   = "instance-type"
    values = ["%[2]v"]
  }

  filter {
    name   = "location"
    values = [%[1]s]
  }

  location_type            = "availability-zone"
  preferred_instance_types = ["%[2]v"]
}
`, availabilityZoneName, strings.Join(preferredInstanceTypes, "\", \""))
}

And possibly moving these to their own file for now (until we come up with a good shared package structure).

Output from acceptance testing:

--- PASS: TestAccAWSInstance_metadataOptions (62.08s)
--- PASS: TestAccAWSInstanceDataSource_metadataOptions (316.81s)

@bflad bflad added this to the v2.60.0 milestone Apr 29, 2020
@bflad bflad merged commit ab9d803 into hashicorp:master Apr 29, 2020
@bflad
Copy link
Contributor

bflad commented Apr 29, 2020

Followup tracking issue: #13083

@ewbankkit ewbankkit deleted the preferred-instance-generator branch April 29, 2020 11:37
@ghost
Copy link

ghost commented May 1, 2020

This has been released in version 2.60.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

adamdecaf pushed a commit to adamdecaf/terraform-provider-aws that referenced this pull request May 28, 2020
…_type_offering' data source. (hashicorp#13076)

Output from acceptance testing:

```
--- PASS: TestAccAWSInstance_metadataOptions (62.08s)
--- PASS: TestAccAWSInstanceDataSource_metadataOptions (316.81s)
```
@ghost
Copy link

ghost commented May 29, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators May 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/ec2 Issues and PRs that pertain to the ec2 service. size/M Managed by automation to categorize the size of a PR. technical-debt Addresses areas of the codebase that need refactoring or redesign. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants