-
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.
Add azure_private_dns_zone table (#583)
- Loading branch information
Showing
14 changed files
with
368 additions
and
9 deletions.
There are no files selected for viewing
Empty file.
8 changes: 8 additions & 0 deletions
8
azure-test/tests/azure_private_dns_zone/test-get-expected.json
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,8 @@ | ||
[ | ||
{ | ||
"id": "{{ output.resource_id.value }}", | ||
"name": "{{resourceName}}.local", | ||
"region": "global", | ||
"type": "Microsoft.Network/privateDnsZones" | ||
} | ||
] |
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,6 @@ | ||
select name, | ||
id, | ||
region, | ||
type | ||
from azure.azure_private_dns_zone | ||
where name = '{{resourceName}}.local' |
13 changes: 13 additions & 0 deletions
13
azure-test/tests/azure_private_dns_zone/test-hydrate-expected.json
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,13 @@ | ||
[ | ||
{ | ||
"akas": [ | ||
"{{ output.resource_aka.value }}", | ||
"azure:///subscriptions/{{ output.subscription_id.value }}/resourcegroups/{{resourceName}}/providers/microsoft.network/privatednszones/{{resourceName}}.local" | ||
], | ||
"name": "{{resourceName}}.local", | ||
"tags": { | ||
"name": "{{resourceName}}.local" | ||
}, | ||
"title": "{{resourceName}}.local" | ||
} | ||
] |
6 changes: 6 additions & 0 deletions
6
azure-test/tests/azure_private_dns_zone/test-hydrate-query.sql
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,6 @@ | ||
select name, | ||
akas, | ||
tags, | ||
title | ||
from azure.azure_private_dns_zone | ||
where name = '{{resourceName}}.local' |
6 changes: 6 additions & 0 deletions
6
azure-test/tests/azure_private_dns_zone/test-list-expected.json
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,6 @@ | ||
[ | ||
{ | ||
"id": "{{ output.resource_id.value }}", | ||
"name": "{{resourceName}}.local" | ||
} | ||
] |
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,4 @@ | ||
select id, | ||
name | ||
from azure.azure_private_dns_zone | ||
where id = '{{ output.resource_id.value }}' |
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 @@ | ||
{} |
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,68 @@ | ||
|
||
variable "resource_name" { | ||
type = string | ||
default = "turbot-test-20230313-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" { | ||
# Cannot be passed as a variable | ||
environment = var.azure_environment | ||
subscription_id = var.azure_subscription | ||
features {} | ||
} | ||
|
||
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" | ||
tags = { | ||
name = var.resource_name | ||
} | ||
} | ||
|
||
resource "azurerm_private_dns_zone" "named_test_resource" { | ||
name = "${var.resource_name}.local" | ||
resource_group_name = azurerm_resource_group.named_test_resource.name | ||
|
||
tags = { | ||
name = "${var.resource_name}.local" | ||
} | ||
} | ||
|
||
output "resource_aka" { | ||
# Azure always puts privateDnsZones with lowercase d and z | ||
value = replace("azure://${azurerm_private_dns_zone.named_test_resource.id}", "Microsoft.Network/PrivateDnsZones", "Microsoft.Network/privatednszones") | ||
} | ||
|
||
output "resource_name" { | ||
value = var.resource_name | ||
} | ||
|
||
output "resource_id" { | ||
# Azure always puts dnsZones with with lowercase d and z | ||
value = replace(azurerm_private_dns_zone.named_test_resource.id, "Microsoft.Network/PrivateDnsZones", "Microsoft.Network/privatednszones") | ||
} | ||
|
||
output "subscription_id" { | ||
value = var.azure_subscription | ||
} |
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
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,207 @@ | ||
package azure | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/dns/mgmt/2018-05-01/dns" | ||
"github.com/Azure/azure-sdk-for-go/services/privatedns/mgmt/2018-09-01/privatedns" | ||
"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 tableAzurePrivateDNSZone(_ context.Context) *plugin.Table { | ||
return &plugin.Table{ | ||
Name: "azure_private_dns_zone", | ||
Description: "Azure Private DNS Zone", | ||
Get: &plugin.GetConfig{ | ||
KeyColumns: plugin.AllColumns([]string{"name", "resource_group"}), | ||
Hydrate: getPrivateDNSZone, | ||
IgnoreConfig: &plugin.IgnoreConfig{ | ||
ShouldIgnoreErrorFunc: isNotFoundError([]string{"ResourceNotFound", "ResourceGroupNotFound", "404"}), | ||
}, | ||
}, | ||
List: &plugin.ListConfig{ | ||
Hydrate: listPrivateDNSZones, | ||
}, | ||
Columns: azureColumns([]*plugin.Column{ | ||
{ | ||
Name: "name", | ||
Type: proto.ColumnType_STRING, | ||
Description: "The friendly name that identifies the Private DNS zone.", | ||
}, | ||
{ | ||
Name: "id", | ||
Description: "Contains ID to identify a Private DNS zone uniquely.", | ||
Type: proto.ColumnType_STRING, | ||
Transform: transform.FromGo(), | ||
}, | ||
{ | ||
Name: "etag", | ||
Description: "An unique read-only string that changes whenever the resource is updated.", | ||
Type: proto.ColumnType_STRING, | ||
}, | ||
{ | ||
Name: "type", | ||
Description: "The resource type of the Private DNS zone.", | ||
Type: proto.ColumnType_STRING, | ||
}, | ||
{ | ||
Name: "max_number_of_record_sets", | ||
Description: "The maximum number of record sets that can be created in this Private DNS zone.", | ||
Type: proto.ColumnType_INT, | ||
Transform: transform.FromField("PrivateZoneProperties.MaxNumberOfRecordSets"), | ||
}, | ||
{ | ||
Name: "number_of_record_sets", | ||
Description: "The current number of record sets in this Private DNS zone.", | ||
Type: proto.ColumnType_INT, | ||
Transform: transform.FromField("PrivateZoneProperties.NumberOfRecordSets").Transform(transform.ToString), | ||
}, | ||
{ | ||
Name: "max_number_of_virtual_network_links", | ||
Description: "The maximum number of virtual networks that can be linked to this Private DNS zone.", | ||
Type: proto.ColumnType_INT, | ||
Transform: transform.FromField("PrivateZoneProperties.MaxNumberOfVirtualNetworkLinks"), | ||
}, | ||
{ | ||
Name: "number_of_virtual_network_links", | ||
Description: "The current number of virtual networks that are linked to this Private DNS zone.", | ||
Type: proto.ColumnType_INT, | ||
Transform: transform.FromField("PrivateZoneProperties.NumberOfVirtualNetworkLinks"), | ||
}, | ||
{ | ||
Name: "max_number_of_virtual_network_links_with_registration", | ||
Description: "The maximum number of virtual networks that can be linked to this Private DNS zone with registration enabled.", | ||
Type: proto.ColumnType_INT, | ||
Transform: transform.FromField("PrivateZoneProperties.MaxNumberOfVirtualNetworkLinksWithRegistration"), | ||
}, | ||
{ | ||
Name: "number_of_virtual_network_links_with_registration", | ||
Description: "The current number of virtual networks that are linked to this Private DNS zone with registration enabled.", | ||
Type: proto.ColumnType_INT, | ||
Transform: transform.FromField("PrivateZoneProperties.NumberOfVirtualNetworkLinksWithRegistration"), | ||
}, | ||
{ | ||
Name: "provisioning_state", | ||
Description: "The provisioning state of the resource. Possible values include: `Creating`, `Updating`, `Deleting`, `Succeeded`, `Failed`, `Canceled`.", | ||
Type: proto.ColumnType_STRING, | ||
Transform: transform.FromField("PrivateZoneProperties.ProvisioningState"), | ||
}, | ||
|
||
// 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), | ||
}, | ||
}), | ||
} | ||
} | ||
|
||
//// FETCH FUNCTIONS //// | ||
|
||
func listPrivateDNSZones(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
session, err := GetNewSession(ctx, d, "MANAGEMENT") | ||
if err != nil { | ||
plugin.Logger(ctx).Error("azure_private_dns_zone.listPrivateDNSZones", "client_error", err) | ||
return nil, err | ||
} | ||
subscriptionID := session.SubscriptionID | ||
|
||
dnsClient := privatedns.NewPrivateZonesClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID) | ||
dnsClient.Authorizer = session.Authorizer | ||
|
||
result, err := dnsClient.List(ctx, nil) | ||
if err != nil { | ||
plugin.Logger(ctx).Error("azure_private_dns_zone.listPrivateDNSZones", "query_error", err) | ||
return nil, err | ||
} | ||
for _, dnsZone := range result.Values() { | ||
d.StreamListItem(ctx, dnsZone) | ||
// 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 | ||
} | ||
} | ||
|
||
for result.NotDone() { | ||
err = result.NextWithContext(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, dnsZone := range result.Values() { | ||
d.StreamListItem(ctx, dnsZone) | ||
// 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 | ||
} | ||
|
||
//// HYDRATE FUNCTIONS //// | ||
|
||
func getPrivateDNSZone(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
plugin.Logger(ctx).Trace("getPrivateDNSZone") | ||
|
||
name := d.EqualsQuals["name"].GetStringValue() | ||
resourceGroup := d.EqualsQuals["resource_group"].GetStringValue() | ||
|
||
session, err := GetNewSession(ctx, d, "MANAGEMENT") | ||
if err != nil { | ||
plugin.Logger(ctx).Error("azure_private_dns_zone.getPrivateDNSZone", "client_error", err) | ||
return nil, err | ||
} | ||
subscriptionID := session.SubscriptionID | ||
|
||
dnsClient := dns.NewZonesClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID) | ||
dnsClient.Authorizer = session.Authorizer | ||
|
||
op, err := dnsClient.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
plugin.Logger(ctx).Error("azure_private_dns_zone.getPrivateDNSZone", "query_error", err) | ||
return nil, err | ||
} | ||
|
||
// In some cases resource does not give any notFound error | ||
// instead of notFound error, it returns empty data | ||
if op.ID != nil { | ||
return op, 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
Oops, something went wrong.