diff --git a/azure/table_azure_cosmosdb_account.go b/azure/table_azure_cosmosdb_account.go index 48b829c1..aa18c53f 100644 --- a/azure/table_azure_cosmosdb_account.go +++ b/azure/table_azure_cosmosdb_account.go @@ -4,7 +4,7 @@ import ( "context" "strings" - "github.com/Azure/azure-sdk-for-go/services/preview/cosmos-db/mgmt/2020-04-01-preview/documentdb" + "github.com/Azure/azure-sdk-for-go/services/preview/cosmos-db/mgmt/2021-04-01-preview/documentdb" "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" @@ -166,6 +166,12 @@ func tableAzureCosmosDBAccount(_ context.Context) *plugin.Table { Type: proto.ColumnType_STRING, Transform: transform.FromField("DatabaseAccount.DatabaseAccountGetProperties.APIProperties.ServerVersion").Transform(transform.ToString), }, + { + Name: "backup_policy", + Description: "The object representing the policy for taking backups on an account.", + Type: proto.ColumnType_JSON, + Transform: transform.FromField("DatabaseAccount.DatabaseAccountGetProperties.BackupPolicy"), + }, { Name: "capabilities", Description: "A list of Cosmos DB capabilities for the account.", @@ -200,7 +206,7 @@ func tableAzureCosmosDBAccount(_ context.Context) *plugin.Table { Name: "private_endpoint_connections", Description: "A list of Private Endpoint Connections configured for the Cosmos DB account.", Type: proto.ColumnType_JSON, - Transform: transform.FromField("DatabaseAccount.DatabaseAccountGetProperties.PrivateEndpointConnections"), + Transform: transform.From(cosmosDBPrivateEndpointConnectionMap), }, { Name: "read_locations", @@ -323,3 +329,53 @@ func extractCosmosDBVirtualNetworkRule(ctx context.Context, d *transform.Transfo } return nil, nil } + +// If we return the API response directly, the output will not give +// all the contents of PrivateEndpointConnection +func cosmosDBPrivateEndpointConnectionMap(ctx context.Context, d *transform.TransformData) (interface{}, error) { + info := d.HydrateItem.(databaseAccountInfo) + conns := info.DatabaseAccount.PrivateEndpointConnections + + if len(*conns) == 0 { + return nil, nil + } + + var privateEndpointConnections []PrivateConnectionInfo + + for _, conn := range *conns { + var connection PrivateConnectionInfo + if conn.ID != nil { + connection.PrivateEndpointConnectionId = string(*conn.ID) + } + if conn.Name != nil { + connection.PrivateEndpointConnectionName = string(*conn.Name) + } + if conn.Type != nil { + connection.PrivateEndpointConnectionType = string(*conn.Type) + } + if conn.PrivateEndpointConnectionProperties != nil { + if conn.PrivateEndpoint != nil { + if conn.PrivateEndpoint.ID != nil { + connection.PrivateEndpointId = string(*conn.PrivateEndpoint.ID) + } + } + if conn.PrivateLinkServiceConnectionState != nil { + if conn.PrivateLinkServiceConnectionState.ActionsRequired != nil { + connection.PrivateLinkServiceConnectionStateActionsRequired = string(*conn.PrivateLinkServiceConnectionState.ActionsRequired) + } + if conn.PrivateLinkServiceConnectionState.Status != nil { + connection.PrivateLinkServiceConnectionStateStatus = string(*conn.PrivateLinkServiceConnectionState.Status) + } + if conn.PrivateLinkServiceConnectionState.Description != nil { + connection.PrivateLinkServiceConnectionStateDescription = string(*conn.PrivateLinkServiceConnectionState.Description) + } + } + if conn.ProvisioningState != nil { + connection.ProvisioningState = string(*conn.ProvisioningState) + } + } + privateEndpointConnections = append(privateEndpointConnections, connection) + } + + return privateEndpointConnections, nil +} diff --git a/docs/tables/azure_cosmosdb_account.md b/docs/tables/azure_cosmosdb_account.md index aecc7f78..00f79b53 100644 --- a/docs/tables/azure_cosmosdb_account.md +++ b/docs/tables/azure_cosmosdb_account.md @@ -9,20 +9,21 @@ Azure Cosmos DB is a fully managed NoSQL database service for modern app develop ```sql select name, - location, + region, enable_automatic_failover, resource_group from - azure_cosmosdb_account; + azure_cosmosdb_account +where + not enable_automatic_failover; ``` - ### List of database accounts which allows traffic from all networks, including the public Internet. ```sql select name, - location, + region, virtual_network_rules from azure_cosmosdb_account @@ -30,13 +31,12 @@ where virtual_network_rules = '[]'; ``` - ### List of database accounts where multiple write location is not enabled ```sql select name, - location, + region, enable_multiple_write_locations from azure_cosmosdb_account @@ -44,7 +44,6 @@ where not enable_multiple_write_locations; ``` - ### Failover policy info for the database accounts ```sql @@ -57,7 +56,6 @@ from cross join jsonb_array_elements(failover_policies) as fp; ``` - ### Consistency policy info for each account ```sql @@ -69,4 +67,36 @@ select default_consistency_level from azure_cosmosdb_account; -``` \ No newline at end of file +``` + +### Get backup policy for accounts having periodic backups enabled + +```sql +select + name, + region, + backup_policy -> 'periodicModeProperties' ->> 'backupIntervalInMinutes' as backup_interval_mins, + backup_policy -> 'periodicModeProperties' ->> 'backupRetentionIntervalInHours' as backup_retention_interval_hrs, + backup_policy -> 'periodicModeProperties' ->> 'backupStorageRedundancy' as backup_storage_redundancy +from + azure_cosmosdb_account +where + backup_policy ->> 'type' = 'Periodic'; +``` + +### Get private endpoint connection details for each account + +```sql +select + c ->> 'PrivateEndpointConnectionName' as private_endpoint_connection_name, + c ->> 'PrivateEndpointConnectionType' as private_endpoint_connection_type, + c ->> 'PrivateEndpointId' as private_endpoint_id, + c ->> 'PrivateLinkServiceConnectionStateActionsRequired' as private_link_service_connection_state_actions_required, + c ->> 'PrivateLinkServiceConnectionStateDescription' as private_link_service_connection_state_description, + c ->> 'PrivateLinkServiceConnectionStateStatus' as private_link_service_connection_state_status, + c ->> 'ProvisioningState' as provisioning_state, + c ->> 'PrivateEndpointConnectionId' as private_endpoint_connection_id +from + azure_cosmosdb_account, + jsonb_array_elements(private_endpoint_connections) as c; +```