diff --git a/azure/plugin.go b/azure/plugin.go index b561380b..d83f2fdb 100644 --- a/azure/plugin.go +++ b/azure/plugin.go @@ -102,6 +102,7 @@ func Plugin(ctx context.Context) *plugin.Plugin { "azure_key_vault_managed_hardware_security_module": tableAzureKeyVaultManagedHardwareSecurityModule(ctx), "azure_key_vault_secret": tableAzureKeyVaultSecret(ctx), "azure_kubernetes_cluster": tableAzureKubernetesCluster(ctx), + "azure_kubernetes_service_version": tableAzureAKSOrchestractor(ctx), "azure_kusto_cluster": tableAzureKustoCluster(ctx), "azure_lb": tableAzureLoadBalancer(ctx), "azure_lb_backend_address_pool": tableAzureLoadBalancerBackendAddressPool(ctx), diff --git a/azure/table_azure_kubernetes_service_version.go b/azure/table_azure_kubernetes_service_version.go new file mode 100644 index 00000000..c49e631f --- /dev/null +++ b/azure/table_azure_kubernetes_service_version.go @@ -0,0 +1,172 @@ +package azure + +import ( + "context" + + "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2020-09-01/containerservice" + "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" + "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" + + "github.com/turbot/steampipe-plugin-sdk/v5/plugin" +) + +//// TABLE DEFINITION //// + +func tableAzureAKSOrchestractor(_ context.Context) *plugin.Table { + return &plugin.Table{ + Name: "azure_kubernetes_service_version", + Description: "Azure Kubernetes Service Version", + List: &plugin.ListConfig{ + Hydrate: listAKSOrchestractors, + KeyColumns: plugin.KeyColumnSlice{ + { + Name: "location", + Require: plugin.Required, + }, + { + Name: "resource_type", + Require: plugin.Optional, + }, + }, + }, + Columns: azureColumns([]*plugin.Column{ + { + Name: "name", + Type: proto.ColumnType_STRING, + Description: "Name of the orchestrator version profile list result.", + }, + { + Name: "id", + Description: "ID of the orchestrator version profile list result.", + Type: proto.ColumnType_STRING, + Transform: transform.FromGo(), + }, + { + Name: "type", + Description: "Type of the orchestrator version profile list result.", + Type: proto.ColumnType_STRING, + }, + { + Name: "orchestrator_type", + Description: "The orchestrator type.", + Type: proto.ColumnType_STRING, + }, + { + Name: "orchestrator_version", + Description: "Orchestrator version (major, minor, patch).", + Type: proto.ColumnType_STRING, + }, + { + Name: "default", + Description: "Installed by default if version is not specified.", + Type: proto.ColumnType_BOOL, + }, + { + Name: "is_preview", + Description: "Whether Kubernetes version is currently in preview.", + Type: proto.ColumnType_BOOL, + }, + { + Name: "resource_type", + Description: "Whether Kubernetes version is currently in preview.", + Type: proto.ColumnType_STRING, + Transform: transform.FromQual("resource_type"), + }, + { + Name: "upgrades", + Description: "The list of available upgrade versions.", + Type: proto.ColumnType_JSON, + }, + + // Steampipe standard columns + { + Name: "title", + Description: ColumnDescriptionTitle, + Type: proto.ColumnType_STRING, + Transform: transform.FromField("Name"), + }, + { + Name: "akas", + Description: ColumnDescriptionAkas, + Type: proto.ColumnType_JSON, + Transform: transform.FromField("ID").Transform(idToAkas), + }, + + // Azure standard columns + { + Name: "location", + Description: ColumnDescriptionRegion, + Type: proto.ColumnType_STRING, + Transform: transform.FromQual("location"), + }, + }), + } +} + +type OrchestratorInfo struct { + // ID - READ-ONLY; Id of the orchestrator version profile list result. + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; Name of the orchestrator version profile list result. + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; Type of the orchestrator version profile list result. + Type *string `json:"type,omitempty"` + // OrchestratorType - Orchestrator type. + OrchestratorType *string `json:"orchestratorType,omitempty"` + // OrchestratorVersion - Orchestrator version (major, minor, patch). + OrchestratorVersion *string `json:"orchestratorVersion,omitempty"` + // Default - Installed by default if version is not specified. + Default *bool `json:"default,omitempty"` + // IsPreview - Whether Kubernetes version is currently in preview. + IsPreview *bool `json:"isPreview,omitempty"` + // Upgrades - The list of available upgrade versions. + Upgrades *[]containerservice.OrchestratorProfile `json:"upgrades,omitempty"` +} + +//// LIST FUNCTION + +func listAKSOrchestractors(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { + location := d.EqualsQualString("location") + resourceType := d.EqualsQualString("resource_type") + + // Empty Check + if location == "" { + return nil, nil + } + + session, err := GetNewSession(ctx, d, "MANAGEMENT") + if err != nil { + plugin.Logger(ctx).Error("azure_kubernetes_service_version.listAKSOrchestractors", "session_error", err) + return nil, err + } + + subscriptionID := session.SubscriptionID + + containerserviceClient := containerservice.NewContainerServicesClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID) + containerserviceClient.Authorizer = session.Authorizer + + result, err := containerserviceClient.ListOrchestrators(ctx, location, resourceType) + if err != nil { + plugin.Logger(ctx).Error("azure_kubernetes_service_version.listAKSOrchestractors", "api_error", err) + return nil, err + } + + for _, op := range *result.Orchestrators { + d.StreamListItem(ctx, &OrchestratorInfo{ + ID: result.ID, + Name: result.Name, + Type: result.Type, + OrchestratorType: op.OrchestratorType, + OrchestratorVersion: op.OrchestratorVersion, + Default: op.Default, + IsPreview: op.IsPreview, + Upgrades: op.Upgrades, + }) + // 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, err +} diff --git a/docs/tables/azure_kubernetes_service_version.md b/docs/tables/azure_kubernetes_service_version.md new file mode 100644 index 00000000..95be7988 --- /dev/null +++ b/docs/tables/azure_kubernetes_service_version.md @@ -0,0 +1,87 @@ +# Table: azure_kubernetes_service_version + +Azure AKS (Azure Kubernetes Service) orchestrator is a managed container orchestration service provided by Microsoft Azure. It simplifies the deployment, management, and scaling of containerized applications using Kubernetes. AKS allows you to deploy and manage containerized applications without the need to manage the underlying infrastructure. It provides automated Kubernetes upgrades, built-in monitoring and diagnostics, and seamless integration with other Azure services. AKS enables developers and DevOps teams to focus on application development and deployment, while Azure takes care of the underlying Kubernetes infrastructure. + +**Note:** You need to pass the `location` in the where clause to query this table. + +## Examples + +### Basic info + +```sql +select + name, + id, + type, + orchestrator_type, + orchestrator_version +from + azure_kubernetes_service_version +where + location = 'eastus2'; +``` + +### List major kubernetes versions + +```sql +select + name, + id, + orchestrator_type, + orchestrator_version +from + azure_kubernetes_service_version +where + orchestrator_version = 'major' +and + location = 'eastus2'; +``` + +### List kubernetes orchestrator type + +```sql +select + name, + id, + type, + orchestrator_type, + is_preview +from + azure_kubernetes_service_version +where + orchestrator_type = 'Kubernetes' +and + location = 'eastus2'; +``` + +### List kubernetes versions that are not in preview + +```sql +select + name, + id, + orchestrator_type, + orchestrator_version, + is_preview +from + azure_kubernetes_service_version +where + not is_preview +and + location = 'eastus2'; +``` + +### Get upgrade details of each kubernetes version + +```sql +select + name, + u ->> 'orchestratorType' as orchestrator_type, + u ->> 'orchestratorVersion' as orchestrator_version, + u ->> 'isPreview' as is_preview +from + azure_kubernetes_service_version, + jsonb_array_elements(upgrades) as u +where + location = 'eastus2'; +```