diff --git a/.changelog/34030.txt b/.changelog/34030.txt new file mode 100644 index 00000000000..4878166d626 --- /dev/null +++ b/.changelog/34030.txt @@ -0,0 +1,3 @@ +```release-note:new-data-source +aws_ec2_instance_types_from_instance_requirements +``` \ No newline at end of file diff --git a/internal/service/ec2/instance_types_from_instance_requirements_data_source.go b/internal/service/ec2/instance_types_from_instance_requirements_data_source.go new file mode 100644 index 00000000000..eadee80e1d6 --- /dev/null +++ b/internal/service/ec2/instance_types_from_instance_requirements_data_source.go @@ -0,0 +1,363 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package ec2 + +import ( + "context" + + "github.com/aws/aws-sdk-go-v2/service/ec2" + awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types" + "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/enum" + "github.com/hashicorp/terraform-provider-aws/internal/framework" + "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" + fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" + "github.com/hashicorp/terraform-provider-aws/names" +) + +// @FrameworkDataSource(name="Instance Types From Instance Requirements") +func newDataSourceInstanceTypesFromInstanceRequirements(context.Context) (datasource.DataSourceWithConfigure, error) { + return &dataSourceInstanceTypesFromInstanceRequirements{}, nil +} + +const ( + DSNameInstanceTypesFromInstanceRequirements = "Instance Types From Instance Requirements Data Source" +) + +type dataSourceInstanceTypesFromInstanceRequirements struct { + framework.DataSourceWithConfigure +} + +func (d *dataSourceInstanceTypesFromInstanceRequirements) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name + resp.TypeName = "aws_ec2_instance_types_from_instance_requirements" +} + +func (d *dataSourceInstanceTypesFromInstanceRequirements) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "architecture_types": schema.ListAttribute{ + CustomType: fwtypes.ListOfStringType, + ElementType: types.StringType, + Required: true, + Validators: []validator.List{ + listvalidator.ValueStringsAre( + enum.FrameworkValidate[awstypes.ArchitectureType](), + ), + }, + }, + "id": framework.IDAttribute(), + "instance_types": schema.ListAttribute{ + ElementType: types.StringType, + Computed: true, + }, + "virtualization_types": schema.ListAttribute{ + CustomType: fwtypes.ListOfStringType, + ElementType: types.StringType, + Required: true, + Validators: []validator.List{ + listvalidator.ValueStringsAre( + enum.FrameworkValidate[awstypes.VirtualizationType](), + ), + }, + }, + }, + Blocks: map[string]schema.Block{ + "instance_requirements": schema.SingleNestedBlock{ + CustomType: fwtypes.NewObjectTypeOf[instanceRequirementsData](ctx), + Attributes: map[string]schema.Attribute{ + "accelerator_manufacturers": schema.ListAttribute{ + CustomType: fwtypes.ListOfStringType, + ElementType: types.StringType, + Optional: true, + Validators: []validator.List{ + listvalidator.ValueStringsAre( + enum.FrameworkValidate[awstypes.AcceleratorManufacturer](), + ), + }, + }, + "accelerator_names": schema.ListAttribute{ + CustomType: fwtypes.ListOfStringType, + ElementType: types.StringType, + Optional: true, + Validators: []validator.List{ + listvalidator.ValueStringsAre( + enum.FrameworkValidate[awstypes.AcceleratorName](), + ), + }, + }, + "accelerator_types": schema.ListAttribute{ + CustomType: fwtypes.ListOfStringType, + ElementType: types.StringType, + Optional: true, + Validators: []validator.List{ + listvalidator.ValueStringsAre( + enum.FrameworkValidate[awstypes.AcceleratorType](), + ), + }, + }, + "allowed_instance_types": schema.ListAttribute{ + CustomType: fwtypes.ListOfStringType, + ElementType: types.StringType, + Optional: true, + }, + "bare_metal": schema.StringAttribute{ + Optional: true, + Validators: []validator.String{ + enum.FrameworkValidate[awstypes.BareMetal](), + }, + }, + "burstable_performance": schema.StringAttribute{ + Optional: true, + Validators: []validator.String{ + enum.FrameworkValidate[awstypes.BurstablePerformance](), + }, + }, + "cpu_manufacturers": schema.ListAttribute{ + CustomType: fwtypes.ListOfStringType, + ElementType: types.StringType, + Optional: true, + Validators: []validator.List{ + listvalidator.ValueStringsAre( + enum.FrameworkValidate[awstypes.CpuManufacturer](), + ), + }, + }, + "excluded_instance_types": schema.ListAttribute{ + CustomType: fwtypes.ListOfStringType, + ElementType: types.StringType, + Optional: true, + }, + "instance_generations": schema.ListAttribute{ + CustomType: fwtypes.ListOfStringType, + ElementType: types.StringType, + Optional: true, + Validators: []validator.List{ + listvalidator.ValueStringsAre( + enum.FrameworkValidate[awstypes.InstanceGeneration](), + ), + }, + }, + "local_storage": schema.StringAttribute{ + Optional: true, + Validators: []validator.String{ + enum.FrameworkValidate[awstypes.LocalStorage](), + }, + }, + "local_storage_types": schema.ListAttribute{ + CustomType: fwtypes.ListOfStringType, + ElementType: types.StringType, + Optional: true, + Validators: []validator.List{ + listvalidator.ValueStringsAre( + enum.FrameworkValidate[awstypes.LocalStorageType](), + ), + }, + }, + "on_demand_max_price_percentage_over_lowest_price": schema.Int64Attribute{ + Optional: true, + }, + "require_hibernate_support": schema.BoolAttribute{ + Optional: true, + }, + "spot_max_price_percentage_over_lowest_price": schema.Int64Attribute{ + Optional: true, + }, + }, + Blocks: map[string]schema.Block{ + "memory_mib": schema.SingleNestedBlock{ + CustomType: fwtypes.NewObjectTypeOf[minMax[types.Int64]](ctx), + Attributes: map[string]schema.Attribute{ + "min": schema.Int64Attribute{ + Required: true, + }, + "max": schema.Int64Attribute{ + Optional: true, + }, + }, + }, + "vcpu_count": schema.SingleNestedBlock{ + CustomType: fwtypes.NewObjectTypeOf[minMax[types.Int64]](ctx), + Attributes: map[string]schema.Attribute{ + "min": schema.Int64Attribute{ + Required: true, + }, + "max": schema.Int64Attribute{ + Optional: true, + }, + }, + }, + "accelerator_count": schema.SingleNestedBlock{ + CustomType: fwtypes.NewObjectTypeOf[minMax[types.Int64]](ctx), + Attributes: map[string]schema.Attribute{ + "min": schema.Int64Attribute{ + Optional: true, + }, + "max": schema.Int64Attribute{ + Optional: true, + }, + }, + }, + "accelerator_total_memory_mib": schema.SingleNestedBlock{ + CustomType: fwtypes.NewObjectTypeOf[minMax[types.Int64]](ctx), + Attributes: map[string]schema.Attribute{ + "min": schema.Int64Attribute{ + Optional: true, + }, + "max": schema.Int64Attribute{ + Optional: true, + }, + }, + }, + "baseline_ebs_bandwidth_mbps": schema.SingleNestedBlock{ + CustomType: fwtypes.NewObjectTypeOf[minMax[types.Float64]](ctx), + Attributes: map[string]schema.Attribute{ + "min": schema.Int64Attribute{ + Optional: true, + }, + "max": schema.Int64Attribute{ + Optional: true, + }, + }, + }, + "memory_gib_per_vcpu": schema.SingleNestedBlock{ + CustomType: fwtypes.NewObjectTypeOf[minMax[types.Float64]](ctx), + Attributes: map[string]schema.Attribute{ + "min": schema.Float64Attribute{ + Optional: true, + }, + "max": schema.Float64Attribute{ + Optional: true, + }, + }, + }, + "network_bandwidth_gbps": schema.SingleNestedBlock{ + CustomType: fwtypes.NewObjectTypeOf[minMax[types.Float64]](ctx), + Attributes: map[string]schema.Attribute{ + "min": schema.Float64Attribute{ + Optional: true, + }, + "max": schema.Float64Attribute{ + Optional: true, + }, + }, + }, + "network_interface_count": schema.SingleNestedBlock{ + CustomType: fwtypes.NewObjectTypeOf[minMax[types.Int64]](ctx), + Attributes: map[string]schema.Attribute{ + "min": schema.Int64Attribute{ + Optional: true, + }, + "max": schema.Int64Attribute{ + Optional: true, + }, + }, + }, + "total_local_storage_gb": schema.SingleNestedBlock{ + CustomType: fwtypes.NewObjectTypeOf[minMax[types.Float64]](ctx), + Attributes: map[string]schema.Attribute{ + "min": schema.Float64Attribute{ + Optional: true, + }, + "max": schema.Float64Attribute{ + Optional: true, + }, + }, + }, + }, + }, + }, + } +} + +func (d *dataSourceInstanceTypesFromInstanceRequirements) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + conn := d.Meta().EC2Client(ctx) + + var data dataSourceInstanceTypesFromInstanceRequirementsData + resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) + if resp.Diagnostics.HasError() { + return + } + + input := &ec2.GetInstanceTypesFromInstanceRequirementsInput{} + resp.Diagnostics.Append(flex.Expand(ctx, data, input)...) + if resp.Diagnostics.HasError() { + return + } + + out, err := findInstanceTypesFromInstanceRequirements(ctx, conn, input) + if err != nil { + resp.Diagnostics.AddError( + create.ProblemStandardMessage(names.EC2, create.ErrActionReading, DSNameInstanceTypesFromInstanceRequirements, d.Meta().Region, err), + err.Error(), + ) + return + } + + data.ID = types.StringValue(d.Meta().Region) + data.InstanceTypes = flex.FlattenFrameworkStringList(ctx, out) + + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +func findInstanceTypesFromInstanceRequirements(ctx context.Context, conn *ec2.Client, input *ec2.GetInstanceTypesFromInstanceRequirementsInput) ([]*string, error) { + var output []*string + + paginator := ec2.NewGetInstanceTypesFromInstanceRequirementsPaginator(conn, input) + + for paginator.HasMorePages() { + page, err := paginator.NextPage(ctx) + if err != nil { + return nil, err + } + for _, v := range page.InstanceTypes { + output = append(output, v.InstanceType) + } + } + + return output, nil +} + +type dataSourceInstanceTypesFromInstanceRequirementsData struct { + ArchitectureTypes fwtypes.ListValueOf[types.String] `tfsdk:"architecture_types"` + InstanceRequirements fwtypes.ObjectValueOf[instanceRequirementsData] `tfsdk:"instance_requirements"` + InstanceTypes types.List `tfsdk:"instance_types"` + ID types.String `tfsdk:"id"` + VirtualizationTypes fwtypes.ListValueOf[types.String] `tfsdk:"virtualization_types"` +} + +type instanceRequirementsData struct { + MemoryMiB fwtypes.ObjectValueOf[minMax[types.Int64]] `tfsdk:"memory_mib"` + VCPUCount fwtypes.ObjectValueOf[minMax[types.Int64]] `tfsdk:"vcpu_count"` + AcceleratorCount fwtypes.ObjectValueOf[minMax[types.Int64]] `tfsdk:"accelerator_count"` + AcceleratorManufacturers fwtypes.ListValueOf[types.String] `tfsdk:"accelerator_manufacturers"` + AcceleratorNames fwtypes.ListValueOf[types.String] `tfsdk:"accelerator_names"` + AcceleratorTotalMemoryMiB fwtypes.ObjectValueOf[minMax[types.Int64]] `tfsdk:"accelerator_total_memory_mib"` + AcceleratorTypes fwtypes.ListValueOf[types.String] `tfsdk:"accelerator_types"` + AllowedInstanceTypes fwtypes.ListValueOf[types.String] `tfsdk:"allowed_instance_types"` + BareMetal types.String `tfsdk:"bare_metal"` + BaselineEBSBandwidthMbps fwtypes.ObjectValueOf[minMax[types.Float64]] `tfsdk:"baseline_ebs_bandwidth_mbps"` + BurstablePerformance types.String `tfsdk:"burstable_performance"` + CPUManufacturers fwtypes.ListValueOf[types.String] `tfsdk:"cpu_manufacturers"` + ExcludedInstanceTypes fwtypes.ListValueOf[types.String] `tfsdk:"excluded_instance_types"` + InstanceGenerations fwtypes.ListValueOf[types.String] `tfsdk:"instance_generations"` + LocalStorage types.String `tfsdk:"local_storage"` + LocalStorageTypes fwtypes.ListValueOf[types.String] `tfsdk:"local_storage_types"` + MemoryGiBPerVCPU fwtypes.ObjectValueOf[minMax[types.Float64]] `tfsdk:"memory_gib_per_vcpu"` + NetworkBandwidthGbps fwtypes.ObjectValueOf[minMax[types.Float64]] `tfsdk:"network_bandwidth_gbps"` + NetworkInterfaceCount fwtypes.ObjectValueOf[minMax[types.Int64]] `tfsdk:"network_interface_count"` + OnDemandMaxPricePercentageOverLowestPrice types.Int64 `tfsdk:"on_demand_max_price_percentage_over_lowest_price"` + RequireHibernateSupport types.Bool `tfsdk:"require_hibernate_support"` + SpotMaxPricePercentageOverLowestPrice types.Int64 `tfsdk:"spot_max_price_percentage_over_lowest_price"` + TotalLocalStorageGB fwtypes.ObjectValueOf[minMax[types.Float64]] `tfsdk:"total_local_storage_gb"` +} + +type minMax[T comparable] struct { + Min T `tfsdk:"min"` + Max T `tfsdk:"max"` +} diff --git a/internal/service/ec2/instance_types_from_instance_requirements_data_source_test.go b/internal/service/ec2/instance_types_from_instance_requirements_data_source_test.go new file mode 100644 index 00000000000..f9769c80674 --- /dev/null +++ b/internal/service/ec2/instance_types_from_instance_requirements_data_source_test.go @@ -0,0 +1,1103 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package ec2_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/names" +) + +func TestAccEC2InstanceTypesFromInstanceRequirementsDataSource_memoryMiBAndVcpuCount(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_ec2_instance_types_from_instance_requirements.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.EC2EndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `memory_mib { + min = 1000 + max = 10000 + } + vcpu_count { + min = 2 + max = 12 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + }, + }) +} + +func TestAccEC2InstanceTypesFromInstanceRequirementsDataSource_acceleratorCount(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_ec2_instance_types_from_instance_requirements.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.EC2EndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `accelerator_count { + min = 2 + } + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `accelerator_count { + min = 1 + max = 3 + } + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `accelerator_count { + max = 0 + } + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + }, + }) +} + +func TestAccEC2InstanceTypesFromInstanceRequirementsDataSource_acceleratorManufacturers(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_ec2_instance_types_from_instance_requirements.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.EC2EndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `accelerator_manufacturers = ["amazon-web-services"] + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `accelerator_manufacturers = ["amazon-web-services", "amd", "nvidia", "xilinx"] + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + }, + }) +} + +func TestAccEC2InstanceTypesFromInstanceRequirementsDataSource_acceleratorNames(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_ec2_instance_types_from_instance_requirements.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.EC2EndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `accelerator_names = ["a100"] + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `accelerator_names = ["a100", "v100", "k80", "t4", "m60", "radeon-pro-v520", "vu9p"] + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + }, + }) +} + +func TestAccEC2InstanceTypesFromInstanceRequirementsDataSource_acceleratorTotalMemoryMiB(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_ec2_instance_types_from_instance_requirements.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.EC2EndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `accelerator_total_memory_mib { + min = 32 + } + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `accelerator_total_memory_mib { + max = 12000 + } + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `accelerator_total_memory_mib { + min = 32 + max = 12000 + } + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + }, + }) +} + +func TestAccEC2InstanceTypesFromInstanceRequirementsDataSource_acceleratorTypes(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_ec2_instance_types_from_instance_requirements.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.EC2EndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `accelerator_types = ["fpga"] + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `accelerator_types = ["fpga", "gpu", "inference"] + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + }, + }) +} + +func TestAccEC2InstanceTypesFromInstanceRequirementsDataSource_allowedInstanceTypes(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_ec2_instance_types_from_instance_requirements.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.EC2EndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `allowed_instance_types = ["m4.large"] + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `allowed_instance_types = ["m4.large", "m5.*", "m6*"] + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + }, + }) +} + +func TestAccEC2InstanceTypesFromInstanceRequirementsDataSource_bareMetal(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_ec2_instance_types_from_instance_requirements.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.EC2EndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `bare_metal = "excluded" + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `bare_metal = "included" + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `bare_metal = "required" + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + }, + }) +} + +func TestAccEC2InstanceTypesFromInstanceRequirementsDataSource_baselineEBSBandwidthMbps(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_ec2_instance_types_from_instance_requirements.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.EC2EndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `baseline_ebs_bandwidth_mbps { + min = 10 + } + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `baseline_ebs_bandwidth_mbps { + max = 20000 + } + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `baseline_ebs_bandwidth_mbps { + min = 10 + max = 20000 + } + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + }, + }) +} + +func TestAccEC2InstanceTypesFromInstanceRequirementsDataSource_burstablePerformance(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_ec2_instance_types_from_instance_requirements.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.EC2EndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `burstable_performance = "excluded" + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `burstable_performance = "included" + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `burstable_performance = "required" + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + }, + }) +} + +func TestAccEC2InstanceTypesFromInstanceRequirementsDataSource_cpuManufacturers(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_ec2_instance_types_from_instance_requirements.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.EC2EndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `cpu_manufacturers = ["amazon-web-services"] + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `cpu_manufacturers = ["amazon-web-services", "amd", "intel"] + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + }, + }) +} + +func TestAccEC2InstanceTypesFromInstanceRequirementsDataSource_excludedInstanceTypes(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_ec2_instance_types_from_instance_requirements.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.EC2EndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `excluded_instance_types = ["t2.nano"] + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `excluded_instance_types = ["t2.nano", "t3*", "t4g.*"] + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + }, + }) +} + +func TestAccEC2InstanceTypesFromInstanceRequirementsDataSource_instanceGenerations(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_ec2_instance_types_from_instance_requirements.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.EC2EndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `instance_generations = ["current"] + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `instance_generations = ["current", "previous"] + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + }, + }) +} + +func TestAccEC2InstanceTypesFromInstanceRequirementsDataSource_localStorage(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_ec2_instance_types_from_instance_requirements.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.EC2EndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `local_storage = "excluded" + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `local_storage = "included" + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `local_storage = "required" + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + }, + }) +} + +func TestAccEC2InstanceTypesFromInstanceRequirementsDataSource_localStorageTypes(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_ec2_instance_types_from_instance_requirements.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.EC2EndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `local_storage_types = ["hdd"] + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `local_storage_types = ["hdd", "ssd"] + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + }, + }) +} + +func TestAccEC2InstanceTypesFromInstanceRequirementsDataSource_memoryGiBPerVCPU(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_ec2_instance_types_from_instance_requirements.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.EC2EndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `memory_gib_per_vcpu { + min = 0.5 + } + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `memory_gib_per_vcpu { + max = 9.5 + } + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `memory_gib_per_vcpu { + min = 0.5 + max = 9.5 + } + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + }, + }) +} + +func TestAccEC2InstanceTypesFromInstanceRequirementsDataSource_networkBandwidthGbps(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_ec2_instance_types_from_instance_requirements.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.EC2EndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `network_bandwidth_gbps { + min = 1.5 + } + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `network_bandwidth_gbps { + max = 200 + } + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `network_bandwidth_gbps { + min = 2.5 + max = 250 + } + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + }, + }) +} + +func TestAccEC2InstanceTypesFromInstanceRequirementsDataSource_networkInterfaceCount(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_ec2_instance_types_from_instance_requirements.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.EC2EndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `network_interface_count { + min = 1 + } + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `network_interface_count { + max = 10 + } + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `network_interface_count { + min = 1 + max = 10 + } + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + }, + }) +} + +func TestAccEC2InstanceTypesFromInstanceRequirementsDataSource_onDemandMaxPricePercentageOverLowestPrice(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_ec2_instance_types_from_instance_requirements.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.EC2EndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `on_demand_max_price_percentage_over_lowest_price = 50 + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + }, + }) +} + +func TestAccEC2InstanceTypesFromInstanceRequirementsDataSource_requireHibernateSupport(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_ec2_instance_types_from_instance_requirements.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.EC2EndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `require_hibernate_support = false + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `require_hibernate_support = true + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + }, + }) +} + +func TestAccEC2InstanceTypesFromInstanceRequirementsDataSource_spotMaxPricePercentageOverLowestPrice(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_ec2_instance_types_from_instance_requirements.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.EC2EndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `spot_max_price_percentage_over_lowest_price = 75 + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + }, + }) +} + +func TestAccEC2InstanceTypesFromInstanceRequirementsDataSource_totalLocalStorageGB(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_ec2_instance_types_from_instance_requirements.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.EC2EndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `total_local_storage_gb { + min = 0.5 + } + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `total_local_storage_gb { + max = 20.5 + } + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + { + Config: testAccInstanceTypesFromInstanceRequirementsDataSourceConfig( + `total_local_storage_gb { + min = 0.5 + max = 20.5 + } + memory_mib { + min = 500 + } + vcpu_count { + min = 1 + }`), + Check: resource.ComposeTestCheckFunc( + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "instance_types.#", 0), + ), + }, + }, + }) +} + +func testAccInstanceTypesFromInstanceRequirementsDataSourceConfig(instanceRequirements string) string { + return fmt.Sprintf(` +data "aws_ec2_instance_types_from_instance_requirements" "test" { + architecture_types = ["x86_64"] + virtualization_types = ["hvm"] + + instance_requirements { + %[1]s + } +} +`, instanceRequirements) +} diff --git a/internal/service/ec2/service_package_gen.go b/internal/service/ec2/service_package_gen.go index 49cbedd80e1..d6b363edea7 100644 --- a/internal/service/ec2/service_package_gen.go +++ b/internal/service/ec2/service_package_gen.go @@ -19,6 +19,10 @@ type servicePackage struct{} func (p *servicePackage) FrameworkDataSources(ctx context.Context) []*types.ServicePackageFrameworkDataSource { return []*types.ServicePackageFrameworkDataSource{ + { + Factory: newDataSourceInstanceTypesFromInstanceRequirements, + Name: "Instance Types From Instance Requirements", + }, { Factory: newSecurityGroupRuleDataSource, Name: "Security Group Rule", diff --git a/names/names.go b/names/names.go index 938491055a1..cbbd9f1f982 100644 --- a/names/names.go +++ b/names/names.go @@ -55,6 +55,7 @@ const ( ConfigServiceEndpointID = "config" DevOpsGuruEndpointID = "devops-guru" ECREndpointID = "api.ecr" + EC2EndpointID = "ec2" EKSEndpointID = "eks" EMREndpointID = "elasticmapreduce" EventsEndpointID = "events" diff --git a/website/docs/d/ec2_instance_types_from_instance_requirements.html.markdown b/website/docs/d/ec2_instance_types_from_instance_requirements.html.markdown new file mode 100644 index 00000000000..453ecfc6596 --- /dev/null +++ b/website/docs/d/ec2_instance_types_from_instance_requirements.html.markdown @@ -0,0 +1,161 @@ +--- +subcategory: "EC2 (Elastic Compute Cloud)" +layout: "aws" +page_title: "AWS: aws_ec2_instance_types_from_instance_requirements" +description: |- + EC2 Instance Types that match requirements. +--- + +# Data Source: aws_ec2_instance_types_from_instance_requirements + +Get a list of EC2 Instance Types that match requirements. + +## Example Usage + +### Basic Usage + +```terraform +data "aws_ec2_instance_types_from_instance_requirements" "example" { + architecture_types = ["x86_64"] + virtualization_types = ["hvm"] + + instance_requirements { + memory_mib { + min = 1024 + } + vcpu_count { + min = 2 + } + } +} +``` + +## Argument Reference + +The following arguments are required: + +* `architecture_types` - (Required) List of architecture types allowed. Possible values are `i386`, `x86_64`, `arm64`, `x86_64_mac` and `arm64_mac` +* `instance_requirements` - (Required) The attribute requirements for the type of instance. +* `virtualization_types` - (Required) List of virtualization types allowed. Possible values are `hvm` and `paravirtual` + +### instance_requirements + +This configuration block supports the following: + +~> **NOTE:** Both `memory_mib.min` and `vcpu_count.min` must be specified. + +- `accelerator_count` - (Optional) Block describing the minimum and maximum number of accelerators (GPUs, FPGAs, or AWS Inferentia chips). Default is no minimum or maximum. + - `min` - (Optional) Minimum. + - `max` - (Optional) Maximum. Set to `0` to exclude instance types with accelerators. +- `accelerator_manufacturers` - (Optional) List of accelerator manufacturer names. Default is any manufacturer. + + ``` + Valid names: + * amazon-web-services + * amd + * nvidia + * xilinx + ``` + +- `accelerator_names` - (Optional) List of accelerator names. Default is any acclerator. + + ``` + Valid names: + * a100 - NVIDIA A100 GPUs + * v100 - NVIDIA V100 GPUs + * k80 - NVIDIA K80 GPUs + * t4 - NVIDIA T4 GPUs + * m60 - NVIDIA M60 GPUs + * radeon-pro-v520 - AMD Radeon Pro V520 GPUs + * vu9p - Xilinx VU9P FPGAs + ``` + +- `accelerator_total_memory_mib` - (Optional) Block describing the minimum and maximum total memory of the accelerators. Default is no minimum or maximum. + + - `min` - (Optional) Minimum. + - `max` - (Optional) Maximum. + +- `accelerator_types` - (Optional) List of accelerator types. Default is any accelerator type. + + ``` + Valid types: + * fpga + * gpu + * inference + ``` + +- `allowed_instance_types` - (Optional) List of instance types to apply your specified attributes against. All other instance types are ignored, even if they match your specified attributes. You can use strings with one or more wild cards, represented by an asterisk (\*), to allow an instance type, size, or generation. The following are examples: `m5.8xlarge`, `c5*.*`, `m5a.*`, `r*`, `*3*`. For example, if you specify `c5*`, you are allowing the entire C5 instance family, which includes all C5a and C5n instance types. If you specify `m5a.*`, you are allowing all the M5a instance types, but not the M5n instance types. Maximum of 400 entries in the list; each entry is limited to 30 characters. Default is all instance types. + + ~> **NOTE:** If you specify `allowed_instance_types`, you can't specify `excluded_instance_types`. + +- `bare_metal` - (Optional) Indicate whether bare metal instace types should be `included`, `excluded`, or `required`. Default is `excluded`. +- `baseline_ebs_bandwidth_mbps` - (Optional) Block describing the minimum and maximum baseline EBS bandwidth, in Mbps. Default is no minimum or maximum. + - `min` - (Optional) Minimum. + - `max` - (Optional) Maximum. +- `burstable_performance` - (Optional) Indicate whether burstable performance instance types should be `included`, `excluded`, or `required`. Default is `excluded`. +- `cpu_manufacturers` (Optional) List of CPU manufacturer names. Default is any manufacturer. + + ~> **NOTE:** Don't confuse the CPU hardware manufacturer with the CPU hardware architecture. Instances will be launched with a compatible CPU architecture based on the Amazon Machine Image (AMI) that you specify in your launch template. + + ``` + Valid names: + * amazon-web-services + * amd + * intel + ``` + +- `excluded_instance_types` - (Optional) List of instance types to exclude. You can use strings with one or more wild cards, represented by an asterisk (\*), to exclude an instance type, size, or generation. The following are examples: `m5.8xlarge`, `c5*.*`, `m5a.*`, `r*`, `*3*`. For example, if you specify `c5*`, you are excluding the entire C5 instance family, which includes all C5a and C5n instance types. If you specify `m5a.*`, you are excluding all the M5a instance types, but not the M5n instance types. Maximum of 400 entries in the list; each entry is limited to 30 characters. Default is no excluded instance types. + + ~> **NOTE:** If you specify `excluded_instance_types`, you can't specify `allowed_instance_types`. + +- `instance_generations` - (Optional) List of instance generation names. Default is any generation. + + ``` + Valid names: + * current - Recommended for best performance. + * previous - For existing applications optimized for older instance types. + ``` + +- `local_storage` - (Optional) Indicate whether instance types with local storage volumes are `included`, `excluded`, or `required`. Default is `included`. +- `local_storage_types` - (Optional) List of local storage type names. Default any storage type. + + ``` + Value names: + * hdd - hard disk drive + * ssd - solid state drive + ``` + +- `memory_gib_per_vcpu` - (Optional) Block describing the minimum and maximum amount of memory (GiB) per vCPU. Default is no minimum or maximum. + - `min` - (Optional) Minimum. May be a decimal number, e.g. `0.5`. + - `max` - (Optional) Maximum. May be a decimal number, e.g. `0.5`. +- `memory_mib` - (Required) Block describing the minimum and maximum amount of memory (MiB). Default is no maximum. + - `min` - (Required) Minimum. + - `max` - (Optional) Maximum. +- `network_bandwidth_gbps` - (Optional) Block describing the minimum and maximum amount of network bandwidth, in gigabits per second (Gbps). Default is no minimum or maximum. + - `min` - (Optional) Minimum. + - `max` - (Optional) Maximum. +- `network_interface_count` - (Optional) Block describing the minimum and maximum number of network interfaces. Default is no minimum or maximum. + - `min` - (Optional) Minimum. + - `max` - (Optional) Maximum. +- `on_demand_max_price_percentage_over_lowest_price` - (Optional) Price protection threshold for On-Demand Instances. This is the maximum you’ll pay for an On-Demand Instance, expressed as a percentage higher than the cheapest M, C, or R instance type with your specified attributes. When Amazon EC2 Auto Scaling selects instance types with your attributes, we will exclude instance types whose price is higher than your threshold. The parameter accepts an integer, which Amazon EC2 Auto Scaling interprets as a percentage. To turn off price protection, specify a high value, such as 999999. Default is 20. + + If you set DesiredCapacityType to vcpu or memory-mib, the price protection threshold is applied based on the per vCPU or per memory price instead of the per instance price. + +- `require_hibernate_support` - (Optional) Indicate whether instance types must support On-Demand Instance Hibernation, either `true` or `false`. Default is `false`. +- `spot_max_price_percentage_over_lowest_price` - (Optional) Price protection threshold for Spot Instances. This is the maximum you’ll pay for a Spot Instance, expressed as a percentage higher than the cheapest M, C, or R instance type with your specified attributes. When Amazon EC2 Auto Scaling selects instance types with your attributes, we will exclude instance types whose price is higher than your threshold. The parameter accepts an integer, which Amazon EC2 Auto Scaling interprets as a percentage. To turn off price protection, specify a high value, such as 999999. Default is 100. + + If you set DesiredCapacityType to vcpu or memory-mib, the price protection threshold is applied based on the per vCPU or per memory price instead of the per instance price. + +- `total_local_storage_gb` - (Optional) Block describing the minimum and maximum total local storage (GB). Default is no minimum or maximum. + - `min` - (Optional) Minimum. May be a decimal number, e.g. `0.5`. + - `max` - (Optional) Maximum. May be a decimal number, e.g. `0.5`. +- `vcpu_count` - (Required) Block describing the minimum and maximum number of vCPUs. Default is no maximum. + - `min` - (Required) Minimum. + - `max` - (Optional) Maximum. + +## Attribute Reference + +This data source exports the following attributes in addition to the arguments above: + +* `id` - AWS Region. +* `instance_types` - List of EC2 Instance Types.