From f821eda919ecb5445bada5a1a702adbbc623f070 Mon Sep 17 00:00:00 2001 From: Lilian Deloche Date: Wed, 23 Sep 2020 22:37:46 +0200 Subject: [PATCH 1/8] New datasource ec2_instance_type to get characteristics about ec2 instance type Co-authored-by: Dirk Avery <31492422+YakDriver@users.noreply.github.com> --- aws/data_source_aws_ec2_instance_type.go | 439 ++++++++++++++++++ aws/data_source_aws_ec2_instance_type_test.go | 101 ++++ aws/provider.go | 1 + .../docs/d/ec2_instance_type.html.markdown | 83 ++++ 4 files changed, 624 insertions(+) create mode 100644 aws/data_source_aws_ec2_instance_type.go create mode 100644 aws/data_source_aws_ec2_instance_type_test.go create mode 100644 website/docs/d/ec2_instance_type.html.markdown diff --git a/aws/data_source_aws_ec2_instance_type.go b/aws/data_source_aws_ec2_instance_type.go new file mode 100644 index 000000000000..ce7fb45330f0 --- /dev/null +++ b/aws/data_source_aws_ec2_instance_type.go @@ -0,0 +1,439 @@ +package aws + +import ( + "fmt" + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/ec2" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "log" +) + +func dataSourceAwsEc2InstanceType() *schema.Resource { + return &schema.Resource{ + Read: dataSourceAwsEc2InstanceTypeRead, + + Schema: map[string]*schema.Schema{ + "instance_type": { + Type: schema.TypeString, + Required: true, + }, + "current_generation": { + Type: schema.TypeBool, + Computed: true, + }, + "free_tier_eligible": { + Type: schema.TypeBool, + Computed: true, + }, + "supported_usages_classes": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "supported_root_device_types": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "bare_metal": { + Type: schema.TypeBool, + Computed: true, + }, + "hypervisor": { + Type: schema.TypeString, + Computed: true, + Optional: true, + }, + "supported_architectures": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "sustained_clock_speed": { + Type: schema.TypeFloat, + Computed: true, + }, + "default_vcpus": { + Type: schema.TypeInt, + Computed: true, + }, + "default_cores": { + Type: schema.TypeInt, + Computed: true, + Optional: true, + }, + "default_threads_per_core": { + Type: schema.TypeInt, + Computed: true, + Optional: true, + }, + "valid_cores": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeInt}, + }, + "valid_threads_per_core": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeInt}, + }, + "memory_size": { + Type: schema.TypeInt, + Computed: true, + }, + "instance_storage_supported": { + Type: schema.TypeBool, + Computed: true, + }, + "total_instance_storage": { + Type: schema.TypeInt, + Computed: true, + Optional: true, + }, + "instance_disks": { + Type: schema.TypeSet, + Computed: true, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "size": { + Type: schema.TypeInt, + Computed: true, + }, + "count": { + Type: schema.TypeInt, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "ebs_optimized_support": { + Type: schema.TypeString, + Computed: true, + }, + "ebs_encryption_support": { + Type: schema.TypeString, + Computed: true, + }, + "network_performance": { + Type: schema.TypeString, + Computed: true, + }, + "maximum_network_interfaces": { + Type: schema.TypeInt, + Computed: true, + }, + "maximum_ipv4_addresses_per_interface": { + Type: schema.TypeInt, + Computed: true, + }, + "maximum_ipv6_addresses_per_interface": { + Type: schema.TypeInt, + Computed: true, + Optional: true, + }, + "ipv6_supported": { + Type: schema.TypeBool, + Computed: true, + }, + "ena_support": { + Type: schema.TypeString, + Computed: true, + }, + "gpus": { + Type: schema.TypeSet, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "manufacturer": { + Type: schema.TypeString, + Computed: true, + }, + "count": { + Type: schema.TypeInt, + Computed: true, + }, + "memory_size": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "total_gpu_memory": { + Type: schema.TypeInt, + Computed: true, + Optional: true, + }, + "fpgas": { + Type: schema.TypeSet, + Computed: true, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "manufacturer": { + Type: schema.TypeString, + Computed: true, + }, + "count": { + Type: schema.TypeInt, + Computed: true, + }, + "memory_size": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "total_fpga_memory": { + Type: schema.TypeInt, + Computed: true, + Optional: true, + }, + "supported_placement_strategies": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "accelerators": { + Type: schema.TypeSet, + Computed: true, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "manufacturer": { + Type: schema.TypeString, + Computed: true, + }, + "count": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "hibernation_supported": { + Type: schema.TypeBool, + Computed: true, + }, + "burstable_performance_supported": { + Type: schema.TypeBool, + Computed: true, + }, + "dedicated_hosts_supported": { + Type: schema.TypeBool, + Computed: true, + }, + "auto_recovery_supported": { + Type: schema.TypeBool, + Computed: true, + }, + }, + } +} + +func dataSourceAwsEc2InstanceTypeRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).ec2conn + + params := &ec2.DescribeInstanceTypesInput{} + + instanceType := d.Get("instance_type").(string) + params.InstanceTypes = []*string{aws.String(instanceType)} + log.Printf("[DEBUG] Reading instances types: %s", params) + + resp, err := conn.DescribeInstanceTypes(params) + if err != nil { + return err + } + if len(resp.InstanceTypes) == 0 { + return fmt.Errorf("no Instance Type found for %s", instanceType) + } + if len(resp.InstanceTypes) > 1 { + return fmt.Errorf("multiple instance types found for type %s", instanceType) + } + v := resp.InstanceTypes[0] + d.Set("instance_type", v.InstanceType) + if err := d.Set("current_generation", aws.BoolValue(v.CurrentGeneration)); err != nil { + return fmt.Errorf("error setting current_generation: %s", err) + } + if err := d.Set("free_tier_eligible", aws.BoolValue(v.FreeTierEligible)); err != nil { + return fmt.Errorf("error setting free_tier_eligible: %s", err) + } + if err := d.Set("supported_usages_classes", aws.StringValueSlice(v.SupportedUsageClasses)); err != nil { + return fmt.Errorf("error setting supported_usages_classes: %s", err) + } + if err := d.Set("supported_root_device_types", aws.StringValueSlice(v.SupportedRootDeviceTypes)); err != nil { + return fmt.Errorf("error setting supported_root_device_types: %s", err) + } + if err := d.Set("bare_metal", aws.BoolValue(v.BareMetal)); err != nil { + return fmt.Errorf("error setting bare_metal: %s", err) + } + if v.Hypervisor != nil { + if err := d.Set("hypervisor", aws.StringValue(v.Hypervisor)); err != nil { + return fmt.Errorf("error setting hypervisor: %s", err) + } + } + if err := d.Set("supported_architectures", aws.StringValueSlice(v.ProcessorInfo.SupportedArchitectures)); err != nil { + return fmt.Errorf("error setting supported_architectures: %s", err) + } + if err := d.Set("sustained_clock_speed", aws.Float64Value(v.ProcessorInfo.SustainedClockSpeedInGhz)); err != nil { + return fmt.Errorf("error setting sustained_clock_speed: %s", err) + } + if err := d.Set("default_vcpus", aws.Int64Value(v.VCpuInfo.DefaultVCpus)); err != nil { + return fmt.Errorf("error setting default_vcpus: %s", err) + } + if v.VCpuInfo.DefaultCores != nil { + if err := d.Set("default_cores", aws.Int64Value(v.VCpuInfo.DefaultCores)); err != nil { + return fmt.Errorf("error setting default_cores: %s", err) + } + } + if v.VCpuInfo.DefaultThreadsPerCore != nil { + if err := d.Set("default_threads_per_core", aws.Int64Value(v.VCpuInfo.DefaultThreadsPerCore)); err != nil { + return fmt.Errorf("error setting default_threads_per_core: %s", err) + } + } + if v.VCpuInfo.ValidThreadsPerCore != nil { + if err := d.Set("valid_threads_per_core", aws.Int64ValueSlice(v.VCpuInfo.ValidThreadsPerCore)); err != nil { + return fmt.Errorf("error setting valid_threads_per_core: %s", err) + } + } + if v.VCpuInfo.ValidCores != nil { + if err := d.Set("valid_cores", aws.Int64ValueSlice(v.VCpuInfo.ValidCores)); err != nil { + return fmt.Errorf("error setting valid_cores: %s", err) + } + } + if err := d.Set("memory_size", aws.Int64Value(v.MemoryInfo.SizeInMiB)); err != nil { + return fmt.Errorf("error setting memory_size: %s", err) + } + if err := d.Set("instance_storage_supported", aws.BoolValue(v.InstanceStorageSupported)); err != nil { + return fmt.Errorf("error setting instance_storage_supported: %s", err) + } + if v.InstanceStorageInfo != nil { + if err := d.Set("total_instance_storage", aws.Int64Value(v.InstanceStorageInfo.TotalSizeInGB)); err != nil { + return fmt.Errorf("error setting total_instance_storage: %s", err) + } + if v.InstanceStorageInfo.Disks != nil { + diskList := make([]interface{}, len(v.InstanceStorageInfo.Disks)) + for i, dk := range v.InstanceStorageInfo.Disks { + disk := map[string]interface{}{ + "size": aws.Int64Value(dk.SizeInGB), + "count": aws.Int64Value(dk.Count), + "type": aws.StringValue(dk.Type), + } + diskList[i] = disk + } + if err := d.Set("instance_disks", diskList); err != nil { + return fmt.Errorf("error setting instance_disks: %s", err) + } + } + } + if err := d.Set("ebs_optimized_support", aws.StringValue(v.EbsInfo.EbsOptimizedSupport)); err != nil { + return fmt.Errorf("error setting ebs_optimized_support: %s", err) + } + if err := d.Set("ebs_encryption_support", aws.StringValue(v.EbsInfo.EncryptionSupport)); err != nil { + return fmt.Errorf("error setting ebs_encryption_support: %s", err) + } + if err := d.Set("network_performance", aws.StringValue(v.NetworkInfo.NetworkPerformance)); err != nil { + return fmt.Errorf("error setting network_performance: %s", err) + } + if err := d.Set("maximum_network_interfaces", aws.Int64Value(v.NetworkInfo.MaximumNetworkInterfaces)); err != nil { + return fmt.Errorf("error setting maximum_network_interfaces: %s", err) + } + if err := d.Set("maximum_ipv4_addresses_per_interface", aws.Int64Value(v.NetworkInfo.Ipv4AddressesPerInterface)); err != nil { + return fmt.Errorf("error setting ipv4_addresses_per_interface: %s", err) + } + if err := d.Set("maximum_ipv6_addresses_per_interface", aws.Int64Value(v.NetworkInfo.Ipv6AddressesPerInterface)); err != nil { + return fmt.Errorf("error setting ipv6_addresses_per_interface: %s", err) + } + if err := d.Set("ipv6_supported", aws.BoolValue(v.NetworkInfo.Ipv6Supported)); err != nil { + return fmt.Errorf("error setting ipv6_supported: %s", err) + } + if err := d.Set("ena_support", aws.StringValue(v.NetworkInfo.EnaSupport)); err != nil { + return fmt.Errorf("error setting ena_support: %s", err) + } + if v.GpuInfo != nil { + gpuList := make([]interface{}, len(v.GpuInfo.Gpus)) + for i, gp := range v.GpuInfo.Gpus { + gpu := map[string]interface{}{ + "manufacturer": aws.StringValue(gp.Manufacturer), + "name": aws.StringValue(gp.Name), + "count": aws.Int64Value(gp.Count), + "memory_size": aws.Int64Value(gp.MemoryInfo.SizeInMiB), + } + gpuList[i] = gpu + } + if err := d.Set("gpus", gpuList); err != nil { + return fmt.Errorf("error setting gpu: %s", err) + } + if err := d.Set("total_gpu_memory", aws.Int64Value(v.GpuInfo.TotalGpuMemoryInMiB)); err != nil { + return fmt.Errorf("error setting total_gpu_memory: %s", err) + } + } + if v.FpgaInfo != nil { + fpgaList := make([]interface{}, len(v.FpgaInfo.Fpgas)) + for i, fpg := range v.FpgaInfo.Fpgas { + fpga := map[string]interface{}{ + "manufacturer": aws.StringValue(fpg.Manufacturer), + "name": aws.StringValue(fpg.Name), + "count": aws.Int64Value(fpg.Count), + "memory_size": aws.Int64Value(fpg.MemoryInfo.SizeInMiB), + } + fpgaList[i] = fpga + } + if err := d.Set("fpgas", fpgaList); err != nil { + return fmt.Errorf("error setting fpga: %s", err) + } + if err := d.Set("total_fpga_memory", aws.Int64Value(v.FpgaInfo.TotalFpgaMemoryInMiB)); err != nil { + return fmt.Errorf("error setting total_fpga_memory: %s", err) + } + } + if err := d.Set("supported_placement_strategies", aws.StringValueSlice(v.PlacementGroupInfo.SupportedStrategies)); err != nil { + return fmt.Errorf("error setting supported_placement_strategies: %s", err) + } + if v.InferenceAcceleratorInfo != nil { + acceleratorList := make([]interface{}, len(v.InferenceAcceleratorInfo.Accelerators)) + for i, accl := range v.InferenceAcceleratorInfo.Accelerators { + accelerator := map[string]interface{}{ + "manufacturer": aws.StringValue(accl.Manufacturer), + "name": aws.StringValue(accl.Name), + "count": aws.Int64Value(accl.Count), + } + acceleratorList[i] = accelerator + } + if err := d.Set("accelerators", acceleratorList); err != nil { + return fmt.Errorf("error setting fpga: %s", err) + } + } + if err := d.Set("hibernation_supported", aws.BoolValue(v.HibernationSupported)); err != nil { + return fmt.Errorf("error setting hibernation_supported: %s", err) + } + if err := d.Set("burstable_performance_supported", aws.BoolValue(v.BurstablePerformanceSupported)); err != nil { + return fmt.Errorf("error setting burstable_performance_supported: %s", err) + } + if err := d.Set("dedicated_hosts_supported", aws.BoolValue(v.DedicatedHostsSupported)); err != nil { + return fmt.Errorf("error setting dedicated_hosts_supported: %s", err) + } + if err := d.Set("auto_recovery_supported", aws.BoolValue(v.AutoRecoverySupported)); err != nil { + return fmt.Errorf("error setting auto_recovery_supported: %s", err) + } + d.SetId(aws.StringValue(v.InstanceType)) + return nil +} diff --git a/aws/data_source_aws_ec2_instance_type_test.go b/aws/data_source_aws_ec2_instance_type_test.go new file mode 100644 index 000000000000..4f71326769ee --- /dev/null +++ b/aws/data_source_aws_ec2_instance_type_test.go @@ -0,0 +1,101 @@ +package aws + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccDataSourceAwsEc2InstanceType_attributes(t *testing.T) { + resourceMetal := "data.aws_ec2_instance_type.metal" + resourceGpu := "data.aws_ec2_instance_type.gpu" + resourceFpga := "data.aws_ec2_instance_type.fpga" + resourceAccelerator := "data.aws_ec2_instance_type.accelerator" + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceEc2InstanceType, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceMetal, "auto_recovery_supported", "false"), + resource.TestCheckResourceAttr(resourceMetal, "bare_metal", "true"), + resource.TestCheckResourceAttr(resourceMetal, "burstable_performance_supported", "false"), + resource.TestCheckResourceAttr(resourceMetal, "current_generation", "true"), + resource.TestCheckResourceAttr(resourceMetal, "dedicated_hosts_supported", "true"), + resource.TestCheckResourceAttr(resourceMetal, "default_vcpus", "96"), + resource.TestCheckResourceAttr(resourceMetal, "ebs_encryption_support", "supported"), + resource.TestCheckResourceAttr(resourceMetal, "ebs_optimized_support", "default"), + resource.TestCheckResourceAttr(resourceMetal, "ena_support", "required"), + resource.TestCheckResourceAttr(resourceMetal, "free_tier_eligible", "false"), + resource.TestCheckResourceAttr(resourceMetal, "hibernation_supported", "false"), + resource.TestCheckResourceAttr(resourceMetal, "instance_storage_supported", "true"), + resource.TestCheckResourceAttr(resourceMetal, "instance_type", "i3en.metal"), + resource.TestCheckResourceAttr(resourceMetal, "ipv6_supported", "true"), + resource.TestCheckResourceAttr(resourceMetal, "maximum_ipv4_addresses_per_interface", "50"), + resource.TestCheckResourceAttr(resourceMetal, "maximum_ipv6_addresses_per_interface", "50"), + resource.TestCheckResourceAttr(resourceMetal, "maximum_network_interfaces", "15"), + resource.TestCheckResourceAttr(resourceMetal, "memory_size", "786432"), + resource.TestCheckResourceAttr(resourceMetal, "network_performance", "100 Gigabit"), + resource.TestCheckResourceAttr(resourceMetal, "supported_architectures.#", "1"), + resource.TestCheckResourceAttr(resourceMetal, "supported_architectures.0", "x86_64"), + resource.TestCheckResourceAttr(resourceMetal, "supported_placement_strategies.#", "3"), + resource.TestCheckResourceAttr(resourceMetal, "supported_placement_strategies.0", "cluster"), + resource.TestCheckResourceAttr(resourceMetal, "supported_placement_strategies.1", "partition"), + resource.TestCheckResourceAttr(resourceMetal, "supported_placement_strategies.2", "spread"), + resource.TestCheckResourceAttr(resourceMetal, "supported_root_device_types.#", "1"), + resource.TestCheckResourceAttr(resourceMetal, "supported_root_device_types.0", "ebs"), + resource.TestCheckResourceAttr(resourceMetal, "supported_usages_classes.#", "2"), + resource.TestCheckResourceAttr(resourceMetal, "supported_usages_classes.0", "on-demand"), + resource.TestCheckResourceAttr(resourceMetal, "supported_usages_classes.1", "spot"), + resource.TestCheckResourceAttr(resourceMetal, "sustained_clock_speed", "3.1"), + resource.TestCheckResourceAttr(resourceMetal, "total_instance_storage", "60000"), + resource.TestCheckResourceAttr(resourceMetal, "instance_disks.#", "1"), + resource.TestCheckResourceAttr(resourceMetal, "instance_disks.0.count", "8"), + resource.TestCheckResourceAttr(resourceMetal, "instance_disks.0.size", "7500"), + resource.TestCheckResourceAttr(resourceMetal, "instance_disks.0.type", "ssd"), + resource.TestCheckResourceAttr(resourceGpu, "total_gpu_memory", "4096"), + resource.TestCheckResourceAttr(resourceGpu, "hypervisor", "xen"), + resource.TestCheckResourceAttr(resourceGpu, "gpus.#", "1"), + resource.TestCheckResourceAttr(resourceGpu, "gpus.0.count", "1"), + resource.TestCheckResourceAttr(resourceGpu, "gpus.0.memory_size", "4096"), + resource.TestCheckResourceAttr(resourceGpu, "gpus.0.manufacturer", "NVIDIA"), + resource.TestCheckResourceAttr(resourceGpu, "gpus.0.name", "K520"), + resource.TestCheckResourceAttr(resourceGpu, "valid_threads_per_core.#", "2"), + resource.TestCheckResourceAttr(resourceGpu, "valid_threads_per_core.0", "1"), + resource.TestCheckResourceAttr(resourceGpu, "valid_threads_per_core.1", "2"), + resource.TestCheckResourceAttr(resourceGpu, "default_threads_per_core", "2"), + resource.TestCheckResourceAttr(resourceGpu, "default_cores", "4"), + resource.TestCheckResourceAttr(resourceGpu, "default_vcpus", "8"), + resource.TestCheckResourceAttr(resourceFpga, "fpgas.#", "1"), + resource.TestCheckResourceAttr(resourceFpga, "fpgas.0.name", "Virtex UltraScale (VU9P)"), + resource.TestCheckResourceAttr(resourceFpga, "fpgas.0.manufacturer", "Xilinx"), + resource.TestCheckResourceAttr(resourceFpga, "fpgas.0.count", "1"), + resource.TestCheckResourceAttr(resourceFpga, "fpgas.0.memory_size", "65536"), + resource.TestCheckResourceAttr(resourceFpga, "total_fpga_memory", "65536"), + resource.TestCheckResourceAttr(resourceAccelerator, "accelerators.#", "1"), + resource.TestCheckResourceAttr(resourceAccelerator, "accelerators.0.count", "1"), + resource.TestCheckResourceAttr(resourceAccelerator, "accelerators.0.name", "Inferentia"), + resource.TestCheckResourceAttr(resourceAccelerator, "accelerators.0.manufacturer", "AWS"), + resource.TestCheckResourceAttr(resourceAccelerator, "valid_cores.#", "1"), + resource.TestCheckResourceAttr(resourceAccelerator, "valid_cores.0", "2"), + ), + }, + }, + }) +} + +const testAccDataSourceEc2InstanceType = ` +data "aws_ec2_instance_type" "metal" { + instance_type="i3en.metal" +} +data "aws_ec2_instance_type" "gpu" { + instance_type="g2.2xlarge" +} +data "aws_ec2_instance_type" "fpga" { + instance_type="f1.2xlarge" +} +data "aws_ec2_instance_type" "accelerator" { + instance_type="inf1.xlarge" +} +` diff --git a/aws/provider.go b/aws/provider.go index 9b0ebc125c98..17ef69b6b804 100644 --- a/aws/provider.go +++ b/aws/provider.go @@ -214,6 +214,7 @@ func Provider() *schema.Provider { "aws_ebs_volumes": dataSourceAwsEbsVolumes(), "aws_ec2_coip_pool": dataSourceAwsEc2CoipPool(), "aws_ec2_coip_pools": dataSourceAwsEc2CoipPools(), + "aws_ec2_instance_type": dataSourceAwsEc2InstanceType(), "aws_ec2_instance_type_offering": dataSourceAwsEc2InstanceTypeOffering(), "aws_ec2_instance_type_offerings": dataSourceAwsEc2InstanceTypeOfferings(), "aws_ec2_local_gateway": dataSourceAwsEc2LocalGateway(), diff --git a/website/docs/d/ec2_instance_type.html.markdown b/website/docs/d/ec2_instance_type.html.markdown new file mode 100644 index 000000000000..932f6b11a09a --- /dev/null +++ b/website/docs/d/ec2_instance_type.html.markdown @@ -0,0 +1,83 @@ +--- +subcategory: "EC2" +layout: "aws" +page_title: "AWS: aws_ec2_instance_type" +description: |- + Information about single EC2 Instance Type. +--- + + +# Data Source: aws_ec2_instance_type + +Get characteristics for a single EC2 Instance Type. + +## Example Usage + +```hcl +data "aws_ec2_instance_type" "example" { + instance_type = "t2.micro" +} + +``` + +## Argument Reference + +The following argument is supported: + +* `instance_type` - (Required) Instance + +## Attribute Reference + +In addition to the argument above, the following attributes are exported: + +~> **NOTE:** Not all attributes are set for every instance type. + +* `accelerators` Describes the Inference accelerators for the instance type. + * `accelerators.#.count` - The number of Inference accelerators for the instance type. + * `accelerators.#.manufacturer` - The manufacturer of the Inference accelerator. + * `accelerators.#.name` - The name of the Inference accelerator. +* `auto_recovery_supported` - `true` if auto recovery is supported. +* `bare_metal` - `true` if it is a bare metal instance type. +* `burstable_performance_supported` - `true` if the instance type is a burstable performance instance type. +* `current_generation` - `true` if the instance type is a current generation. +* `default_cores` - The default number of cores for the instance type. +* `default_threads_per_core` - The default number of threads per core for the instance type. +* `default_vcpus` - The default number of vCPUs for the instance type. +* `dedicated_hosts_supported` - `true` if Dedicated Hosts are supported on the instance type. +* `ebs_encryption_support` - Indicates whether Amazon EBS encryption is supported. +* `ebs_optimized_support` - Indicates that the instance type is Amazon EBS-optimized. +* `ena_support` - Indicates whether Elastic Network Adapter (ENA) is supported. +* `fpgas` - Describes the FPGA accelerator settings for the instance type. + * `fpgas.#.count` - The count of FPGA accelerators for the instance type. + * `fpgas.#.manufacturer` - The manufacturer of the FPGA accelerator. + * `fpgas.#.memory_size` - The size (in MiB) for the memory available to the FPGA accelerator. + * `fpgas.#.name` - The name of the FPGA accelerator. +* `free_tier_eligible` - `true` if the instance type is eligible for the free tier. +* `gpus` - Describes the GPU accelerators for the instance type. + * `gpus.#.count` - The number of GPUs for the instance type. + * `gpus.#.manufacturer` - The manufacturer of the GPU accelerator. + * `gpus.#.memory_size` - The size (in MiB) for the memory available to the GPU accelerator. + * `gpus.#.name` - The name of the GPU accelerator. +* `hibernation_supported` - `true` if On-Demand hibernation is supported. +* `hypervisor` - Indicates the hypervisor used for the instance type. +* `ipv6_supported` - `true` if IPv6 is supported. +* `instance_disks` - Describes the disks for the instance type. + * `instance_disks.#.count` - The number of disks with this configuration. + * `instance_disks.#.size` - The size of the disk in GB. + * `instance_disks.#.type` - The type of disk. +* `instance_storage_supported` - `true` if instance storage is supported. +* `maximum_ipv4_addresses_per_interface` - The maximum number of IPv4 addresses per network interface. +* `maximum_ipv6_addresses_per_interface` - The maximum number of IPv6 addresses per network interface. +* `maximum_network_interfaces` - The maximum number of network interfaces for the instance type. +* `memory_size` - Size of the instance memory, in MiB. +* `network_performance` - Describes the network performance. +* `supported_architectures` - A list of architectures supported by the instance type. +* `supported_placement_strategies` - A list of supported placement groups types. +* `supported_root_device_types` - Indicates the supported root device types. +* `supported_usages_classes` - Indicates whether the instance type is offered for spot or On-Demand. +* `sustained_clock_speed` - The speed of the processor, in GHz. +* `total_fpga_memory` - The total memory of all FPGA accelerators for the instance type (in MiB). +* `total_gpu_memory` - The total size of the memory for the GPU accelerators for the instance type (in MiB). +* `total_instance_storage` - The total size of the instance disks, in GB. +* `valid_cores` - List of the valid number of cores that can be configured for the instance type. +* `valid_threads_per_core` - List of the valid number of threads per core that can be configured for the instance type. From 01f5284908d291447c0344def5cdc1b85760bf68 Mon Sep 17 00:00:00 2001 From: Lilian Deloche Date: Fri, 25 Sep 2020 18:01:53 +0200 Subject: [PATCH 2/8] Apply suggestions from code review Fix indent in tests Co-authored-by: Dirk Avery <31492422+YakDriver@users.noreply.github.com> --- aws/data_source_aws_ec2_instance_type_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/aws/data_source_aws_ec2_instance_type_test.go b/aws/data_source_aws_ec2_instance_type_test.go index 4f71326769ee..a80261f62b26 100644 --- a/aws/data_source_aws_ec2_instance_type_test.go +++ b/aws/data_source_aws_ec2_instance_type_test.go @@ -87,15 +87,15 @@ func TestAccDataSourceAwsEc2InstanceType_attributes(t *testing.T) { const testAccDataSourceEc2InstanceType = ` data "aws_ec2_instance_type" "metal" { - instance_type="i3en.metal" + instance_type="i3en.metal" } data "aws_ec2_instance_type" "gpu" { - instance_type="g2.2xlarge" + instance_type="g2.2xlarge" } data "aws_ec2_instance_type" "fpga" { - instance_type="f1.2xlarge" + instance_type="f1.2xlarge" } data "aws_ec2_instance_type" "accelerator" { - instance_type="inf1.xlarge" + instance_type="inf1.xlarge" } ` From 3c6fac007e5f1be552aa327be904a63d75472d6e Mon Sep 17 00:00:00 2001 From: Lilian Deloche Date: Mon, 28 Sep 2020 21:16:00 +0200 Subject: [PATCH 3/8] Apply suggestions from code review Co-authored-by: Dirk Avery <31492422+YakDriver@users.noreply.github.com> --- aws/data_source_aws_ec2_instance_type.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/aws/data_source_aws_ec2_instance_type.go b/aws/data_source_aws_ec2_instance_type.go index ce7fb45330f0..edbfe003949f 100644 --- a/aws/data_source_aws_ec2_instance_type.go +++ b/aws/data_source_aws_ec2_instance_type.go @@ -17,6 +17,7 @@ func dataSourceAwsEc2InstanceType() *schema.Resource { Type: schema.TypeString, Required: true, }, + "current_generation": { Type: schema.TypeBool, Computed: true, @@ -271,9 +272,7 @@ func dataSourceAwsEc2InstanceTypeRead(d *schema.ResourceData, meta interface{}) } v := resp.InstanceTypes[0] d.Set("instance_type", v.InstanceType) - if err := d.Set("current_generation", aws.BoolValue(v.CurrentGeneration)); err != nil { - return fmt.Errorf("error setting current_generation: %s", err) - } + d.Set("current_generation", v.CurrentGeneration) if err := d.Set("free_tier_eligible", aws.BoolValue(v.FreeTierEligible)); err != nil { return fmt.Errorf("error setting free_tier_eligible: %s", err) } From 3f1bc392aa0e15835cd5b8adc2057bf8a201fe1f Mon Sep 17 00:00:00 2001 From: Lilian Deloche Date: Tue, 29 Sep 2020 21:16:10 +0200 Subject: [PATCH 4/8] applying new pattern for d.set() and extra line between attributes --- aws/data_source_aws_ec2_instance_type.go | 190 ++++++++++------------- 1 file changed, 78 insertions(+), 112 deletions(-) diff --git a/aws/data_source_aws_ec2_instance_type.go b/aws/data_source_aws_ec2_instance_type.go index edbfe003949f..57843a440285 100644 --- a/aws/data_source_aws_ec2_instance_type.go +++ b/aws/data_source_aws_ec2_instance_type.go @@ -22,75 +22,91 @@ func dataSourceAwsEc2InstanceType() *schema.Resource { Type: schema.TypeBool, Computed: true, }, + "free_tier_eligible": { Type: schema.TypeBool, Computed: true, }, + "supported_usages_classes": { Type: schema.TypeList, Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, }, + "supported_root_device_types": { Type: schema.TypeList, Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, }, + "bare_metal": { Type: schema.TypeBool, Computed: true, }, + "hypervisor": { Type: schema.TypeString, Computed: true, Optional: true, }, + "supported_architectures": { Type: schema.TypeList, Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, }, + "sustained_clock_speed": { Type: schema.TypeFloat, Computed: true, }, + "default_vcpus": { Type: schema.TypeInt, Computed: true, }, + "default_cores": { Type: schema.TypeInt, Computed: true, Optional: true, }, + "default_threads_per_core": { Type: schema.TypeInt, Computed: true, Optional: true, }, + "valid_cores": { Type: schema.TypeList, Computed: true, Elem: &schema.Schema{Type: schema.TypeInt}, }, + "valid_threads_per_core": { Type: schema.TypeList, Computed: true, Elem: &schema.Schema{Type: schema.TypeInt}, }, + "memory_size": { Type: schema.TypeInt, Computed: true, }, + "instance_storage_supported": { Type: schema.TypeBool, Computed: true, }, + "total_instance_storage": { Type: schema.TypeInt, Computed: true, Optional: true, }, + "instance_disks": { Type: schema.TypeSet, Computed: true, @@ -101,10 +117,12 @@ func dataSourceAwsEc2InstanceType() *schema.Resource { Type: schema.TypeInt, Computed: true, }, + "count": { Type: schema.TypeInt, Computed: true, }, + "type": { Type: schema.TypeString, Computed: true, @@ -112,39 +130,48 @@ func dataSourceAwsEc2InstanceType() *schema.Resource { }, }, }, + "ebs_optimized_support": { Type: schema.TypeString, Computed: true, }, + "ebs_encryption_support": { Type: schema.TypeString, Computed: true, }, + "network_performance": { Type: schema.TypeString, Computed: true, }, + "maximum_network_interfaces": { Type: schema.TypeInt, Computed: true, }, + "maximum_ipv4_addresses_per_interface": { Type: schema.TypeInt, Computed: true, }, + "maximum_ipv6_addresses_per_interface": { Type: schema.TypeInt, Computed: true, Optional: true, }, + "ipv6_supported": { Type: schema.TypeBool, Computed: true, }, + "ena_support": { Type: schema.TypeString, Computed: true, }, + "gpus": { Type: schema.TypeSet, Optional: true, @@ -155,14 +182,17 @@ func dataSourceAwsEc2InstanceType() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "manufacturer": { Type: schema.TypeString, Computed: true, }, + "count": { Type: schema.TypeInt, Computed: true, }, + "memory_size": { Type: schema.TypeInt, Computed: true, @@ -170,11 +200,13 @@ func dataSourceAwsEc2InstanceType() *schema.Resource { }, }, }, + "total_gpu_memory": { Type: schema.TypeInt, Computed: true, Optional: true, }, + "fpgas": { Type: schema.TypeSet, Computed: true, @@ -185,14 +217,17 @@ func dataSourceAwsEc2InstanceType() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "manufacturer": { Type: schema.TypeString, Computed: true, }, + "count": { Type: schema.TypeInt, Computed: true, }, + "memory_size": { Type: schema.TypeInt, Computed: true, @@ -200,16 +235,19 @@ func dataSourceAwsEc2InstanceType() *schema.Resource { }, }, }, + "total_fpga_memory": { Type: schema.TypeInt, Computed: true, Optional: true, }, + "supported_placement_strategies": { Type: schema.TypeList, Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, }, + "accelerators": { Type: schema.TypeSet, Computed: true, @@ -220,10 +258,12 @@ func dataSourceAwsEc2InstanceType() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "manufacturer": { Type: schema.TypeString, Computed: true, }, + "count": { Type: schema.TypeInt, Computed: true, @@ -231,18 +271,22 @@ func dataSourceAwsEc2InstanceType() *schema.Resource { }, }, }, + "hibernation_supported": { Type: schema.TypeBool, Computed: true, }, + "burstable_performance_supported": { Type: schema.TypeBool, Computed: true, }, + "dedicated_hosts_supported": { Type: schema.TypeBool, Computed: true, }, + "auto_recovery_supported": { Type: schema.TypeBool, Computed: true, @@ -273,62 +317,22 @@ func dataSourceAwsEc2InstanceTypeRead(d *schema.ResourceData, meta interface{}) v := resp.InstanceTypes[0] d.Set("instance_type", v.InstanceType) d.Set("current_generation", v.CurrentGeneration) - if err := d.Set("free_tier_eligible", aws.BoolValue(v.FreeTierEligible)); err != nil { - return fmt.Errorf("error setting free_tier_eligible: %s", err) - } - if err := d.Set("supported_usages_classes", aws.StringValueSlice(v.SupportedUsageClasses)); err != nil { - return fmt.Errorf("error setting supported_usages_classes: %s", err) - } - if err := d.Set("supported_root_device_types", aws.StringValueSlice(v.SupportedRootDeviceTypes)); err != nil { - return fmt.Errorf("error setting supported_root_device_types: %s", err) - } - if err := d.Set("bare_metal", aws.BoolValue(v.BareMetal)); err != nil { - return fmt.Errorf("error setting bare_metal: %s", err) - } - if v.Hypervisor != nil { - if err := d.Set("hypervisor", aws.StringValue(v.Hypervisor)); err != nil { - return fmt.Errorf("error setting hypervisor: %s", err) - } - } - if err := d.Set("supported_architectures", aws.StringValueSlice(v.ProcessorInfo.SupportedArchitectures)); err != nil { - return fmt.Errorf("error setting supported_architectures: %s", err) - } - if err := d.Set("sustained_clock_speed", aws.Float64Value(v.ProcessorInfo.SustainedClockSpeedInGhz)); err != nil { - return fmt.Errorf("error setting sustained_clock_speed: %s", err) - } - if err := d.Set("default_vcpus", aws.Int64Value(v.VCpuInfo.DefaultVCpus)); err != nil { - return fmt.Errorf("error setting default_vcpus: %s", err) - } - if v.VCpuInfo.DefaultCores != nil { - if err := d.Set("default_cores", aws.Int64Value(v.VCpuInfo.DefaultCores)); err != nil { - return fmt.Errorf("error setting default_cores: %s", err) - } - } - if v.VCpuInfo.DefaultThreadsPerCore != nil { - if err := d.Set("default_threads_per_core", aws.Int64Value(v.VCpuInfo.DefaultThreadsPerCore)); err != nil { - return fmt.Errorf("error setting default_threads_per_core: %s", err) - } - } - if v.VCpuInfo.ValidThreadsPerCore != nil { - if err := d.Set("valid_threads_per_core", aws.Int64ValueSlice(v.VCpuInfo.ValidThreadsPerCore)); err != nil { - return fmt.Errorf("error setting valid_threads_per_core: %s", err) - } - } - if v.VCpuInfo.ValidCores != nil { - if err := d.Set("valid_cores", aws.Int64ValueSlice(v.VCpuInfo.ValidCores)); err != nil { - return fmt.Errorf("error setting valid_cores: %s", err) - } - } - if err := d.Set("memory_size", aws.Int64Value(v.MemoryInfo.SizeInMiB)); err != nil { - return fmt.Errorf("error setting memory_size: %s", err) - } - if err := d.Set("instance_storage_supported", aws.BoolValue(v.InstanceStorageSupported)); err != nil { - return fmt.Errorf("error setting instance_storage_supported: %s", err) - } + d.Set("free_tier_eligible", v.FreeTierEligible) + d.Set("supported_usages_classes", v.SupportedUsageClasses) + d.Set("supported_root_device_types", v.SupportedRootDeviceTypes) + d.Set("bare_metal", v.BareMetal) + d.Set("hypervisor", v.Hypervisor) + d.Set("supported_architectures", v.ProcessorInfo.SupportedArchitectures) + d.Set("sustained_clock_speed", v.ProcessorInfo.SustainedClockSpeedInGhz) + d.Set("default_vcpus", v.VCpuInfo.DefaultVCpus) + d.Set("default_cores", v.VCpuInfo.DefaultCores) + d.Set("default_threads_per_core", v.VCpuInfo.DefaultThreadsPerCore) + d.Set("valid_threads_per_core", v.VCpuInfo.ValidThreadsPerCore) + d.Set("valid_cores", v.VCpuInfo.ValidCores) + d.Set("memory_size", v.MemoryInfo.SizeInMiB) + d.Set("instance_storage_supported", v.InstanceStorageSupported) if v.InstanceStorageInfo != nil { - if err := d.Set("total_instance_storage", aws.Int64Value(v.InstanceStorageInfo.TotalSizeInGB)); err != nil { - return fmt.Errorf("error setting total_instance_storage: %s", err) - } + d.Set("total_instance_storage", v.InstanceStorageInfo.TotalSizeInGB) if v.InstanceStorageInfo.Disks != nil { diskList := make([]interface{}, len(v.InstanceStorageInfo.Disks)) for i, dk := range v.InstanceStorageInfo.Disks { @@ -339,35 +343,17 @@ func dataSourceAwsEc2InstanceTypeRead(d *schema.ResourceData, meta interface{}) } diskList[i] = disk } - if err := d.Set("instance_disks", diskList); err != nil { - return fmt.Errorf("error setting instance_disks: %s", err) - } + d.Set("instance_disks", diskList) } } - if err := d.Set("ebs_optimized_support", aws.StringValue(v.EbsInfo.EbsOptimizedSupport)); err != nil { - return fmt.Errorf("error setting ebs_optimized_support: %s", err) - } - if err := d.Set("ebs_encryption_support", aws.StringValue(v.EbsInfo.EncryptionSupport)); err != nil { - return fmt.Errorf("error setting ebs_encryption_support: %s", err) - } - if err := d.Set("network_performance", aws.StringValue(v.NetworkInfo.NetworkPerformance)); err != nil { - return fmt.Errorf("error setting network_performance: %s", err) - } - if err := d.Set("maximum_network_interfaces", aws.Int64Value(v.NetworkInfo.MaximumNetworkInterfaces)); err != nil { - return fmt.Errorf("error setting maximum_network_interfaces: %s", err) - } - if err := d.Set("maximum_ipv4_addresses_per_interface", aws.Int64Value(v.NetworkInfo.Ipv4AddressesPerInterface)); err != nil { - return fmt.Errorf("error setting ipv4_addresses_per_interface: %s", err) - } - if err := d.Set("maximum_ipv6_addresses_per_interface", aws.Int64Value(v.NetworkInfo.Ipv6AddressesPerInterface)); err != nil { - return fmt.Errorf("error setting ipv6_addresses_per_interface: %s", err) - } - if err := d.Set("ipv6_supported", aws.BoolValue(v.NetworkInfo.Ipv6Supported)); err != nil { - return fmt.Errorf("error setting ipv6_supported: %s", err) - } - if err := d.Set("ena_support", aws.StringValue(v.NetworkInfo.EnaSupport)); err != nil { - return fmt.Errorf("error setting ena_support: %s", err) - } + d.Set("ebs_optimized_support", v.EbsInfo.EbsOptimizedSupport) + d.Set("ebs_encryption_support", v.EbsInfo.EncryptionSupport) + d.Set("network_performance", v.NetworkInfo.NetworkPerformance) + d.Set("maximum_network_interfaces", v.NetworkInfo.MaximumNetworkInterfaces) + d.Set("maximum_ipv4_addresses_per_interface", v.NetworkInfo.Ipv4AddressesPerInterface) + d.Set("maximum_ipv6_addresses_per_interface", v.NetworkInfo.Ipv6AddressesPerInterface) + d.Set("ipv6_supported", v.NetworkInfo.Ipv6Supported) + d.Set("ena_support", v.NetworkInfo.EnaSupport) if v.GpuInfo != nil { gpuList := make([]interface{}, len(v.GpuInfo.Gpus)) for i, gp := range v.GpuInfo.Gpus { @@ -379,12 +365,8 @@ func dataSourceAwsEc2InstanceTypeRead(d *schema.ResourceData, meta interface{}) } gpuList[i] = gpu } - if err := d.Set("gpus", gpuList); err != nil { - return fmt.Errorf("error setting gpu: %s", err) - } - if err := d.Set("total_gpu_memory", aws.Int64Value(v.GpuInfo.TotalGpuMemoryInMiB)); err != nil { - return fmt.Errorf("error setting total_gpu_memory: %s", err) - } + d.Set("gpus", gpuList) + d.Set("total_gpu_memory", v.GpuInfo.TotalGpuMemoryInMiB) } if v.FpgaInfo != nil { fpgaList := make([]interface{}, len(v.FpgaInfo.Fpgas)) @@ -397,16 +379,10 @@ func dataSourceAwsEc2InstanceTypeRead(d *schema.ResourceData, meta interface{}) } fpgaList[i] = fpga } - if err := d.Set("fpgas", fpgaList); err != nil { - return fmt.Errorf("error setting fpga: %s", err) - } - if err := d.Set("total_fpga_memory", aws.Int64Value(v.FpgaInfo.TotalFpgaMemoryInMiB)); err != nil { - return fmt.Errorf("error setting total_fpga_memory: %s", err) - } - } - if err := d.Set("supported_placement_strategies", aws.StringValueSlice(v.PlacementGroupInfo.SupportedStrategies)); err != nil { - return fmt.Errorf("error setting supported_placement_strategies: %s", err) + d.Set("fpgas", fpgaList) + d.Set("total_fpga_memory", v.FpgaInfo.TotalFpgaMemoryInMiB) } + d.Set("supported_placement_strategies", v.PlacementGroupInfo.SupportedStrategies) if v.InferenceAcceleratorInfo != nil { acceleratorList := make([]interface{}, len(v.InferenceAcceleratorInfo.Accelerators)) for i, accl := range v.InferenceAcceleratorInfo.Accelerators { @@ -417,22 +393,12 @@ func dataSourceAwsEc2InstanceTypeRead(d *schema.ResourceData, meta interface{}) } acceleratorList[i] = accelerator } - if err := d.Set("accelerators", acceleratorList); err != nil { - return fmt.Errorf("error setting fpga: %s", err) - } - } - if err := d.Set("hibernation_supported", aws.BoolValue(v.HibernationSupported)); err != nil { - return fmt.Errorf("error setting hibernation_supported: %s", err) - } - if err := d.Set("burstable_performance_supported", aws.BoolValue(v.BurstablePerformanceSupported)); err != nil { - return fmt.Errorf("error setting burstable_performance_supported: %s", err) - } - if err := d.Set("dedicated_hosts_supported", aws.BoolValue(v.DedicatedHostsSupported)); err != nil { - return fmt.Errorf("error setting dedicated_hosts_supported: %s", err) - } - if err := d.Set("auto_recovery_supported", aws.BoolValue(v.AutoRecoverySupported)); err != nil { - return fmt.Errorf("error setting auto_recovery_supported: %s", err) + d.Set("accelerators", acceleratorList) } + d.Set("hibernation_supported", v.HibernationSupported) + d.Set("burstable_performance_supported", v.BurstablePerformanceSupported) + d.Set("dedicated_hosts_supported", v.DedicatedHostsSupported) + d.Set("auto_recovery_supported", v.AutoRecoverySupported) d.SetId(aws.StringValue(v.InstanceType)) return nil } From 4831ea971e6a44a1d3d2be39ebf6086fdebede18 Mon Sep 17 00:00:00 2001 From: Lilian Deloche Date: Sat, 3 Oct 2020 19:39:11 +0200 Subject: [PATCH 5/8] split tests, add missing attributes and update documentation --- aws/data_source_aws_ec2_instance_type.go | 57 ++++++ aws/data_source_aws_ec2_instance_type_test.go | 173 +++++++++++++----- .../docs/d/ec2_instance_type.html.markdown | 9 + 3 files changed, 190 insertions(+), 49 deletions(-) diff --git a/aws/data_source_aws_ec2_instance_type.go b/aws/data_source_aws_ec2_instance_type.go index 57843a440285..68c3a9424119 100644 --- a/aws/data_source_aws_ec2_instance_type.go +++ b/aws/data_source_aws_ec2_instance_type.go @@ -40,6 +40,12 @@ func dataSourceAwsEc2InstanceType() *schema.Resource { Elem: &schema.Schema{Type: schema.TypeString}, }, + "supported_virtualization_types": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "bare_metal": { Type: schema.TypeBool, Computed: true, @@ -136,11 +142,46 @@ func dataSourceAwsEc2InstanceType() *schema.Resource { Computed: true, }, + "ebs_performance_baseline_bandwidth": { + Type: schema.TypeInt, + Computed: true, + }, + + "ebs_performance_baseline_throughput": { + Type: schema.TypeFloat, + Computed: true, + }, + + "ebs_performance_baseline_iops": { + Type: schema.TypeInt, + Computed: true, + }, + + "ebs_performance_maximum_bandwidth": { + Type: schema.TypeInt, + Computed: true, + }, + + "ebs_performance_maximum_throughput": { + Type: schema.TypeFloat, + Computed: true, + }, + + "ebs_performance_maximum_iops": { + Type: schema.TypeInt, + Computed: true, + }, + "ebs_encryption_support": { Type: schema.TypeString, Computed: true, }, + "ebs_nvme_support": { + Type: schema.TypeString, + Computed: true, + }, + "network_performance": { Type: schema.TypeString, Computed: true, @@ -172,6 +213,11 @@ func dataSourceAwsEc2InstanceType() *schema.Resource { Computed: true, }, + "efa_supported": { + Type: schema.TypeBool, + Computed: true, + }, + "gpus": { Type: schema.TypeSet, Optional: true, @@ -320,6 +366,7 @@ func dataSourceAwsEc2InstanceTypeRead(d *schema.ResourceData, meta interface{}) d.Set("free_tier_eligible", v.FreeTierEligible) d.Set("supported_usages_classes", v.SupportedUsageClasses) d.Set("supported_root_device_types", v.SupportedRootDeviceTypes) + d.Set("supported_virtualization_types", v.SupportedVirtualizationTypes) d.Set("bare_metal", v.BareMetal) d.Set("hypervisor", v.Hypervisor) d.Set("supported_architectures", v.ProcessorInfo.SupportedArchitectures) @@ -347,13 +394,23 @@ func dataSourceAwsEc2InstanceTypeRead(d *schema.ResourceData, meta interface{}) } } d.Set("ebs_optimized_support", v.EbsInfo.EbsOptimizedSupport) + if v.EbsInfo.EbsOptimizedInfo != nil { + d.Set("ebs_performance_baseline_bandwidth", v.EbsInfo.EbsOptimizedInfo.BaselineBandwidthInMbps) + d.Set("ebs_performance_baseline_throughput", v.EbsInfo.EbsOptimizedInfo.BaselineThroughputInMBps) + d.Set("ebs_performance_baseline_iops", v.EbsInfo.EbsOptimizedInfo.BaselineIops) + d.Set("ebs_performance_maximum_bandwidth", v.EbsInfo.EbsOptimizedInfo.MaximumBandwidthInMbps) + d.Set("ebs_performance_maximum_throughput", v.EbsInfo.EbsOptimizedInfo.MaximumThroughputInMBps) + d.Set("ebs_performance_maximum_iops", v.EbsInfo.EbsOptimizedInfo.MaximumIops) + } d.Set("ebs_encryption_support", v.EbsInfo.EncryptionSupport) + d.Set("ebs_nvme_support", v.EbsInfo.NvmeSupport) d.Set("network_performance", v.NetworkInfo.NetworkPerformance) d.Set("maximum_network_interfaces", v.NetworkInfo.MaximumNetworkInterfaces) d.Set("maximum_ipv4_addresses_per_interface", v.NetworkInfo.Ipv4AddressesPerInterface) d.Set("maximum_ipv6_addresses_per_interface", v.NetworkInfo.Ipv6AddressesPerInterface) d.Set("ipv6_supported", v.NetworkInfo.Ipv6Supported) d.Set("ena_support", v.NetworkInfo.EnaSupport) + d.Set("efa_supported", v.NetworkInfo.EfaSupported) if v.GpuInfo != nil { gpuList := make([]interface{}, len(v.GpuInfo.Gpus)) for i, gp := range v.GpuInfo.Gpus { diff --git a/aws/data_source_aws_ec2_instance_type_test.go b/aws/data_source_aws_ec2_instance_type_test.go index a80261f62b26..c611d4d4bd5e 100644 --- a/aws/data_source_aws_ec2_instance_type_test.go +++ b/aws/data_source_aws_ec2_instance_type_test.go @@ -1,100 +1,175 @@ package aws import ( - "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "testing" ) -func TestAccDataSourceAwsEc2InstanceType_attributes(t *testing.T) { +func TestAccDataSourceAwsEc2InstanceType_basic(t *testing.T) { + resourceBasic := "data.aws_ec2_instance_type.basic" + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceEc2InstanceTypeBasic, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceBasic, "instance_type", "t2.micro"), + resource.TestCheckResourceAttr(resourceBasic, "current_generation", "true"), + resource.TestCheckResourceAttr(resourceBasic, "free_tier_eligible", "true"), + resource.TestCheckResourceAttr(resourceBasic, "supported_usages_classes.#", "2"), + resource.TestCheckResourceAttr(resourceBasic, "supported_usages_classes.0", "on-demand"), + resource.TestCheckResourceAttr(resourceBasic, "supported_usages_classes.1", "spot"), + resource.TestCheckResourceAttr(resourceBasic, "supported_root_device_types.#", "1"), + resource.TestCheckResourceAttr(resourceBasic, "supported_root_device_types.0", "ebs"), + resource.TestCheckResourceAttr(resourceBasic, "supported_virtualization_types.#", "1"), + resource.TestCheckResourceAttr(resourceBasic, "supported_virtualization_types.0", "hvm"), + resource.TestCheckResourceAttr(resourceBasic, "bare_metal", "false"), + resource.TestCheckResourceAttr(resourceBasic, "hypervisor", "xen"), + resource.TestCheckResourceAttr(resourceBasic, "supported_architectures.#", "2"), + resource.TestCheckResourceAttr(resourceBasic, "supported_architectures.0", "i386"), + resource.TestCheckResourceAttr(resourceBasic, "supported_architectures.1", "x86_64"), + resource.TestCheckResourceAttr(resourceBasic, "sustained_clock_speed", "2.5"), + resource.TestCheckResourceAttr(resourceBasic, "default_vcpus", "1"), + resource.TestCheckResourceAttr(resourceBasic, "default_cores", "1"), + resource.TestCheckResourceAttr(resourceBasic, "default_threads_per_core", "1"), + resource.TestCheckResourceAttr(resourceBasic, "valid_cores.#", "1"), + resource.TestCheckResourceAttr(resourceBasic, "valid_cores.#", "1"), + resource.TestCheckResourceAttr(resourceBasic, "valid_threads_per_core.#", "1"), + resource.TestCheckResourceAttr(resourceBasic, "valid_threads_per_core.0", "1"), + resource.TestCheckResourceAttr(resourceBasic, "memory_size", "1024"), + resource.TestCheckResourceAttr(resourceBasic, "instance_storage_supported", "false"), + resource.TestCheckResourceAttr(resourceBasic, "ebs_optimized_support", "unsupported"), + resource.TestCheckResourceAttr(resourceBasic, "ebs_encryption_support", "supported"), + resource.TestCheckResourceAttr(resourceBasic, "ebs_nvme_support", "unsupported"), + resource.TestCheckResourceAttr(resourceBasic, "network_performance", "Low to Moderate"), + resource.TestCheckResourceAttr(resourceBasic, "maximum_network_interfaces", "2"), + resource.TestCheckResourceAttr(resourceBasic, "maximum_ipv4_addresses_per_interface", "2"), + resource.TestCheckResourceAttr(resourceBasic, "maximum_ipv6_addresses_per_interface", "2"), + resource.TestCheckResourceAttr(resourceBasic, "ipv6_supported", "true"), + resource.TestCheckResourceAttr(resourceBasic, "ena_support", "unsupported"), + resource.TestCheckResourceAttr(resourceBasic, "efa_supported", "false"), + resource.TestCheckResourceAttr(resourceBasic, "supported_placement_strategies.#", "2"), + resource.TestCheckResourceAttr(resourceBasic, "supported_placement_strategies.0", "partition"), + resource.TestCheckResourceAttr(resourceBasic, "supported_placement_strategies.1", "spread"), + ), + }, + }, + }) +} + +func TestAccDataSourceAwsEc2InstanceType_metal(t *testing.T) { resourceMetal := "data.aws_ec2_instance_type.metal" - resourceGpu := "data.aws_ec2_instance_type.gpu" - resourceFpga := "data.aws_ec2_instance_type.fpga" - resourceAccelerator := "data.aws_ec2_instance_type.accelerator" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceEc2InstanceType, + Config: testAccDataSourceEc2InstanceTypeMetal, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceMetal, "auto_recovery_supported", "false"), - resource.TestCheckResourceAttr(resourceMetal, "bare_metal", "true"), - resource.TestCheckResourceAttr(resourceMetal, "burstable_performance_supported", "false"), - resource.TestCheckResourceAttr(resourceMetal, "current_generation", "true"), - resource.TestCheckResourceAttr(resourceMetal, "dedicated_hosts_supported", "true"), - resource.TestCheckResourceAttr(resourceMetal, "default_vcpus", "96"), - resource.TestCheckResourceAttr(resourceMetal, "ebs_encryption_support", "supported"), - resource.TestCheckResourceAttr(resourceMetal, "ebs_optimized_support", "default"), - resource.TestCheckResourceAttr(resourceMetal, "ena_support", "required"), - resource.TestCheckResourceAttr(resourceMetal, "free_tier_eligible", "false"), - resource.TestCheckResourceAttr(resourceMetal, "hibernation_supported", "false"), - resource.TestCheckResourceAttr(resourceMetal, "instance_storage_supported", "true"), - resource.TestCheckResourceAttr(resourceMetal, "instance_type", "i3en.metal"), - resource.TestCheckResourceAttr(resourceMetal, "ipv6_supported", "true"), - resource.TestCheckResourceAttr(resourceMetal, "maximum_ipv4_addresses_per_interface", "50"), - resource.TestCheckResourceAttr(resourceMetal, "maximum_ipv6_addresses_per_interface", "50"), - resource.TestCheckResourceAttr(resourceMetal, "maximum_network_interfaces", "15"), - resource.TestCheckResourceAttr(resourceMetal, "memory_size", "786432"), - resource.TestCheckResourceAttr(resourceMetal, "network_performance", "100 Gigabit"), - resource.TestCheckResourceAttr(resourceMetal, "supported_architectures.#", "1"), - resource.TestCheckResourceAttr(resourceMetal, "supported_architectures.0", "x86_64"), - resource.TestCheckResourceAttr(resourceMetal, "supported_placement_strategies.#", "3"), - resource.TestCheckResourceAttr(resourceMetal, "supported_placement_strategies.0", "cluster"), - resource.TestCheckResourceAttr(resourceMetal, "supported_placement_strategies.1", "partition"), - resource.TestCheckResourceAttr(resourceMetal, "supported_placement_strategies.2", "spread"), - resource.TestCheckResourceAttr(resourceMetal, "supported_root_device_types.#", "1"), - resource.TestCheckResourceAttr(resourceMetal, "supported_root_device_types.0", "ebs"), - resource.TestCheckResourceAttr(resourceMetal, "supported_usages_classes.#", "2"), - resource.TestCheckResourceAttr(resourceMetal, "supported_usages_classes.0", "on-demand"), - resource.TestCheckResourceAttr(resourceMetal, "supported_usages_classes.1", "spot"), - resource.TestCheckResourceAttr(resourceMetal, "sustained_clock_speed", "3.1"), + resource.TestCheckResourceAttr(resourceMetal, "ebs_performance_baseline_bandwidth", "19000"), + resource.TestCheckResourceAttr(resourceMetal, "ebs_performance_baseline_throughput", "2375"), + resource.TestCheckResourceAttr(resourceMetal, "ebs_performance_baseline_iops", "80000"), + resource.TestCheckResourceAttr(resourceMetal, "ebs_performance_maximum_bandwidth", "19000"), + resource.TestCheckResourceAttr(resourceMetal, "ebs_performance_maximum_throughput", "2375"), + resource.TestCheckResourceAttr(resourceMetal, "ebs_performance_maximum_iops", "80000"), resource.TestCheckResourceAttr(resourceMetal, "total_instance_storage", "60000"), resource.TestCheckResourceAttr(resourceMetal, "instance_disks.#", "1"), resource.TestCheckResourceAttr(resourceMetal, "instance_disks.0.count", "8"), resource.TestCheckResourceAttr(resourceMetal, "instance_disks.0.size", "7500"), resource.TestCheckResourceAttr(resourceMetal, "instance_disks.0.type", "ssd"), - resource.TestCheckResourceAttr(resourceGpu, "total_gpu_memory", "4096"), - resource.TestCheckResourceAttr(resourceGpu, "hypervisor", "xen"), + ), + }, + }, + }) +} + +func TestAccDataSourceAwsEc2InstanceType_gpu(t *testing.T) { + resourceGpu := "data.aws_ec2_instance_type.gpu" + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceEc2InstanceTypeGpu, + Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceGpu, "gpus.#", "1"), resource.TestCheckResourceAttr(resourceGpu, "gpus.0.count", "1"), resource.TestCheckResourceAttr(resourceGpu, "gpus.0.memory_size", "4096"), resource.TestCheckResourceAttr(resourceGpu, "gpus.0.manufacturer", "NVIDIA"), resource.TestCheckResourceAttr(resourceGpu, "gpus.0.name", "K520"), - resource.TestCheckResourceAttr(resourceGpu, "valid_threads_per_core.#", "2"), - resource.TestCheckResourceAttr(resourceGpu, "valid_threads_per_core.0", "1"), - resource.TestCheckResourceAttr(resourceGpu, "valid_threads_per_core.1", "2"), - resource.TestCheckResourceAttr(resourceGpu, "default_threads_per_core", "2"), - resource.TestCheckResourceAttr(resourceGpu, "default_cores", "4"), - resource.TestCheckResourceAttr(resourceGpu, "default_vcpus", "8"), + ), + }, + }, + }) +} + +func TestAccDataSourceAwsEc2InstanceType_fpga(t *testing.T) { + resourceFpga := "data.aws_ec2_instance_type.fpga" + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceEc2InstanceTypeFgpa, + Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceFpga, "fpgas.#", "1"), resource.TestCheckResourceAttr(resourceFpga, "fpgas.0.name", "Virtex UltraScale (VU9P)"), resource.TestCheckResourceAttr(resourceFpga, "fpgas.0.manufacturer", "Xilinx"), resource.TestCheckResourceAttr(resourceFpga, "fpgas.0.count", "1"), resource.TestCheckResourceAttr(resourceFpga, "fpgas.0.memory_size", "65536"), resource.TestCheckResourceAttr(resourceFpga, "total_fpga_memory", "65536"), + ), + }, + }, + }) +} + +func TestAccDataSourceAwsEc2InstanceType_accelerator(t *testing.T) { + resourceAccelerator := "data.aws_ec2_instance_type.accelerator" + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceEc2InstanceTypeAccelerator, + Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceAccelerator, "accelerators.#", "1"), resource.TestCheckResourceAttr(resourceAccelerator, "accelerators.0.count", "1"), resource.TestCheckResourceAttr(resourceAccelerator, "accelerators.0.name", "Inferentia"), resource.TestCheckResourceAttr(resourceAccelerator, "accelerators.0.manufacturer", "AWS"), - resource.TestCheckResourceAttr(resourceAccelerator, "valid_cores.#", "1"), - resource.TestCheckResourceAttr(resourceAccelerator, "valid_cores.0", "2"), ), }, }, }) } -const testAccDataSourceEc2InstanceType = ` +const testAccDataSourceEc2InstanceTypeBasic = ` +data "aws_ec2_instance_type" "basic" { + instance_type="t2.micro" +} +` + +const testAccDataSourceEc2InstanceTypeMetal = ` data "aws_ec2_instance_type" "metal" { instance_type="i3en.metal" } +` + +const testAccDataSourceEc2InstanceTypeGpu = ` data "aws_ec2_instance_type" "gpu" { instance_type="g2.2xlarge" } +` + +const testAccDataSourceEc2InstanceTypeFgpa = ` data "aws_ec2_instance_type" "fpga" { instance_type="f1.2xlarge" } +` + +const testAccDataSourceEc2InstanceTypeAccelerator = ` + data "aws_ec2_instance_type" "accelerator" { instance_type="inf1.xlarge" } diff --git a/website/docs/d/ec2_instance_type.html.markdown b/website/docs/d/ec2_instance_type.html.markdown index 932f6b11a09a..48e65a310cc7 100644 --- a/website/docs/d/ec2_instance_type.html.markdown +++ b/website/docs/d/ec2_instance_type.html.markdown @@ -44,8 +44,16 @@ In addition to the argument above, the following attributes are exported: * `default_threads_per_core` - The default number of threads per core for the instance type. * `default_vcpus` - The default number of vCPUs for the instance type. * `dedicated_hosts_supported` - `true` if Dedicated Hosts are supported on the instance type. +* `ebs_performance_baseline_bandwidth` - The baseline bandwidth performance for an EBS-optimized instance type, in Mbps. +* `ebs_performance_baseline_iops` - The baseline input/output storage operations per seconds for an EBS-optimized instance type. +* `ebs_performance_baseline_throughput` - The baseline throughput performance for an EBS-optimized instance type, in MBps. +* `ebs_performance_maximum_bandwidth` - The maximum bandwidth performance for an EBS-optimized instance type, in Mbps. +* `ebs_performance_maximum_iops` - The maximum input/output storage operations per second for an EBS-optimized instance type. +* `ebs_performance_maximum_throughput` - The maximum throughput performance for an EBS-optimized instance type, in MBps. * `ebs_encryption_support` - Indicates whether Amazon EBS encryption is supported. +* `ebs_nvme_support` - Indicates whether non-volatile memory express (NVMe) is supported. * `ebs_optimized_support` - Indicates that the instance type is Amazon EBS-optimized. +* `efa_supported` - Indicates whether Elastic Fabric Adapter (EFA) is supported. * `ena_support` - Indicates whether Elastic Network Adapter (ENA) is supported. * `fpgas` - Describes the FPGA accelerator settings for the instance type. * `fpgas.#.count` - The count of FPGA accelerators for the instance type. @@ -75,6 +83,7 @@ In addition to the argument above, the following attributes are exported: * `supported_placement_strategies` - A list of supported placement groups types. * `supported_root_device_types` - Indicates the supported root device types. * `supported_usages_classes` - Indicates whether the instance type is offered for spot or On-Demand. +* `supported_virtualization_types` - The supported virtualization types. * `sustained_clock_speed` - The speed of the processor, in GHz. * `total_fpga_memory` - The total memory of all FPGA accelerators for the instance type (in MiB). * `total_gpu_memory` - The total size of the memory for the GPU accelerators for the instance type (in MiB). From 5de95e4d12678fbd41bbec6b865e316eb7ace5be Mon Sep 17 00:00:00 2001 From: Lilian Deloche Date: Wed, 7 Oct 2020 19:13:00 +0200 Subject: [PATCH 6/8] alphabetical sort structures, docs, tests and set --- aws/data_source_aws_ec2_instance_type.go | 420 +++++++++--------- aws/data_source_aws_ec2_instance_type_test.go | 73 +-- .../docs/d/ec2_instance_type.html.markdown | 18 +- 3 files changed, 257 insertions(+), 254 deletions(-) diff --git a/aws/data_source_aws_ec2_instance_type.go b/aws/data_source_aws_ec2_instance_type.go index 68c3a9424119..3649a67f5973 100644 --- a/aws/data_source_aws_ec2_instance_type.go +++ b/aws/data_source_aws_ec2_instance_type.go @@ -13,63 +13,28 @@ func dataSourceAwsEc2InstanceType() *schema.Resource { Read: dataSourceAwsEc2InstanceTypeRead, Schema: map[string]*schema.Schema{ - "instance_type": { - Type: schema.TypeString, - Required: true, - }, - - "current_generation": { - Type: schema.TypeBool, - Computed: true, - }, - - "free_tier_eligible": { + "auto_recovery_supported": { Type: schema.TypeBool, Computed: true, }, - "supported_usages_classes": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - - "supported_root_device_types": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - - "supported_virtualization_types": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "bare_metal": { Type: schema.TypeBool, Computed: true, }, - "hypervisor": { - Type: schema.TypeString, - Computed: true, - Optional: true, - }, - - "supported_architectures": { - Type: schema.TypeList, + "burstable_performance_supported": { + Type: schema.TypeBool, Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, }, - "sustained_clock_speed": { - Type: schema.TypeFloat, + "current_generation": { + Type: schema.TypeBool, Computed: true, }, - "default_vcpus": { - Type: schema.TypeInt, + "dedicated_hosts_supported": { + Type: schema.TypeBool, Computed: true, }, @@ -85,56 +50,19 @@ func dataSourceAwsEc2InstanceType() *schema.Resource { Optional: true, }, - "valid_cores": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeInt}, - }, - - "valid_threads_per_core": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeInt}, - }, - - "memory_size": { + "default_vcpus": { Type: schema.TypeInt, Computed: true, }, - "instance_storage_supported": { - Type: schema.TypeBool, - Computed: true, - }, - - "total_instance_storage": { - Type: schema.TypeInt, + "ebs_encryption_support": { + Type: schema.TypeString, Computed: true, - Optional: true, }, - "instance_disks": { - Type: schema.TypeSet, + "ebs_nvme_support": { + Type: schema.TypeString, Computed: true, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "size": { - Type: schema.TypeInt, - Computed: true, - }, - - "count": { - Type: schema.TypeInt, - Computed: true, - }, - - "type": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, }, "ebs_optimized_support": { @@ -172,48 +100,46 @@ func dataSourceAwsEc2InstanceType() *schema.Resource { Computed: true, }, - "ebs_encryption_support": { - Type: schema.TypeString, - Computed: true, - }, - - "ebs_nvme_support": { - Type: schema.TypeString, + "efa_supported": { + Type: schema.TypeBool, Computed: true, }, - "network_performance": { + "ena_support": { Type: schema.TypeString, Computed: true, }, - "maximum_network_interfaces": { - Type: schema.TypeInt, - Computed: true, - }, - - "maximum_ipv4_addresses_per_interface": { - Type: schema.TypeInt, - Computed: true, - }, - - "maximum_ipv6_addresses_per_interface": { - Type: schema.TypeInt, + "fpgas": { + Type: schema.TypeSet, Computed: true, Optional: true, - }, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "count": { + Type: schema.TypeInt, + Computed: true, + }, - "ipv6_supported": { - Type: schema.TypeBool, - Computed: true, - }, + "manufacturer": { + Type: schema.TypeString, + Computed: true, + }, - "ena_support": { - Type: schema.TypeString, - Computed: true, + "memory_size": { + Type: schema.TypeInt, + Computed: true, + }, + + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, }, - "efa_supported": { + "free_tier_eligible": { Type: schema.TypeBool, Computed: true, }, @@ -224,8 +150,8 @@ func dataSourceAwsEc2InstanceType() *schema.Resource { Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, + "count": { + Type: schema.TypeInt, Computed: true, }, @@ -234,31 +160,41 @@ func dataSourceAwsEc2InstanceType() *schema.Resource { Computed: true, }, - "count": { + "memory_size": { Type: schema.TypeInt, Computed: true, }, - "memory_size": { - Type: schema.TypeInt, + "name": { + Type: schema.TypeString, Computed: true, }, }, }, }, - "total_gpu_memory": { - Type: schema.TypeInt, + "hibernation_supported": { + Type: schema.TypeBool, + Computed: true, + }, + + "hypervisor": { + Type: schema.TypeString, Computed: true, Optional: true, }, - "fpgas": { + "inference_accelerators": { Type: schema.TypeSet, Computed: true, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + "count": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { Type: schema.TypeString, Computed: true, @@ -268,74 +204,138 @@ func dataSourceAwsEc2InstanceType() *schema.Resource { Type: schema.TypeString, Computed: true, }, + }, + }, + }, + "instance_disks": { + Type: schema.TypeSet, + Computed: true, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ "count": { Type: schema.TypeInt, Computed: true, }, - "memory_size": { + "size": { Type: schema.TypeInt, Computed: true, }, + + "type": { + Type: schema.TypeString, + Computed: true, + }, }, }, }, - "total_fpga_memory": { + "instance_storage_supported": { + Type: schema.TypeBool, + Computed: true, + }, + + "instance_type": { + Type: schema.TypeString, + Required: true, + }, + + "ipv6_supported": { + Type: schema.TypeBool, + Computed: true, + }, + + "maximum_ipv4_addresses_per_interface": { + Type: schema.TypeInt, + Computed: true, + }, + + "maximum_ipv6_addresses_per_interface": { Type: schema.TypeInt, Computed: true, Optional: true, }, + "maximum_network_interfaces": { + Type: schema.TypeInt, + Computed: true, + }, + + "memory_size": { + Type: schema.TypeInt, + Computed: true, + }, + + "network_performance": { + Type: schema.TypeString, + Computed: true, + }, + + "supported_architectures": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "supported_placement_strategies": { Type: schema.TypeList, Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, }, - "accelerators": { - Type: schema.TypeSet, + "supported_root_device_types": { + Type: schema.TypeList, Computed: true, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Computed: true, - }, + Elem: &schema.Schema{Type: schema.TypeString}, + }, - "manufacturer": { - Type: schema.TypeString, - Computed: true, - }, + "supported_usages_classes": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, - "count": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, + "supported_virtualization_types": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, }, - "hibernation_supported": { - Type: schema.TypeBool, + "sustained_clock_speed": { + Type: schema.TypeFloat, Computed: true, }, - "burstable_performance_supported": { - Type: schema.TypeBool, + "total_fpga_memory": { + Type: schema.TypeInt, Computed: true, + Optional: true, }, - "dedicated_hosts_supported": { - Type: schema.TypeBool, + "total_gpu_memory": { + Type: schema.TypeInt, Computed: true, + Optional: true, }, - "auto_recovery_supported": { - Type: schema.TypeBool, + "total_instance_storage": { + Type: schema.TypeInt, + Computed: true, + Optional: true, + }, + + "valid_cores": { + Type: schema.TypeList, Computed: true, + Elem: &schema.Schema{Type: schema.TypeInt}, + }, + + "valid_threads_per_core": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeInt}, }, }, } @@ -361,38 +361,16 @@ func dataSourceAwsEc2InstanceTypeRead(d *schema.ResourceData, meta interface{}) return fmt.Errorf("multiple instance types found for type %s", instanceType) } v := resp.InstanceTypes[0] - d.Set("instance_type", v.InstanceType) - d.Set("current_generation", v.CurrentGeneration) - d.Set("free_tier_eligible", v.FreeTierEligible) - d.Set("supported_usages_classes", v.SupportedUsageClasses) - d.Set("supported_root_device_types", v.SupportedRootDeviceTypes) - d.Set("supported_virtualization_types", v.SupportedVirtualizationTypes) + d.Set("auto_recovery_supported", v.AutoRecoverySupported) d.Set("bare_metal", v.BareMetal) - d.Set("hypervisor", v.Hypervisor) - d.Set("supported_architectures", v.ProcessorInfo.SupportedArchitectures) - d.Set("sustained_clock_speed", v.ProcessorInfo.SustainedClockSpeedInGhz) - d.Set("default_vcpus", v.VCpuInfo.DefaultVCpus) + d.Set("burstable_performance_supported", v.BurstablePerformanceSupported) + d.Set("current_generation", v.CurrentGeneration) + d.Set("dedicated_hosts_supported", v.DedicatedHostsSupported) d.Set("default_cores", v.VCpuInfo.DefaultCores) d.Set("default_threads_per_core", v.VCpuInfo.DefaultThreadsPerCore) - d.Set("valid_threads_per_core", v.VCpuInfo.ValidThreadsPerCore) - d.Set("valid_cores", v.VCpuInfo.ValidCores) - d.Set("memory_size", v.MemoryInfo.SizeInMiB) - d.Set("instance_storage_supported", v.InstanceStorageSupported) - if v.InstanceStorageInfo != nil { - d.Set("total_instance_storage", v.InstanceStorageInfo.TotalSizeInGB) - if v.InstanceStorageInfo.Disks != nil { - diskList := make([]interface{}, len(v.InstanceStorageInfo.Disks)) - for i, dk := range v.InstanceStorageInfo.Disks { - disk := map[string]interface{}{ - "size": aws.Int64Value(dk.SizeInGB), - "count": aws.Int64Value(dk.Count), - "type": aws.StringValue(dk.Type), - } - diskList[i] = disk - } - d.Set("instance_disks", diskList) - } - } + d.Set("default_vcpus", v.VCpuInfo.DefaultVCpus) + d.Set("ebs_encryption_support", v.EbsInfo.EncryptionSupport) + d.Set("ebs_nvme_support", v.EbsInfo.NvmeSupport) d.Set("ebs_optimized_support", v.EbsInfo.EbsOptimizedSupport) if v.EbsInfo.EbsOptimizedInfo != nil { d.Set("ebs_performance_baseline_bandwidth", v.EbsInfo.EbsOptimizedInfo.BaselineBandwidthInMbps) @@ -402,60 +380,82 @@ func dataSourceAwsEc2InstanceTypeRead(d *schema.ResourceData, meta interface{}) d.Set("ebs_performance_maximum_throughput", v.EbsInfo.EbsOptimizedInfo.MaximumThroughputInMBps) d.Set("ebs_performance_maximum_iops", v.EbsInfo.EbsOptimizedInfo.MaximumIops) } - d.Set("ebs_encryption_support", v.EbsInfo.EncryptionSupport) - d.Set("ebs_nvme_support", v.EbsInfo.NvmeSupport) - d.Set("network_performance", v.NetworkInfo.NetworkPerformance) - d.Set("maximum_network_interfaces", v.NetworkInfo.MaximumNetworkInterfaces) - d.Set("maximum_ipv4_addresses_per_interface", v.NetworkInfo.Ipv4AddressesPerInterface) - d.Set("maximum_ipv6_addresses_per_interface", v.NetworkInfo.Ipv6AddressesPerInterface) - d.Set("ipv6_supported", v.NetworkInfo.Ipv6Supported) - d.Set("ena_support", v.NetworkInfo.EnaSupport) d.Set("efa_supported", v.NetworkInfo.EfaSupported) - if v.GpuInfo != nil { - gpuList := make([]interface{}, len(v.GpuInfo.Gpus)) - for i, gp := range v.GpuInfo.Gpus { - gpu := map[string]interface{}{ - "manufacturer": aws.StringValue(gp.Manufacturer), - "name": aws.StringValue(gp.Name), - "count": aws.Int64Value(gp.Count), - "memory_size": aws.Int64Value(gp.MemoryInfo.SizeInMiB), - } - gpuList[i] = gpu - } - d.Set("gpus", gpuList) - d.Set("total_gpu_memory", v.GpuInfo.TotalGpuMemoryInMiB) - } + d.Set("ena_support", v.NetworkInfo.EnaSupport) if v.FpgaInfo != nil { fpgaList := make([]interface{}, len(v.FpgaInfo.Fpgas)) for i, fpg := range v.FpgaInfo.Fpgas { fpga := map[string]interface{}{ - "manufacturer": aws.StringValue(fpg.Manufacturer), - "name": aws.StringValue(fpg.Name), "count": aws.Int64Value(fpg.Count), + "manufacturer": aws.StringValue(fpg.Manufacturer), "memory_size": aws.Int64Value(fpg.MemoryInfo.SizeInMiB), + "name": aws.StringValue(fpg.Name), } fpgaList[i] = fpga } d.Set("fpgas", fpgaList) d.Set("total_fpga_memory", v.FpgaInfo.TotalFpgaMemoryInMiB) } - d.Set("supported_placement_strategies", v.PlacementGroupInfo.SupportedStrategies) + d.Set("free_tier_eligible", v.FreeTierEligible) + if v.GpuInfo != nil { + gpuList := make([]interface{}, len(v.GpuInfo.Gpus)) + for i, gp := range v.GpuInfo.Gpus { + gpu := map[string]interface{}{ + "count": aws.Int64Value(gp.Count), + "manufacturer": aws.StringValue(gp.Manufacturer), + "memory_size": aws.Int64Value(gp.MemoryInfo.SizeInMiB), + "name": aws.StringValue(gp.Name), + } + gpuList[i] = gpu + } + d.Set("gpus", gpuList) + d.Set("total_gpu_memory", v.GpuInfo.TotalGpuMemoryInMiB) + } + d.Set("hibernation_supported", v.HibernationSupported) + d.Set("hypervisor", v.Hypervisor) if v.InferenceAcceleratorInfo != nil { acceleratorList := make([]interface{}, len(v.InferenceAcceleratorInfo.Accelerators)) for i, accl := range v.InferenceAcceleratorInfo.Accelerators { accelerator := map[string]interface{}{ + "count": aws.Int64Value(accl.Count), "manufacturer": aws.StringValue(accl.Manufacturer), "name": aws.StringValue(accl.Name), - "count": aws.Int64Value(accl.Count), } acceleratorList[i] = accelerator } - d.Set("accelerators", acceleratorList) + d.Set("inference_accelerators", acceleratorList) } - d.Set("hibernation_supported", v.HibernationSupported) - d.Set("burstable_performance_supported", v.BurstablePerformanceSupported) - d.Set("dedicated_hosts_supported", v.DedicatedHostsSupported) - d.Set("auto_recovery_supported", v.AutoRecoverySupported) + if v.InstanceStorageInfo != nil { + if v.InstanceStorageInfo.Disks != nil { + diskList := make([]interface{}, len(v.InstanceStorageInfo.Disks)) + for i, dk := range v.InstanceStorageInfo.Disks { + disk := map[string]interface{}{ + "count": aws.Int64Value(dk.Count), + "size": aws.Int64Value(dk.SizeInGB), + "type": aws.StringValue(dk.Type), + } + diskList[i] = disk + } + d.Set("instance_disks", diskList) + } + d.Set("total_instance_storage", v.InstanceStorageInfo.TotalSizeInGB) + } + d.Set("instance_storage_supported", v.InstanceStorageSupported) + d.Set("instance_type", v.InstanceType) + d.Set("ipv6_supported", v.NetworkInfo.Ipv6Supported) + d.Set("maximum_ipv4_addresses_per_interface", v.NetworkInfo.Ipv4AddressesPerInterface) + d.Set("maximum_ipv6_addresses_per_interface", v.NetworkInfo.Ipv6AddressesPerInterface) + d.Set("maximum_network_interfaces", v.NetworkInfo.MaximumNetworkInterfaces) + d.Set("memory_size", v.MemoryInfo.SizeInMiB) + d.Set("network_performance", v.NetworkInfo.NetworkPerformance) + d.Set("supported_architectures", v.ProcessorInfo.SupportedArchitectures) + d.Set("supported_placement_strategies", v.PlacementGroupInfo.SupportedStrategies) + d.Set("supported_root_device_types", v.SupportedRootDeviceTypes) + d.Set("supported_usages_classes", v.SupportedUsageClasses) + d.Set("supported_virtualization_types", v.SupportedVirtualizationTypes) + d.Set("sustained_clock_speed", v.ProcessorInfo.SustainedClockSpeedInGhz) + d.Set("valid_cores", v.VCpuInfo.ValidCores) + d.Set("valid_threads_per_core", v.VCpuInfo.ValidThreadsPerCore) d.SetId(aws.StringValue(v.InstanceType)) return nil } diff --git a/aws/data_source_aws_ec2_instance_type_test.go b/aws/data_source_aws_ec2_instance_type_test.go index c611d4d4bd5e..8b85513b6c13 100644 --- a/aws/data_source_aws_ec2_instance_type_test.go +++ b/aws/data_source_aws_ec2_instance_type_test.go @@ -14,44 +14,48 @@ func TestAccDataSourceAwsEc2InstanceType_basic(t *testing.T) { { Config: testAccDataSourceEc2InstanceTypeBasic, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceBasic, "instance_type", "t2.micro"), + resource.TestCheckResourceAttr(resourceBasic, "auto_recovery_supported", "true"), + resource.TestCheckResourceAttr(resourceBasic, "bare_metal", "false"), + resource.TestCheckResourceAttr(resourceBasic, "burstable_performance_supported", "true"), resource.TestCheckResourceAttr(resourceBasic, "current_generation", "true"), + resource.TestCheckResourceAttr(resourceBasic, "dedicated_hosts_supported", "false"), + resource.TestCheckResourceAttr(resourceBasic, "default_cores", "1"), + resource.TestCheckResourceAttr(resourceBasic, "default_threads_per_core", "1"), + resource.TestCheckResourceAttr(resourceBasic, "default_vcpus", "1"), + resource.TestCheckResourceAttr(resourceBasic, "ebs_encryption_support", "supported"), + resource.TestCheckResourceAttr(resourceBasic, "ebs_nvme_support", "unsupported"), + resource.TestCheckResourceAttr(resourceBasic, "ebs_optimized_support", "unsupported"), + resource.TestCheckResourceAttr(resourceBasic, "efa_supported", "false"), + resource.TestCheckResourceAttr(resourceBasic, "ena_support", "unsupported"), resource.TestCheckResourceAttr(resourceBasic, "free_tier_eligible", "true"), + resource.TestCheckResourceAttr(resourceBasic, "hibernation_supported", "true"), + resource.TestCheckResourceAttr(resourceBasic, "hypervisor", "xen"), + resource.TestCheckResourceAttr(resourceBasic, "instance_storage_supported", "false"), + resource.TestCheckResourceAttr(resourceBasic, "instance_type", "t2.micro"), + resource.TestCheckResourceAttr(resourceBasic, "ipv6_supported", "true"), + resource.TestCheckResourceAttr(resourceBasic, "maximum_ipv4_addresses_per_interface", "2"), + resource.TestCheckResourceAttr(resourceBasic, "maximum_ipv6_addresses_per_interface", "2"), + resource.TestCheckResourceAttr(resourceBasic, "maximum_network_interfaces", "2"), + resource.TestCheckResourceAttr(resourceBasic, "memory_size", "1024"), + resource.TestCheckResourceAttr(resourceBasic, "network_performance", "Low to Moderate"), + resource.TestCheckResourceAttr(resourceBasic, "supported_architectures.#", "2"), + resource.TestCheckResourceAttr(resourceBasic, "supported_architectures.0", "i386"), + resource.TestCheckResourceAttr(resourceBasic, "supported_architectures.1", "x86_64"), + resource.TestCheckResourceAttr(resourceBasic, "supported_placement_strategies.#", "2"), + resource.TestCheckResourceAttr(resourceBasic, "supported_placement_strategies.0", "partition"), + resource.TestCheckResourceAttr(resourceBasic, "supported_placement_strategies.1", "spread"), + resource.TestCheckResourceAttr(resourceBasic, "supported_root_device_types.#", "1"), + resource.TestCheckResourceAttr(resourceBasic, "supported_root_device_types.0", "ebs"), resource.TestCheckResourceAttr(resourceBasic, "supported_usages_classes.#", "2"), resource.TestCheckResourceAttr(resourceBasic, "supported_usages_classes.0", "on-demand"), resource.TestCheckResourceAttr(resourceBasic, "supported_usages_classes.1", "spot"), - resource.TestCheckResourceAttr(resourceBasic, "supported_root_device_types.#", "1"), - resource.TestCheckResourceAttr(resourceBasic, "supported_root_device_types.0", "ebs"), resource.TestCheckResourceAttr(resourceBasic, "supported_virtualization_types.#", "1"), resource.TestCheckResourceAttr(resourceBasic, "supported_virtualization_types.0", "hvm"), - resource.TestCheckResourceAttr(resourceBasic, "bare_metal", "false"), - resource.TestCheckResourceAttr(resourceBasic, "hypervisor", "xen"), - resource.TestCheckResourceAttr(resourceBasic, "supported_architectures.#", "2"), - resource.TestCheckResourceAttr(resourceBasic, "supported_architectures.0", "i386"), - resource.TestCheckResourceAttr(resourceBasic, "supported_architectures.1", "x86_64"), resource.TestCheckResourceAttr(resourceBasic, "sustained_clock_speed", "2.5"), - resource.TestCheckResourceAttr(resourceBasic, "default_vcpus", "1"), - resource.TestCheckResourceAttr(resourceBasic, "default_cores", "1"), - resource.TestCheckResourceAttr(resourceBasic, "default_threads_per_core", "1"), resource.TestCheckResourceAttr(resourceBasic, "valid_cores.#", "1"), resource.TestCheckResourceAttr(resourceBasic, "valid_cores.#", "1"), resource.TestCheckResourceAttr(resourceBasic, "valid_threads_per_core.#", "1"), resource.TestCheckResourceAttr(resourceBasic, "valid_threads_per_core.0", "1"), - resource.TestCheckResourceAttr(resourceBasic, "memory_size", "1024"), - resource.TestCheckResourceAttr(resourceBasic, "instance_storage_supported", "false"), - resource.TestCheckResourceAttr(resourceBasic, "ebs_optimized_support", "unsupported"), - resource.TestCheckResourceAttr(resourceBasic, "ebs_encryption_support", "supported"), - resource.TestCheckResourceAttr(resourceBasic, "ebs_nvme_support", "unsupported"), - resource.TestCheckResourceAttr(resourceBasic, "network_performance", "Low to Moderate"), - resource.TestCheckResourceAttr(resourceBasic, "maximum_network_interfaces", "2"), - resource.TestCheckResourceAttr(resourceBasic, "maximum_ipv4_addresses_per_interface", "2"), - resource.TestCheckResourceAttr(resourceBasic, "maximum_ipv6_addresses_per_interface", "2"), - resource.TestCheckResourceAttr(resourceBasic, "ipv6_supported", "true"), - resource.TestCheckResourceAttr(resourceBasic, "ena_support", "unsupported"), - resource.TestCheckResourceAttr(resourceBasic, "efa_supported", "false"), - resource.TestCheckResourceAttr(resourceBasic, "supported_placement_strategies.#", "2"), - resource.TestCheckResourceAttr(resourceBasic, "supported_placement_strategies.0", "partition"), - resource.TestCheckResourceAttr(resourceBasic, "supported_placement_strategies.1", "spread"), ), }, }, @@ -73,11 +77,11 @@ func TestAccDataSourceAwsEc2InstanceType_metal(t *testing.T) { resource.TestCheckResourceAttr(resourceMetal, "ebs_performance_maximum_bandwidth", "19000"), resource.TestCheckResourceAttr(resourceMetal, "ebs_performance_maximum_throughput", "2375"), resource.TestCheckResourceAttr(resourceMetal, "ebs_performance_maximum_iops", "80000"), - resource.TestCheckResourceAttr(resourceMetal, "total_instance_storage", "60000"), resource.TestCheckResourceAttr(resourceMetal, "instance_disks.#", "1"), resource.TestCheckResourceAttr(resourceMetal, "instance_disks.0.count", "8"), resource.TestCheckResourceAttr(resourceMetal, "instance_disks.0.size", "7500"), resource.TestCheckResourceAttr(resourceMetal, "instance_disks.0.type", "ssd"), + resource.TestCheckResourceAttr(resourceMetal, "total_instance_storage", "60000"), ), }, }, @@ -95,8 +99,8 @@ func TestAccDataSourceAwsEc2InstanceType_gpu(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceGpu, "gpus.#", "1"), resource.TestCheckResourceAttr(resourceGpu, "gpus.0.count", "1"), - resource.TestCheckResourceAttr(resourceGpu, "gpus.0.memory_size", "4096"), resource.TestCheckResourceAttr(resourceGpu, "gpus.0.manufacturer", "NVIDIA"), + resource.TestCheckResourceAttr(resourceGpu, "gpus.0.memory_size", "4096"), resource.TestCheckResourceAttr(resourceGpu, "gpus.0.name", "K520"), ), }, @@ -114,10 +118,10 @@ func TestAccDataSourceAwsEc2InstanceType_fpga(t *testing.T) { Config: testAccDataSourceEc2InstanceTypeFgpa, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceFpga, "fpgas.#", "1"), - resource.TestCheckResourceAttr(resourceFpga, "fpgas.0.name", "Virtex UltraScale (VU9P)"), - resource.TestCheckResourceAttr(resourceFpga, "fpgas.0.manufacturer", "Xilinx"), resource.TestCheckResourceAttr(resourceFpga, "fpgas.0.count", "1"), + resource.TestCheckResourceAttr(resourceFpga, "fpgas.0.manufacturer", "Xilinx"), resource.TestCheckResourceAttr(resourceFpga, "fpgas.0.memory_size", "65536"), + resource.TestCheckResourceAttr(resourceFpga, "fpgas.0.name", "Virtex UltraScale (VU9P)"), resource.TestCheckResourceAttr(resourceFpga, "total_fpga_memory", "65536"), ), }, @@ -134,10 +138,10 @@ func TestAccDataSourceAwsEc2InstanceType_accelerator(t *testing.T) { { Config: testAccDataSourceEc2InstanceTypeAccelerator, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceAccelerator, "accelerators.#", "1"), - resource.TestCheckResourceAttr(resourceAccelerator, "accelerators.0.count", "1"), - resource.TestCheckResourceAttr(resourceAccelerator, "accelerators.0.name", "Inferentia"), - resource.TestCheckResourceAttr(resourceAccelerator, "accelerators.0.manufacturer", "AWS"), + resource.TestCheckResourceAttr(resourceAccelerator, "inference_accelerators.#", "1"), + resource.TestCheckResourceAttr(resourceAccelerator, "inference_accelerators.0.count", "1"), + resource.TestCheckResourceAttr(resourceAccelerator, "inference_accelerators.0.manufacturer", "AWS"), + resource.TestCheckResourceAttr(resourceAccelerator, "inference_accelerators.0.name", "Inferentia"), ), }, }, @@ -169,7 +173,6 @@ data "aws_ec2_instance_type" "fpga" { ` const testAccDataSourceEc2InstanceTypeAccelerator = ` - data "aws_ec2_instance_type" "accelerator" { instance_type="inf1.xlarge" } diff --git a/website/docs/d/ec2_instance_type.html.markdown b/website/docs/d/ec2_instance_type.html.markdown index 48e65a310cc7..7ec4a7a3bbfc 100644 --- a/website/docs/d/ec2_instance_type.html.markdown +++ b/website/docs/d/ec2_instance_type.html.markdown @@ -32,27 +32,23 @@ In addition to the argument above, the following attributes are exported: ~> **NOTE:** Not all attributes are set for every instance type. -* `accelerators` Describes the Inference accelerators for the instance type. - * `accelerators.#.count` - The number of Inference accelerators for the instance type. - * `accelerators.#.manufacturer` - The manufacturer of the Inference accelerator. - * `accelerators.#.name` - The name of the Inference accelerator. * `auto_recovery_supported` - `true` if auto recovery is supported. * `bare_metal` - `true` if it is a bare metal instance type. * `burstable_performance_supported` - `true` if the instance type is a burstable performance instance type. * `current_generation` - `true` if the instance type is a current generation. +* `dedicated_hosts_supported` - `true` if Dedicated Hosts are supported on the instance type. * `default_cores` - The default number of cores for the instance type. * `default_threads_per_core` - The default number of threads per core for the instance type. * `default_vcpus` - The default number of vCPUs for the instance type. -* `dedicated_hosts_supported` - `true` if Dedicated Hosts are supported on the instance type. +* `ebs_encryption_support` - Indicates whether Amazon EBS encryption is supported. +* `ebs_nvme_support` - Indicates whether non-volatile memory express (NVMe) is supported. +* `ebs_optimized_support` - Indicates that the instance type is Amazon EBS-optimized. * `ebs_performance_baseline_bandwidth` - The baseline bandwidth performance for an EBS-optimized instance type, in Mbps. * `ebs_performance_baseline_iops` - The baseline input/output storage operations per seconds for an EBS-optimized instance type. * `ebs_performance_baseline_throughput` - The baseline throughput performance for an EBS-optimized instance type, in MBps. * `ebs_performance_maximum_bandwidth` - The maximum bandwidth performance for an EBS-optimized instance type, in Mbps. * `ebs_performance_maximum_iops` - The maximum input/output storage operations per second for an EBS-optimized instance type. * `ebs_performance_maximum_throughput` - The maximum throughput performance for an EBS-optimized instance type, in MBps. -* `ebs_encryption_support` - Indicates whether Amazon EBS encryption is supported. -* `ebs_nvme_support` - Indicates whether non-volatile memory express (NVMe) is supported. -* `ebs_optimized_support` - Indicates that the instance type is Amazon EBS-optimized. * `efa_supported` - Indicates whether Elastic Fabric Adapter (EFA) is supported. * `ena_support` - Indicates whether Elastic Network Adapter (ENA) is supported. * `fpgas` - Describes the FPGA accelerator settings for the instance type. @@ -68,12 +64,16 @@ In addition to the argument above, the following attributes are exported: * `gpus.#.name` - The name of the GPU accelerator. * `hibernation_supported` - `true` if On-Demand hibernation is supported. * `hypervisor` - Indicates the hypervisor used for the instance type. -* `ipv6_supported` - `true` if IPv6 is supported. +* `inference_accelerators` Describes the Inference accelerators for the instance type. + * `inference_accelerators.#.count` - The number of Inference accelerators for the instance type. + * `inference_accelerators.#.manufacturer` - The manufacturer of the Inference accelerator. + * `inference_accelerators.#.name` - The name of the Inference accelerator. * `instance_disks` - Describes the disks for the instance type. * `instance_disks.#.count` - The number of disks with this configuration. * `instance_disks.#.size` - The size of the disk in GB. * `instance_disks.#.type` - The type of disk. * `instance_storage_supported` - `true` if instance storage is supported. +* `ipv6_supported` - `true` if IPv6 is supported. * `maximum_ipv4_addresses_per_interface` - The maximum number of IPv4 addresses per network interface. * `maximum_ipv6_addresses_per_interface` - The maximum number of IPv6 addresses per network interface. * `maximum_network_interfaces` - The maximum number of network interfaces for the instance type. From 570e9e95c82ab34ce9d8993ac63c2980c66c5141 Mon Sep 17 00:00:00 2001 From: Lilian Deloche Date: Wed, 7 Oct 2020 19:36:56 +0200 Subject: [PATCH 7/8] Apply suggestions from code review Co-authored-by: Dirk Avery <31492422+YakDriver@users.noreply.github.com> --- aws/data_source_aws_ec2_instance_type_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/aws/data_source_aws_ec2_instance_type_test.go b/aws/data_source_aws_ec2_instance_type_test.go index 8b85513b6c13..e1531145597b 100644 --- a/aws/data_source_aws_ec2_instance_type_test.go +++ b/aws/data_source_aws_ec2_instance_type_test.go @@ -150,30 +150,30 @@ func TestAccDataSourceAwsEc2InstanceType_accelerator(t *testing.T) { const testAccDataSourceEc2InstanceTypeBasic = ` data "aws_ec2_instance_type" "basic" { - instance_type="t2.micro" + instance_type = "t2.micro" } ` const testAccDataSourceEc2InstanceTypeMetal = ` data "aws_ec2_instance_type" "metal" { - instance_type="i3en.metal" + instance_type = "i3en.metal" } ` const testAccDataSourceEc2InstanceTypeGpu = ` data "aws_ec2_instance_type" "gpu" { - instance_type="g2.2xlarge" + instance_type = "g2.2xlarge" } ` const testAccDataSourceEc2InstanceTypeFgpa = ` data "aws_ec2_instance_type" "fpga" { - instance_type="f1.2xlarge" + instance_type = "f1.2xlarge" } ` const testAccDataSourceEc2InstanceTypeAccelerator = ` data "aws_ec2_instance_type" "accelerator" { - instance_type="inf1.xlarge" + instance_type = "inf1.xlarge" } ` From a3d7b65bf9dddecf5010b5c4abed4b27c4e86cd3 Mon Sep 17 00:00:00 2001 From: Lilian Deloche Date: Wed, 7 Oct 2020 20:59:34 +0200 Subject: [PATCH 8/8] Adapt test for cross regions Co-authored-by: Dirk Avery <31492422+YakDriver@users.noreply.github.com> --- aws/data_source_aws_ec2_instance_type_test.go | 31 ++----------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/aws/data_source_aws_ec2_instance_type_test.go b/aws/data_source_aws_ec2_instance_type_test.go index e1531145597b..59d84208b80d 100644 --- a/aws/data_source_aws_ec2_instance_type_test.go +++ b/aws/data_source_aws_ec2_instance_type_test.go @@ -100,8 +100,8 @@ func TestAccDataSourceAwsEc2InstanceType_gpu(t *testing.T) { resource.TestCheckResourceAttr(resourceGpu, "gpus.#", "1"), resource.TestCheckResourceAttr(resourceGpu, "gpus.0.count", "1"), resource.TestCheckResourceAttr(resourceGpu, "gpus.0.manufacturer", "NVIDIA"), - resource.TestCheckResourceAttr(resourceGpu, "gpus.0.memory_size", "4096"), - resource.TestCheckResourceAttr(resourceGpu, "gpus.0.name", "K520"), + resource.TestCheckResourceAttr(resourceGpu, "gpus.0.memory_size", "8192"), + resource.TestCheckResourceAttr(resourceGpu, "gpus.0.name", "M60"), ), }, }, @@ -129,25 +129,6 @@ func TestAccDataSourceAwsEc2InstanceType_fpga(t *testing.T) { }) } -func TestAccDataSourceAwsEc2InstanceType_accelerator(t *testing.T) { - resourceAccelerator := "data.aws_ec2_instance_type.accelerator" - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceEc2InstanceTypeAccelerator, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceAccelerator, "inference_accelerators.#", "1"), - resource.TestCheckResourceAttr(resourceAccelerator, "inference_accelerators.0.count", "1"), - resource.TestCheckResourceAttr(resourceAccelerator, "inference_accelerators.0.manufacturer", "AWS"), - resource.TestCheckResourceAttr(resourceAccelerator, "inference_accelerators.0.name", "Inferentia"), - ), - }, - }, - }) -} - const testAccDataSourceEc2InstanceTypeBasic = ` data "aws_ec2_instance_type" "basic" { instance_type = "t2.micro" @@ -162,7 +143,7 @@ data "aws_ec2_instance_type" "metal" { const testAccDataSourceEc2InstanceTypeGpu = ` data "aws_ec2_instance_type" "gpu" { - instance_type = "g2.2xlarge" + instance_type = "g3.4xlarge" } ` @@ -171,9 +152,3 @@ data "aws_ec2_instance_type" "fpga" { instance_type = "f1.2xlarge" } ` - -const testAccDataSourceEc2InstanceTypeAccelerator = ` -data "aws_ec2_instance_type" "accelerator" { - instance_type = "inf1.xlarge" -} -`