Skip to content

Commit

Permalink
Add attributes to the aws_ec2_instance_type data source
Browse files Browse the repository at this point in the history
Added the following attributes to the `aws_ec2_instance_type` data source to bring it up-to-date with the EC2 API.

* `bandwidth_weightings`
* `boot_modes`
* `default_network_card_index`
* `efa_maximum_interfaces`
* `inference_accelerators.#.memory_size`
* `media_accelerators.#.count`
* `media_accelerators.#.manufacturer`
* `media_accelerators.#.memory_size`
* `media_accelerators.#.name`
* `network_cards.#.baseline_bandwidth`
* `network_cards.#.index`
* `network_cards.#.maximum_interfaces`
* `network_cards.#.performance`
* `network_cards.#.peak_bandwidth`
* `neuron_devices.#.core_count`
* `neuron_devices.#.count`
* `neuron_devices.#.memory_size`
* `neuron_devices.#.name`
* `neuron_devices.#.version`
* `nitro_enclaves_support`
* `nitro_tpm_support`
* `nitro_tpm_supported_versions`
* `phc_support`
* `srd_supported`
* `supported_cpu_features`
* `total_inference_memory`
* `total_media_memory`
* `total_neuron_device_memory`
  • Loading branch information
bakeemawaytoys committed Dec 28, 2024
1 parent 017df23 commit 8171296
Show file tree
Hide file tree
Showing 2 changed files with 246 additions and 11 deletions.
209 changes: 206 additions & 3 deletions internal/service/ec2/ec2_instance_type_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,20 @@ func dataSourceInstanceType() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"bandwidth_weightings": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"bare_metal": {
Type: schema.TypeBool,
Computed: true,
},
"boot_modes": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"burstable_performance_supported": {
Type: schema.TypeBool,
Computed: true,
Expand All @@ -50,6 +60,10 @@ func dataSourceInstanceType() *schema.Resource {
Type: schema.TypeInt,
Computed: true,
},
"default_network_card_index": {
Type: schema.TypeInt,
Computed: true,
},
"default_threads_per_core": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -98,6 +112,10 @@ func dataSourceInstanceType() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"efa_maximum_interfaces": {
Type: schema.TypeInt,
Computed: true,
},
"ena_support": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -179,6 +197,10 @@ func dataSourceInstanceType() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"memory_size": {
Type: schema.TypeInt,
Computed: true,
},
names.AttrName: {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -234,19 +256,125 @@ func dataSourceInstanceType() *schema.Resource {
Type: schema.TypeInt,
Computed: true,
},
"media_accelerators": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"count": {
Type: schema.TypeInt,
Computed: true,
},
"manufacturer": {
Type: schema.TypeString,
Computed: true,
},
"memory_size": {
Type: schema.TypeInt,
Computed: true,
},
names.AttrName: {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"memory_size": {
Type: schema.TypeInt,
Computed: true,
},
"network_cards": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"baseline_bandwidth": {
Type: schema.TypeFloat,
Computed: true,
},
"index": {
Type: schema.TypeInt,
Computed: true,
},
"maximum_interfaces": {
Type: schema.TypeInt,
Computed: true,
},
"performance": {
Type: schema.TypeString,
Computed: true,
},
"peak_bandwidth": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
"network_performance": {
Type: schema.TypeString,
Computed: true,
},
"neuron_devices": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"core_count": {
Type: schema.TypeInt,
Computed: true,
},
"count": {
Type: schema.TypeInt,
Computed: true,
},
"memory_size": {
Type: schema.TypeInt,
Computed: true,
},
names.AttrName: {
Type: schema.TypeString,
Computed: true,
},
"version": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"nitro_enclaves_support": {
Type: schema.TypeString,
Computed: true,
},
"nitro_tpm_support": {
Type: schema.TypeString,
Computed: true,
},
"nitro_tpm_supported_versions": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"phc_support": {
Type: schema.TypeString,
Computed: true,
},
"srd_supported": {
Type: schema.TypeBool,
Computed: true,
},
"supported_architectures": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"supported_cpu_features": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"supported_placement_strategies": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -279,10 +407,22 @@ func dataSourceInstanceType() *schema.Resource {
Type: schema.TypeInt,
Computed: true,
},
"total_inference_memory": {
Type: schema.TypeInt,
Computed: true,
},
"total_instance_storage": {
Type: schema.TypeInt,
Computed: true,
},
"total_media_memory": {
Type: schema.TypeInt,
Computed: true,
},
"total_neuron_device_memory": {
Type: schema.TypeInt,
Computed: true,
},
"valid_cores": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -310,10 +450,13 @@ func dataSourceInstanceTypeRead(ctx context.Context, d *schema.ResourceData, met
d.SetId(string(v.InstanceType))
d.Set("auto_recovery_supported", v.AutoRecoverySupported)
d.Set("bare_metal", v.BareMetal)
d.Set("bandwidth_weightings", v.NetworkInfo.BandwidthWeightings)
d.Set("boot_modes", v.SupportedBootModes)
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_network_card_index", v.NetworkInfo.DefaultNetworkCardIndex)
d.Set("default_threads_per_core", v.VCpuInfo.DefaultThreadsPerCore)
d.Set("default_vcpus", v.VCpuInfo.DefaultVCpus)
d.Set("ebs_encryption_support", v.EbsInfo.EncryptionSupport)
Expand All @@ -328,6 +471,9 @@ func dataSourceInstanceTypeRead(ctx context.Context, d *schema.ResourceData, met
d.Set("ebs_performance_maximum_iops", v.EbsInfo.EbsOptimizedInfo.MaximumIops)
}
d.Set("efa_supported", v.NetworkInfo.EfaSupported)
if v.NetworkInfo.EfaInfo != nil {
d.Set("efa_maximum_interfaces", v.NetworkInfo.EfaInfo.MaximumEfaInterfaces)
}
d.Set("ena_support", v.NetworkInfo.EnaSupport)
d.Set("encryption_in_transit_supported", v.NetworkInfo.EncryptionInTransitSupported)
if v.FpgaInfo != nil {
Expand Down Expand Up @@ -361,17 +507,19 @@ func dataSourceInstanceTypeRead(ctx context.Context, d *schema.ResourceData, met
}
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 {
if info := v.InferenceAcceleratorInfo; info != nil {
acceleratorList := make([]interface{}, len(info.Accelerators))
for i, accl := range info.Accelerators {
accelerator := map[string]interface{}{
"count": aws.ToInt32(accl.Count),
"manufacturer": aws.ToString(accl.Manufacturer),
"memory_size": aws.ToInt32(accl.MemoryInfo.SizeInMiB),
names.AttrName: aws.ToString(accl.Name),
}
acceleratorList[i] = accelerator
}
d.Set("inference_accelerators", acceleratorList)
d.Set("total_inference_memory", info.TotalInferenceMemoryInMiB)
}
if v.InstanceStorageInfo != nil {
if v.InstanceStorageInfo.Disks != nil {
Expand All @@ -395,9 +543,64 @@ func dataSourceInstanceTypeRead(ctx context.Context, d *schema.ResourceData, met
d.Set("maximum_ipv6_addresses_per_interface", v.NetworkInfo.Ipv6AddressesPerInterface)
d.Set("maximum_network_cards", v.NetworkInfo.MaximumNetworkCards)
d.Set("maximum_network_interfaces", v.NetworkInfo.MaximumNetworkInterfaces)
if info := v.MediaAcceleratorInfo; info != nil {
acceleratorList := make([]interface{}, len(info.Accelerators))
for i, accl := range info.Accelerators {
accelerator := map[string]interface{}{
"count": aws.ToInt32(accl.Count),
"manufacturer": aws.ToString(accl.Manufacturer),
"memory_size": aws.ToInt32(accl.MemoryInfo.SizeInMiB),
names.AttrName: aws.ToString(accl.Name),
}
acceleratorList[i] = accelerator
}
d.Set("media_accelerators", acceleratorList)
d.Set("total_media_memory", info.TotalMediaMemoryInMiB)
}
d.Set("memory_size", v.MemoryInfo.SizeInMiB)
if info := v.NeuronInfo; info != nil {
deviceList := make([]interface{}, len(info.NeuronDevices))
for i, d := range info.NeuronDevices {
device := map[string]interface{}{
"count": aws.ToInt32(d.Count),
"core_count": aws.ToInt32(d.CoreInfo.Count),
"memory_size": aws.ToInt32(d.MemoryInfo.SizeInMiB),
names.AttrName: aws.ToString(d.Name),
"version": aws.ToInt32(d.CoreInfo.Version),
}
deviceList[i] = device
}
d.Set("neuron_devices", deviceList)
d.Set("total_neuron_device_memory", info.TotalNeuronDeviceMemoryInMiB)
}
d.Set("nitro_enclaves_support", v.NitroEnclavesSupport)
d.Set("nitro_tpm_support", v.NitroTpmSupport)
var nitroTpmSupportedVersions []string
if v.NitroTpmInfo != nil {
nitroTpmSupportedVersions = v.NitroTpmInfo.SupportedVersions
} else {
nitroTpmSupportedVersions = []string{}
}
d.Set("nitro_tpm_supported_versions", nitroTpmSupportedVersions)
d.Set("network_performance", v.NetworkInfo.NetworkPerformance)
if info := v.NetworkInfo; info != nil {
cardList := make([]interface{}, len(info.NetworkCards))
for i, c := range info.NetworkCards {
card := map[string]interface{}{
"baseline_bandwidth": aws.ToFloat64(c.BaselineBandwidthInGbps),
"index": aws.ToInt32(c.NetworkCardIndex),
"maximum_interfaces": aws.ToInt32(c.MaximumNetworkInterfaces),
"peak_bandwidth": aws.ToFloat64(c.PeakBandwidthInGbps),
"performance": aws.ToString(c.NetworkPerformance),
}
cardList[i] = card
}
d.Set("network_cards", cardList)
}
d.Set("phc_support", v.PhcSupport)
d.Set("srd_supported", v.NetworkInfo.EnaSrdSupported)
d.Set("supported_architectures", v.ProcessorInfo.SupportedArchitectures)
d.Set("supported_cpu_features", v.ProcessorInfo.SupportedFeatures)
d.Set("supported_placement_strategies", v.PlacementGroupInfo.SupportedStrategies)
d.Set("supported_root_device_types", v.SupportedRootDeviceTypes)
d.Set("supported_usages_classes", v.SupportedUsageClasses)
Expand Down
Loading

0 comments on commit 8171296

Please sign in to comment.