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

Fix private_endpoint_connections column for table azure_mysql_server. Closes #304 #338

Merged
merged 2 commits into from
Sep 28, 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
6 changes: 3 additions & 3 deletions azure-test/tests/azure_mysql_server/test-get-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
"public_network_access": "Enabled",
"region": "eastus",
"resource_group": "{{ resourceName }}",
"sku_capacity": 1,
"sku_capacity": 2,
"sku_family": "Gen5",
"sku_name": "B_Gen5_1",
"sku_name": "B_Gen5_2",
"sku_tier": "Basic",
"ssl_enforcement": "Enabled",
"storage_auto_grow": "Disabled",
"storage_mb": 5120,
"subscription_id": "{{ output.subscription_id.value }}",
"type": "Microsoft.DBforMySQL/servers",
"version": "5.6"
"version": "5.7"
}
]
22 changes: 12 additions & 10 deletions azure-test/tests/azure_mysql_server/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,22 @@ variable "azure_subscription" {
description = "Azure subscription used for the test."
}

terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=2.73.0"
}
}
}

# Configure the Microsoft Azure Provider
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"
Expand All @@ -44,9 +46,9 @@ resource "azurerm_mysql_server" "named_test_resource" {
administrator_login = "mradministrator"
administrator_login_password = "H@Sh1CoR3!"

sku_name = "B_Gen5_1"
sku_name = "B_Gen5_2"
storage_mb = 5120
version = "5.6"
version = "5.7"

auto_grow_enabled = false
backup_retention_days = 7
Expand Down
45 changes: 43 additions & 2 deletions azure/table_azure_mysql_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func tableAzureMySQLServer(_ context.Context) *plugin.Table {
Name: "private_endpoint_connections",
Description: "A list of private endpoint connections on a server.",
Type: proto.ColumnType_JSON,
Transform: transform.FromField("ServerProperties.PrivateEndpointConnections"),
Transform: transform.From(extractMySQLServerPrivateEndpointConnections),
},

// Steampipe standard columns
Expand Down Expand Up @@ -247,6 +247,7 @@ func listMySQLServers(ctx context.Context, d *plugin.QueryData, _ *plugin.Hydrat

result, err := client.List(ctx)
if err != nil {
plugin.Logger(ctx).Error("listMySQLServers", "list", err)
return nil, err
}

Expand All @@ -258,7 +259,7 @@ func listMySQLServers(ctx context.Context, d *plugin.QueryData, _ *plugin.Hydrat
return nil, err
}

//// HYDRATE FUNCTIONS
//// HYDRATE FUNCTION

func getMySQLServer(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
plugin.Logger(ctx).Trace("getMySQLServer")
Expand All @@ -283,6 +284,7 @@ func getMySQLServer(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateD

op, err := client.Get(ctx, resourceGroup, name)
if err != nil {
plugin.Logger(ctx).Error("getMySQLServer", "get", err)
return nil, err
}

Expand All @@ -294,3 +296,42 @@ func getMySQLServer(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateD

return nil, nil
}

//// TRANSFORM FUNCTION

// If we return the API response directly, the output will not provide the properties of PrivateEndpointConnections
func extractMySQLServerPrivateEndpointConnections(ctx context.Context, d *transform.TransformData) (interface{}, error) {
server := d.HydrateItem.(mysql.Server)
var properties []map[string]interface{}

if server.ServerProperties.PrivateEndpointConnections != nil {
for _, i := range *server.ServerProperties.PrivateEndpointConnections {
objectMap := make(map[string]interface{})
if i.ID != nil {
objectMap["id"] = i.ID
}
if i.Properties != nil {
if i.Properties.PrivateEndpoint != nil {
objectMap["privateEndpointPropertyId"] = i.Properties.PrivateEndpoint.ID
}
if i.Properties.PrivateLinkServiceConnectionState != nil {
if len(i.Properties.PrivateLinkServiceConnectionState.ActionsRequired) > 0 {
objectMap["privateLinkServiceConnectionStateActionsRequired"] = i.Properties.PrivateLinkServiceConnectionState.ActionsRequired
}
if len(i.Properties.PrivateLinkServiceConnectionState.Status) > 0 {
objectMap["privateLinkServiceConnectionStateStatus"] = i.Properties.PrivateLinkServiceConnectionState.Status
}
if i.Properties.PrivateLinkServiceConnectionState.Description != nil {
objectMap["privateLinkServiceConnectionStateDescription"] = i.Properties.PrivateLinkServiceConnectionState.Description
}
}
if len(i.Properties.ProvisioningState) > 0 {
objectMap["provisioningState"] = i.Properties.ProvisioningState
}
}
properties = append(properties, objectMap)
}
}

return properties, nil
}
17 changes: 17 additions & 0 deletions docs/tables/azure_mysql_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,20 @@ where
minimal_tls_version = 'TLS1_0'
or minimal_tls_version = 'TLS1_1';
```

### List private endpoint connection details

```sql
select
name as server_name,
id as server_id,
connections ->> 'id' as connection_id,
connections ->> 'privateEndpointPropertyId' as connection_private_endpoint_property_id,
connections ->> 'privateLinkServiceConnectionStateActionsRequired' as connection_actions_required,
connections ->> 'privateLinkServiceConnectionStateDescription' as connection_description,
connections ->> 'privateLinkServiceConnectionStateStatus' as connection_status,
connections ->> 'provisioningState' as connection_provisioning_state
from
azure_mysql_server,
jsonb_array_elements(private_endpoint_connections) as connections;
```