-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Ved misra <[email protected]>
- Loading branch information
Showing
5 changed files
with
281 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package azure | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
sub "github.com/Azure/azure-sdk-for-go/profiles/latest/subscription/mgmt/subscription" | ||
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute" | ||
|
||
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" | ||
"github.com/turbot/steampipe-plugin-sdk/v5/plugin" | ||
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" | ||
) | ||
|
||
//// TABLE DEFINITION //// | ||
|
||
func tableAzureComputeVirtualMachineSize(_ context.Context) *plugin.Table { | ||
return &plugin.Table{ | ||
Name: "azure_compute_virtual_machine_size", | ||
Description: "Azure Compute Virtual Machine Size", | ||
List: &plugin.ListConfig{ | ||
ParentHydrate: listLocations, | ||
Hydrate: listComputeVirtualMachineSizes, | ||
}, | ||
Columns: azureColumns([]*plugin.Column{ | ||
{ | ||
Name: "name", | ||
Description: "The name of the virtual machine size.", | ||
Type: proto.ColumnType_STRING, | ||
Transform: transform.FromField("VirtualMachineSize.Name"), | ||
}, | ||
{ | ||
Name: "number_of_cores", | ||
Description: "The number of cores supported by the virtual machine size.", | ||
Type: proto.ColumnType_INT, | ||
Transform: transform.FromField("VirtualMachineSize.NumberOfCores"), | ||
}, | ||
{ | ||
Name: "os_disk_size_in_mb", | ||
Description: "The OS disk size, in MB, allowed by the virtual machine size.", | ||
Type: proto.ColumnType_INT, | ||
Transform: transform.FromField("VirtualMachineSize.OSDiskSizeInMB"), | ||
}, | ||
{ | ||
Name: "resource_disk_size_in_mb", | ||
Description: "The resource disk size, in MB, allowed by the virtual machine size.", | ||
Type: proto.ColumnType_INT, | ||
Transform: transform.FromField("VirtualMachineSize.ResourceDiskSizeInMB"), | ||
}, | ||
{ | ||
Name: "memory_in_mb", | ||
Description: "The amount of memory, in MB, supported by the virtual machine size.", | ||
Type: proto.ColumnType_INT, | ||
Transform: transform.FromField("VirtualMachineSize.MemoryInMB"), | ||
}, | ||
{ | ||
Name: "max_data_disk_count", | ||
Description: "The maximum number of data disks that can be attached to the virtual machine size.", | ||
Type: proto.ColumnType_INT, | ||
Transform: transform.FromField("VirtualMachineSize.MaxDataDiskCount"), | ||
}, | ||
|
||
// Standard steampipe columns | ||
{ | ||
Name: "title", | ||
Description: ColumnDescriptionTitle, | ||
Type: proto.ColumnType_STRING, | ||
Transform: transform.FromField("VirtualMachineSize.Name"), | ||
}, | ||
|
||
// Azure standard columns | ||
{ | ||
Name: "region", | ||
Description: ColumnDescriptionRegion, | ||
Type: proto.ColumnType_STRING, | ||
Transform: transform.FromField("Location").Transform(toLower), | ||
}, | ||
}), | ||
} | ||
} | ||
|
||
type VMSizeInfo struct { | ||
*armcompute.VirtualMachineSize | ||
Location string | ||
} | ||
|
||
//// LIST FUNCTION //// | ||
|
||
func listComputeVirtualMachineSizes(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
|
||
if h.Item == nil { | ||
return nil, nil | ||
} | ||
|
||
locationDetails := h.Item.(sub.Location) | ||
|
||
session, err := GetNewSessionUpdated(ctx, d) | ||
if err != nil { | ||
plugin.Logger(ctx).Error("azure_compute_virtual_machine_size.listComputeVirtualMachineSizes", "session_error", err) | ||
return nil, err | ||
} | ||
|
||
session.ClientOptions.APIVersion = "2024-07-01" | ||
|
||
clientFactory, err := armcompute.NewVirtualMachineSizesClient(session.SubscriptionID, session.Cred, session.ClientOptions) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
pager := clientFactory.NewListPager(*locationDetails.Name, &armcompute.VirtualMachineSizesClientListOptions{}) | ||
for pager.More() { | ||
page, err := pager.NextPage(ctx) | ||
if err != nil { | ||
// In Azure, resource providers are services that allow you to interact with resources (like virtual machines). | ||
// The relevant resource provider for Virtual Machines is `Microsoft.Compute`. | ||
// If this provider is not registered, or if it's not available in the specified region, you might encounter the error. | ||
// You can use the command (`az provider show --namespace Microsoft.Compute`) to check the availability of the service in the specified location. | ||
// Look for the `locations/vmSizes` resource type in the command result to verify it's availability. | ||
|
||
if strings.Contains(strings.ToLower(err.Error()), "no registered resource provider found for location") { | ||
plugin.Logger(ctx).Error("azure_compute_virtual_machine_size.listComputeVirtualMachineSizes", "no registered resource provider found", err.Error()) | ||
return nil, nil | ||
} | ||
plugin.Logger(ctx).Error("azure_compute_virtual_machine_size.listComputeVirtualMachineSizes", "api_error", err) | ||
return nil, err | ||
} | ||
|
||
for _, virtualMachineSize := range page.Value { | ||
d.StreamListItem(ctx, VMSizeInfo{virtualMachineSize, *locationDetails.Name}) | ||
// Check if context has been cancelled or if the limit has been hit (if specified) | ||
// if there is a limit, it will return the number of rows required to reach this limit | ||
if d.RowsRemaining(ctx) == 0 { | ||
return nil, nil | ||
} | ||
} | ||
} | ||
|
||
return nil, nil | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
--- | ||
title: "Steampipe Table: azure_compute_virtual_machine_size - Query Azure Virtual Machine Sizes using SQL" | ||
description: "Allows users to query available virtual machine sizes in Azure, providing details on cores, memory, disk sizes, and more." | ||
--- | ||
|
||
# Table: azure_compute_virtual_machine_size - Query Azure Virtual Machine Sizes using SQL | ||
|
||
Azure virtual machine sizes determine the computing resources, such as memory, CPU cores, and disk capacity, available to your virtual machines (VMs). The `azure_compute_virtual_machine_size` table in Steampipe allows you to query and explore the different virtual machine sizes available in Azure, enabling you to compare memory, disk sizes, and other attributes to choose the right VM for your workload. | ||
|
||
## Table Usage Guide | ||
|
||
The `azure_compute_virtual_machine_size` table is useful for cloud architects, administrators, and DevOps engineers who need insights into the available VM sizes in Azure. You can query attributes like the number of cores, memory, and disk sizes to make informed decisions about the resources required for your virtual machines. | ||
|
||
## Examples | ||
|
||
### Basic VM size information | ||
Retrieve basic information about the virtual machine sizes, including name, region, and number of cores. | ||
|
||
```sql+postgres | ||
select | ||
name, | ||
region, | ||
number_of_cores, | ||
memory_in_mb | ||
from | ||
azure_compute_virtual_machine_size; | ||
``` | ||
|
||
```sql+sqlite | ||
select | ||
name, | ||
region, | ||
number_of_cores, | ||
memory_in_mb | ||
from | ||
azure_compute_virtual_machine_size; | ||
``` | ||
|
||
### List VM sizes with high memory | ||
Identify VM sizes that have more than a specified amount of memory (e.g., 32 GB). | ||
|
||
```sql+postgres | ||
select | ||
name, | ||
memory_in_mb, | ||
number_of_cores | ||
from | ||
azure_compute_virtual_machine_size | ||
where | ||
memory_in_mb > 32768; | ||
``` | ||
|
||
```sql+sqlite | ||
select | ||
name, | ||
memory_in_mb, | ||
number_of_cores | ||
from | ||
azure_compute_virtual_machine_size | ||
where | ||
memory_in_mb > 32768; | ||
``` | ||
|
||
### List VM sizes with large OS disk size | ||
Fetch VM sizes that support large OS disk sizes (e.g., over 500 GB). | ||
|
||
```sql+postgres | ||
select | ||
name, | ||
os_disk_size_in_mb, | ||
max_data_disk_count | ||
from | ||
azure_compute_virtual_machine_size | ||
where | ||
os_disk_size_in_mb > 512000; | ||
``` | ||
|
||
```sql+sqlite | ||
select | ||
name, | ||
os_disk_size_in_mb, | ||
max_data_disk_count | ||
from | ||
azure_compute_virtual_machine_size | ||
where | ||
os_disk_size_in_mb > 512000; | ||
``` | ||
|
||
### List VM sizes by core count | ||
Retrieve a list of VM sizes based on the number of cores available. | ||
|
||
```sql+postgres | ||
select | ||
name, | ||
number_of_cores, | ||
region | ||
from | ||
azure_compute_virtual_machine_size | ||
where | ||
number_of_cores >= 8; | ||
``` | ||
|
||
```sql+sqlite | ||
select | ||
name, | ||
number_of_cores, | ||
region | ||
from | ||
azure_compute_virtual_machine_size | ||
where | ||
number_of_cores >= 8; | ||
``` | ||
|
||
### List VM sizes with a specific data disk count | ||
Identify VM sizes that support a certain number of data disks. | ||
|
||
```sql+postgres | ||
select | ||
name, | ||
max_data_disk_count, | ||
resource_disk_size_in_mb | ||
from | ||
azure_compute_virtual_machine_size | ||
where | ||
max_data_disk_count >= 8; | ||
``` | ||
|
||
```sql+sqlite | ||
select | ||
name, | ||
max_data_disk_count, | ||
resource_disk_size_in_mb | ||
from | ||
azure_compute_virtual_machine_size | ||
where | ||
max_data_disk_count >= 8; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters