-
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.
Browse files
Browse the repository at this point in the history
Co-authored-by: Ved misra <[email protected]>
- Loading branch information
Showing
14 changed files
with
410 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
9 changes: 9 additions & 0 deletions
9
azure-test/tests/azure_cdn_frontdoor_profile/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,9 @@ | ||
[ | ||
{ | ||
"id": "{{ output.resource_id.value }}", | ||
"name": "{{ resourceName }}", | ||
"resource_group": "{{ resourceName }}", | ||
"subscription_id": "{{ output.subscription_id.value }}", | ||
"type": "Microsoft.Cdn/profiles" | ||
} | ||
] |
3 changes: 3 additions & 0 deletions
3
azure-test/tests/azure_cdn_frontdoor_profile/test-get-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,3 @@ | ||
select name, id, type, resource_group, subscription_id | ||
from azure.azure_cdn_frontdoor_profile | ||
where name = '{{ resourceName }}' and resource_group = '{{ resourceName }}'; |
9 changes: 9 additions & 0 deletions
9
azure-test/tests/azure_cdn_frontdoor_profile/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,9 @@ | ||
[ | ||
{ | ||
"id": "{{ output.resource_id.value }}", | ||
"name": "{{ resourceName }}", | ||
"resource_group": "{{ resourceName }}", | ||
"subscription_id": "{{ output.subscription_id.value }}", | ||
"type": "Microsoft.Cdn/profiles" | ||
} | ||
] |
3 changes: 3 additions & 0 deletions
3
azure-test/tests/azure_cdn_frontdoor_profile/test-list-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,3 @@ | ||
select name, id, type, resource_group, subscription_id | ||
from azure.azure_cdn_frontdoor_profile | ||
where id = '{{ output.resource_id.value }}'; |
1 change: 1 addition & 0 deletions
1
azure-test/tests/azure_cdn_frontdoor_profile/test-not-found-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 @@ | ||
[] |
3 changes: 3 additions & 0 deletions
3
azure-test/tests/azure_cdn_frontdoor_profile/test-not-found-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,3 @@ | ||
select name, id, type | ||
from azure.azure_cdn_frontdoor_profile | ||
where name = 'dummy-test{{ resourceName }}' and resource_group = '{{ resourceName }}'; |
10 changes: 10 additions & 0 deletions
10
azure-test/tests/azure_cdn_frontdoor_profile/test-turbot-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,10 @@ | ||
[ | ||
{ | ||
"akas": [ | ||
"{{ output.resource_aka.value }}", | ||
"{{ output.resource_aka_lower.value }}" | ||
], | ||
"name": "{{ resourceName }}", | ||
"title": "{{ resourceName }}" | ||
} | ||
] |
3 changes: 3 additions & 0 deletions
3
azure-test/tests/azure_cdn_frontdoor_profile/test-turbot-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,3 @@ | ||
select name, akas, title | ||
from azure.azure_cdn_frontdoor_profile | ||
where name = '{{ resourceName }}' and resource_group = '{{ resourceName }}'; |
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,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 | ||
} |
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,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 | ||
} |
Oops, something went wrong.