Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add table azure_databox_edge_device closes #330 #377

Merged
merged 11 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"id": "{{ output.resource_id.value }}",
"name": "{{ resourceName }}",
"type": "Microsoft.DataBoxEdge/dataBoxEdgeDevices"
}
]
3 changes: 3 additions & 0 deletions azure-test/tests/azure_databox_edge_device/test-get-query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select name, id,type
from azure.azure_databox_edge_device
where name = '{{ resourceName }}' and resource_group = '{{ resourceName }}';
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"id": "{{ output.resource_id.value }}",
"name": "{{ resourceName }}"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select id, name
from azure.azure_databox_edge_device
where title = '{{ resourceName }}';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
null
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select name, akas, title
from azure.azure_databox_edge_device
where name = 'dummy-{{ resourceName }}';
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"akas": [
"{{ output.resource_aka.value }}",
"{{ output.resource_aka_lower.value }}"
],
"name": "{{ resourceName }}",
"title": "{{ resourceName }}"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select name, akas, title
from azure.azure_databox_edge_device
where name = '{{ resourceName }}';
1 change: 1 addition & 0 deletions azure-test/tests/azure_databox_edge_device/variables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
68 changes: 68 additions & 0 deletions azure-test/tests/azure_databox_edge_device/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
variable "resource_name" {
type = string
default = "turbot-test-20200125-create-update"
description = "Name of the resource used throughout the test."
}

variable "azure_environment" {
type = string
default = "public"
description = "Azure environment used for the test."
}

variable "azure_subscription" {
type = string
default = "3510ae4d-530b-497d-8f30-53b9616fc6c1"
description = "Azure subscription used for the test."
}

provider "azurerm" {
features {}
environment = var.azure_environment
subscription_id = var.azure_subscription
}

data "azurerm_client_config" "current" {}

data "null_data_source" "resource" {
inputs = {
scope = "azure:///subscriptions/${data.azurerm_client_config.current.subscription_id}"
}
}

resource "azurerm_resource_group" "named_test_resource" {
name = var.resource_name
location = "East US"
}

resource "azurerm_databox_edge_device" "named_test_resource" {
name = var.resource_name
resource_group_name = azurerm_resource_group.named_test_resource.name
location = azurerm_resource_group.named_test_resource.location

sku_name = "Gateway-Standard"

tags = {
Name = var.resource_name
}
}

output "resource_aka" {
value = "azure://${azurerm_databox_edge_device.named_test_resource.id}"
}

output "resource_aka_lower" {
value = "azure://${lower(azurerm_databox_edge_device.named_test_resource.id)}"
}

output "resource_name" {
value = var.resource_name
}

output "resource_id" {
value = azurerm_databox_edge_device.named_test_resource.id
}

output "subscription_id" {
value = var.azure_subscription
}
1 change: 1 addition & 0 deletions azure/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func Plugin(ctx context.Context) *plugin.Plugin {
"azure_cosmosdb_account": tableAzureCosmosDBAccount(ctx),
"azure_cosmosdb_mongo_database": tableAzureCosmosDBMongoDatabase(ctx),
"azure_cosmosdb_sql_database": tableAzureCosmosDBSQLDatabase(ctx),
"azure_databox_edge_device": tableAzureDataBoxEdgeDevice(ctx),
"azure_data_factory": tableAzureDataFactory(ctx),
"azure_data_factory_dataset": tableAzureDataFactoryDataset(ctx),
"azure_data_factory_pipeline": tableAzureDataFactoryPipeline(ctx),
Expand Down
258 changes: 258 additions & 0 deletions azure/table_azure_databox_edge_device.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
package azure

import (
"context"

"github.com/Azure/azure-sdk-for-go/services/databoxedge/mgmt/2019-07-01/databoxedge"
"github.com/turbot/steampipe-plugin-sdk/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/plugin/transform"

"github.com/turbot/steampipe-plugin-sdk/plugin"
)

//// TABLE DEFINITION

func tableAzureDataBoxEdgeDevice(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "azure_databox_edge_device",
Description: "Azure Data Box Edge Device",
Get: &plugin.GetConfig{
KeyColumns: plugin.AllColumns([]string{"name", "resource_group"}),
Hydrate: getDataBoxEdgeDevice,
ShouldIgnoreError: isNotFoundError([]string{"ResourceNotFound", "ResourceGroupNotFound", "400"}),
},
List: &plugin.ListConfig{
Hydrate: listDataBoxEdgeDevices,
},
Columns: []*plugin.Column{
{
Name: "name",
Description: "The resource name.",
Type: proto.ColumnType_STRING,
},
{
Name: "id",
Description: "The resource identifier.",
Type: proto.ColumnType_STRING,
Transform: transform.FromGo(),
},
{
Name: "friendly_name",
Description: "The Data Box Edge/Gateway device name.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DeviceProperties.FriendlyName"),
},
{
Name: "type",
Description: "The resource type.",
Type: proto.ColumnType_STRING,
},
{
Name: "data_box_edge_device_status",
Description: "The status of the Data Box Edge/Gateway device. Possible values include: 'ReadyToSetup', 'Online', 'Offline', 'NeedsAttention', 'Disconnected', 'PartiallyDisconnected', 'Maintenance'.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DeviceProperties.DataBoxEdgeDeviceStatus"),
},
{
Name: "culture",
Description: "The Data Box Edge/Gateway device culture.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DeviceProperties.Culture"),
},
{
Name: "description",
Description: "he Description of the Data Box Edge/Gateway device.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DeviceProperties.Description"),
},
{
Name: "device_model",
Description: "The Data Box Edge/Gateway device model.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DeviceProperties.DeviceModel"),
},
{
Name: "device_type",
Description: "The type of the Data Box Edge/Gateway device. Possible values include: 'DataBoxEdgeDevice'.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DeviceProperties.DeviceType"),
},
{
Name: "device_hcs_version",
Description: "The device software version number of the device (eg: 1.2.18105.6).",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DeviceProperties.DeviceHcsVersion"),
},
{
Name: "device_local_capacity",
Description: "The Data Box Edge/Gateway device local capacity in MB.",
Type: proto.ColumnType_INT,
Transform: transform.FromField("DeviceProperties.DeviceLocalCapacity"),
},
{
Name: "device_software_version",
Description: "The Data Box Edge/Gateway device software version.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DeviceProperties.DeviceSoftwareVersion"),
},
{
Name: "etag",
Description: "The etag for the devices.",
Type: proto.ColumnType_STRING,
},
{
Name: "location",
Description: "The location of the device. This is a supported and registered Azure geographical region (for example, West US, East US, or Southeast Asia). The geographical region of a device cannot be changed once it is created, but if an identical geographical region is specified on update, the request will succeed.",
Type: proto.ColumnType_STRING,
},
{
Name: "model_description",
Description: "The description of the Data Box Edge/Gateway device model.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DeviceProperties.ModelDescription"),
},
{
Name: "node_count",
Description: "The number of nodes in the cluster.",
Type: proto.ColumnType_INT,
Transform: transform.FromField("DeviceProperties.NodeCount"),
},
{
Name: "serial_number",
Description: "The Serial Number of Data Box Edge/Gateway device.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DeviceProperties.SerialNumber"),
},
{
Name: "sku_name",
Description: "SKU name of the resource. Possible values include: 'Gateway', 'Edge'.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("Sku.Name"),
},
{
Name: "sku_tier",
Description: "The SKU tier. This is based on the SKU name. Possible values include: 'Standard'.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("Sku.Tier"),
},
{
Name: "time_zone",
Description: "The Data Box Edge/Gateway device timezone.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DeviceProperties.TimeZone"),
},
{
Name: "configured_role_types",
Description: "Type of compute roles configured.",
Type: proto.ColumnType_JSON,
Transform: transform.FromField("DeviceProperties.ConfiguredRoleTypes"),
},

// Steampipe standard columns
{
Name: "title",
Description: ColumnDescriptionTitle,
Type: proto.ColumnType_STRING,
Transform: transform.FromField("Name"),
},
{
Name: "tags",
Description: ColumnDescriptionTags,
Type: proto.ColumnType_JSON,
},
{
Name: "akas",
Description: ColumnDescriptionAkas,
Type: proto.ColumnType_JSON,
Transform: transform.FromField("ID").Transform(idToAkas),
},

// Azure standard columns
{
Name: "region",
Description: ColumnDescriptionRegion,
Type: proto.ColumnType_STRING,
Transform: transform.FromField("Location").Transform(toLower),
},
{
Name: "resource_group",
Description: ColumnDescriptionResourceGroup,
Type: proto.ColumnType_STRING,
Transform: transform.FromField("ID").Transform(extractResourceGroupFromID),
},
{
Name: "subscription_id",
Description: ColumnDescriptionSubscription,
Type: proto.ColumnType_STRING,
Transform: transform.FromField("ID").Transform(idToSubscriptionID),
},
},
}
}

//// LIST FUNCTION

func listDataBoxEdgeDevices(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
plugin.Logger(ctx).Trace("listDataBoxEdgeDevices")
session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
return nil, err
}
subscriptionID := session.SubscriptionID

deviceClient := databoxedge.NewDevicesClient(subscriptionID)
deviceClient.Authorizer = session.Authorizer

result, err := deviceClient.ListBySubscription(ctx, "")
if err != nil {
plugin.Logger(ctx).Error("listDataBoxEdgeDevices", "ListBySubscription", err)
return nil, err
}
for _, device := range result.Values() {
d.StreamListItem(ctx, device)
}

for result.NotDone() {
err = result.NextWithContext(ctx)
if err != nil {
plugin.Logger(ctx).Error("listDataBoxEdgeDevices", "ListBySubscription_pagination", err)
return nil, err
}
for _, device := range result.Values() {
d.StreamListItem(ctx, device)
}

}
return nil, err
}

//// HYDRATE FUNCTIONS

func getDataBoxEdgeDevice(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
plugin.Logger(ctx).Trace("getDataBoxEdgeDevice")

name := d.KeyColumnQuals["name"].GetStringValue()
resourceGroup := d.KeyColumnQuals["resource_group"].GetStringValue()

// Return nil, if no input provide
if name == "" || resourceGroup == "" {
return nil, nil
}

// Create session
session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
return nil, err
}
subscriptionID := session.SubscriptionID

deviceClient := databoxedge.NewDevicesClient(subscriptionID)
deviceClient.Authorizer = session.Authorizer

op, err := deviceClient.Get(ctx, resourceGroup, name)
if err != nil {
return nil, err
}

return op, nil
}
Loading