Skip to content

Commit

Permalink
Add table azure_cdn_frontdoor_profile Closes #764 (#777)
Browse files Browse the repository at this point in the history
Co-authored-by: Ved misra <[email protected]>
  • Loading branch information
ParthaI and misraved authored Jun 14, 2024
1 parent b9d8bc1 commit dcae814
Show file tree
Hide file tree
Showing 14 changed files with 410 additions and 0 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"id": "{{ output.resource_id.value }}",
"name": "{{ resourceName }}",
"resource_group": "{{ resourceName }}",
"subscription_id": "{{ output.subscription_id.value }}",
"type": "Microsoft.Cdn/profiles"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select name, id, type, resource_group, subscription_id
from azure.azure_cdn_frontdoor_profile
where name = '{{ resourceName }}' and resource_group = '{{ resourceName }}';
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"id": "{{ output.resource_id.value }}",
"name": "{{ resourceName }}",
"resource_group": "{{ resourceName }}",
"subscription_id": "{{ output.subscription_id.value }}",
"type": "Microsoft.Cdn/profiles"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select name, id, type, resource_group, subscription_id
from azure.azure_cdn_frontdoor_profile
where id = '{{ output.resource_id.value }}';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select name, id, type
from azure.azure_cdn_frontdoor_profile
where name = 'dummy-test{{ resourceName }}' and resource_group = '{{ 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_cdn_frontdoor_profile
where name = '{{ resourceName }}' and resource_group = '{{ resourceName }}';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
69 changes: 69 additions & 0 deletions azure-test/tests/azure_cdn_frontdoor_profile/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
variable "resource_name" {
type = string
default = "turbot-test-20200930-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 environment used for the test."
}

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

provider "azurerm" {
# Cannot be passed as a variable
environment = var.azure_environment
subscription_id = var.azure_subscription
features {}
}

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

resource "azurerm_cdn_frontdoor_profile" "named_test_resource" {
name = var.resource_name
resource_group_name = azurerm_resource_group.named_test_resource.name
sku_name = "Standard_AzureFrontDoor"

tags = {
environment = "Production"
}
}

output "resource_id" {
depends_on = [azurerm_cdn_frontdoor_profile.named_test_resource]
value = replace(replace(azurerm_cdn_frontdoor_profile.named_test_resource.id, "resourceGroups", "resourcegroups"), "Profiles", "profiles")
}

output "resource_aka" {
value = "azure://${replace(replace(azurerm_cdn_frontdoor_profile.named_test_resource.id, "resourceGroups", "resourcegroups"), "Profiles", "profiles")}"
}

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

output "resource_name" {
value = "${var.resource_name}"
}

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 @@ -53,6 +53,7 @@ func Plugin(ctx context.Context) *plugin.Plugin {
"azure_backup_policy": tableAzureBackupPolicy(ctx),
"azure_bastion_host": tableAzureBastionHost(ctx),
"azure_batch_account": tableAzureBatchAccount(ctx),
"azure_cdn_frontdoor_profile": tableAzureCDNFrontDoorProfile(ctx),
"azure_cognitive_account": tableAzureCognitiveAccount(ctx),
"azure_compute_availability_set": tableAzureComputeAvailabilitySet(ctx),
"azure_compute_disk": tableAzureComputeDisk(ctx),
Expand Down
196 changes: 196 additions & 0 deletions azure/table_azure_cdn_frontdoor_profile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
package azure

import (
"context"

"github.com/Azure/azure-sdk-for-go/profiles/latest/cdn/mgmt/cdn"
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
)

func tableAzureCDNFrontDoorProfile(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "azure_cdn_frontdoor_profile",
Description: "Azure CDN Front Door Profile",
Get: &plugin.GetConfig{
KeyColumns: plugin.AllColumns([]string{"name", "resource_group"}),
Hydrate: getAzureCDNFrontDoorProfile,
IgnoreConfig: &plugin.IgnoreConfig{
ShouldIgnoreErrorFunc: isNotFoundError([]string{"ResourceNotFound", "ResourceGroupNotFound", "404"}),
},
},
List: &plugin.ListConfig{
Hydrate: listAzureCDNFrontDoorProfiles,
},
Columns: azureColumns([]*plugin.Column{
{
Name: "name",
Description: "The name of the CDN front door profile.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("Name"),
},
{
Name: "id",
Description: "The resource identifier.",
Type: proto.ColumnType_STRING,
Transform: transform.FromGo(),
},
{
Name: "type",
Description: "The resource type.",
Type: proto.ColumnType_STRING,
},
{
Name: "location",
Description: "The location of the CDN front door profile.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("Location").Transform(toLower),
},
{
Name: "sku_name",
Description: "Name of the pricing tier.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("Sku.Name"),
},
{
Name: "kind",
Description: "Kind of the profile. Used by portal to differentiate traditional CDN profile and new AFD profile.",
Type: proto.ColumnType_STRING,
},
{
Name: "resource_state",
Description: "Resource status of the CDN front door profile.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("ProfileProperties.ResourceState").Transform(transform.ToString),
},
{
Name: "provisioning_state",
Description: "Provisioning status of the CDN front door profile.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("ProfileProperties.ProvisioningState"),
},
{
Name: "front_door_id",
Description: "The ID of the front door.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("ProfileProperties.FrontDoorID"),
},
{
Name: "origin_response_timeout_seconds",
Description: "Send and receive timeout on forwarding request to the origin. When timeout is reached, the request fails and returns.",
Type: proto.ColumnType_INT,
Transform: transform.FromField("ProfileProperties.OriginResponseTimeoutSeconds"),
},

// Steampipe standard columns
{
Name: "title",
Description: "Title of the resource.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("Name"),
},
{
Name: "tags",
Description: "Tags associated with the resource.",
Type: proto.ColumnType_JSON,
},
{
Name: "akas",
Description: "Array of globally unique identifier strings (also known as) for the resource.",
Type: proto.ColumnType_JSON,
Transform: transform.FromField("ID").Transform(idToAkas),
},

// Azure standard columns
{
Name: "region",
Description: "The Azure region where the resource is located.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("Location").Transform(toLower),
},
{
Name: "resource_group",
Description: "The resource group in which the resource is located.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("ID").Transform(extractResourceGroupFromID),
},
}),
}
}

//// LIST FUNCTION

func listAzureCDNFrontDoorProfiles(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
plugin.Logger(ctx).Error("azure_cdn_frontdoor_profile.listAzureCDNFrontDoorProfiles", "session_error", err)
return nil, err
}

subscriptionID := session.SubscriptionID
client := cdn.NewProfilesClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID)
client.Authorizer = session.Authorizer
result, err := client.List(ctx)
if err != nil {
plugin.Logger(ctx).Error("azure_cdn_frontdoor_profile.listAzureCDNFrontDoorProfiles", "api_error", err)
return nil, err
}

for _, profile := range result.Values() {
d.StreamListItem(ctx, profile)
if d.RowsRemaining(ctx) == 0 {
return nil, nil
}
}

for result.NotDone() {
err = result.NextWithContext(ctx)
if err != nil {
plugin.Logger(ctx).Error("azure_cdn_frontdoor_profile.listAzureCDNFrontDoorProfiles", "paging_error", err)
return nil, err
}
for _, profile := range result.Values() {
d.StreamListItem(ctx, profile)
if d.RowsRemaining(ctx) == 0 {
return nil, nil
}
}
}

return nil, nil
}

//// HYDRATE FUNCTION

func getAzureCDNFrontDoorProfile(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {

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

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

session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
plugin.Logger(ctx).Error("azure_cdn_frontdoor_profile.getAzureCDNFrontDoorProfile", "session_error", err)
return nil, err
}
subscriptionID := session.SubscriptionID
client := cdn.NewProfilesClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID)
client.Authorizer = session.Authorizer

profile, err := client.Get(ctx, resourceGroup, name)
if err != nil {
plugin.Logger(ctx).Error("azure_cdn_frontdoor_profile.getAzureCDNFrontDoorProfile", "api_error", err)
return nil, err
}

if profile.ID != nil {
return profile, nil
}

return nil, nil
}
Loading

0 comments on commit dcae814

Please sign in to comment.