-
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.
- Loading branch information
Showing
14 changed files
with
370 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
10 changes: 10 additions & 0 deletions
10
azure-test/tests/azure_automation_account/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,10 @@ | ||
[ | ||
{ | ||
"id": "{{ output.resource_id.value }}", | ||
"name": "{{ resourceName }}", | ||
"region": "{{ output.location.value }}", | ||
"resource_group": "{{ resourceName }}", | ||
"subscription_id": "{{ output.subscription_id.value }}", | ||
"type": "Microsoft.Automation/AutomationAccounts" | ||
} | ||
] |
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, region, resource_group, subscription_id | ||
from azure.azure_automation_account | ||
where name = '{{ resourceName }}' and resource_group = '{{ resourceName }}'; |
7 changes: 7 additions & 0 deletions
7
azure-test/tests/azure_automation_account/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,7 @@ | ||
[ | ||
{ | ||
"id": "{{ output.resource_id.value }}", | ||
"name": "{{ resourceName }}", | ||
"type": "Microsoft.Automation/AutomationAccounts" | ||
} | ||
] |
3 changes: 3 additions & 0 deletions
3
azure-test/tests/azure_automation_account/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 | ||
from azure.azure_automation_account | ||
where name = '{{ resourceName }}'; |
1 change: 1 addition & 0 deletions
1
azure-test/tests/azure_automation_account/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 @@ | ||
null |
3 changes: 3 additions & 0 deletions
3
azure-test/tests/azure_automation_account/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, tags, title, akas | ||
from azure.azure_automation_account | ||
where name = 'dummy-{{ resourceName }}' and resource_group = '{{ resourceName }}'; |
10 changes: 10 additions & 0 deletions
10
azure-test/tests/azure_automation_account/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_automation_account/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, title, akas | ||
from azure.azure_automation_account | ||
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,72 @@ | ||
variable "resource_name" { | ||
type = string | ||
default = "steampipe-test" | ||
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" | ||
} | ||
|
||
resource "azurerm_automation_account" "named_test_resource" { | ||
name = var.resource_name | ||
location = azurerm_resource_group.named_test_resource.location | ||
resource_group_name = azurerm_resource_group.named_test_resource.name | ||
sku_name = "Basic" | ||
|
||
tags = { | ||
name = var.resource_name | ||
} | ||
} | ||
|
||
output "resource_aka" { | ||
value = "azure://${azurerm_automation_account.named_test_resource.id}" | ||
} | ||
|
||
output "resource_aka_lower" { | ||
value = "azure://${lower(azurerm_automation_account.named_test_resource.id)}" | ||
} | ||
|
||
output "resource_name" { | ||
value = var.resource_name | ||
} | ||
|
||
output "resource_id" { | ||
value = azurerm_automation_account.named_test_resource.id | ||
} | ||
|
||
output "location" { | ||
value = azurerm_resource_group.named_test_resource.location | ||
} | ||
|
||
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,208 @@ | ||
package azure | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/automation/mgmt/2019-06-01/automation" | ||
"github.com/turbot/steampipe-plugin-sdk/v4/grpc/proto" | ||
"github.com/turbot/steampipe-plugin-sdk/v4/plugin/transform" | ||
|
||
"github.com/turbot/steampipe-plugin-sdk/v4/plugin" | ||
) | ||
|
||
//// TABLE DEFINITION //// | ||
|
||
func tableAzureApAutomationAccount(_ context.Context) *plugin.Table { | ||
return &plugin.Table{ | ||
Name: "azure_automation_account", | ||
Description: "Azure Automation Account", | ||
Get: &plugin.GetConfig{ | ||
KeyColumns: plugin.AllColumns([]string{"name", "resource_group"}), | ||
Hydrate: getAutomationAccount, | ||
IgnoreConfig: &plugin.IgnoreConfig{ | ||
ShouldIgnoreErrorFunc: isNotFoundError([]string{"ResourceNotFound", "ResourceGroupNotFound", "404"}), | ||
}, | ||
}, | ||
List: &plugin.ListConfig{ | ||
Hydrate: listAutomationAccounts, | ||
}, | ||
Columns: azureColumns([]*plugin.Column{ | ||
{ | ||
Name: "name", | ||
Type: proto.ColumnType_STRING, | ||
Description: "The name of the resource.", | ||
}, | ||
{ | ||
Name: "id", | ||
Description: "Fully qualified resource ID.", | ||
Type: proto.ColumnType_STRING, | ||
Transform: transform.FromGo(), | ||
}, | ||
{ | ||
Name: "description", | ||
Description: "The description for the account.", | ||
Type: proto.ColumnType_STRING, | ||
Transform: transform.FromField("AccountProperties.Description"), | ||
}, | ||
{ | ||
Name: "etag", | ||
Description: "Gets the etag of the resource.", | ||
Type: proto.ColumnType_STRING, | ||
}, | ||
{ | ||
Name: "creation_time", | ||
Description: "The creation time of the account.", | ||
Type: proto.ColumnType_TIMESTAMP, | ||
Transform: transform.FromField("AccountProperties.CreationTime.Time"), | ||
}, | ||
{ | ||
Name: "last_modified_time", | ||
Description: "The last modified time of the account.", | ||
Type: proto.ColumnType_TIMESTAMP, | ||
Transform: transform.FromField("AccountProperties.LastModifiedTime.Time"), | ||
}, | ||
{ | ||
Name: "last_modified_by", | ||
Description: "The account last modified by.", | ||
Type: proto.ColumnType_STRING, | ||
Transform: transform.FromField("AccountProperties.LastModifiedBy"), | ||
}, | ||
{ | ||
Name: "type", | ||
Description: "The type of the resource.", | ||
Type: proto.ColumnType_STRING, | ||
}, | ||
{ | ||
Name: "state", | ||
Description: "The status of account. Possible values include: 'AccountStateOk', 'AccountStateUnavailable', 'AccountStateSuspended'.", | ||
Type: proto.ColumnType_STRING, | ||
Transform: transform.FromField("AccountProperties.State"), | ||
}, | ||
{ | ||
Name: "sku_name", | ||
Description: "The SKU name of the account. Possible values include: 'SkuNameEnumFree', 'SkuNameEnumBasic'.", | ||
Type: proto.ColumnType_STRING, | ||
Transform: transform.FromField("Sku.Name"), | ||
}, | ||
{ | ||
Name: "sku_family", | ||
Description: "The SKU family of the account.", | ||
Type: proto.ColumnType_STRING, | ||
Transform: transform.FromField("Sku.Family"), | ||
}, | ||
{ | ||
Name: "sku_capacity", | ||
Description: "The SKU capacity of the account.", | ||
Type: proto.ColumnType_STRING, | ||
Transform: transform.FromField("Sku.Capacity"), | ||
}, | ||
|
||
// 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), | ||
}, | ||
}), | ||
} | ||
} | ||
|
||
//// LIST FUNCTION //// | ||
|
||
func listAutomationAccounts(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { | ||
session, err := GetNewSession(ctx, d, "MANAGEMENT") | ||
if err != nil { | ||
return nil, err | ||
} | ||
subscriptionID := session.SubscriptionID | ||
|
||
accountClient := automation.NewAccountClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID) | ||
accountClient.Authorizer = session.Authorizer | ||
|
||
result, err := accountClient.List(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, account := range result.Values() { | ||
d.StreamListItem(ctx, account) | ||
// 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.QueryStatus.RowsRemaining(ctx) == 0 { | ||
return nil, nil | ||
} | ||
} | ||
|
||
for result.NotDone() { | ||
err = result.NextWithContext(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, account := range result.Values() { | ||
d.StreamListItem(ctx, account) | ||
// 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.QueryStatus.RowsRemaining(ctx) == 0 { | ||
return nil, nil | ||
} | ||
} | ||
} | ||
return nil, err | ||
} | ||
|
||
//// HYDRATE FUNCTIONS //// | ||
|
||
func getAutomationAccount(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
|
||
name := d.KeyColumnQuals["name"].GetStringValue() | ||
resourceGroup := d.KeyColumnQuals["resource_group"].GetStringValue() | ||
|
||
session, err := GetNewSession(ctx, d, "MANAGEMENT") | ||
if err != nil { | ||
return nil, err | ||
} | ||
subscriptionID := session.SubscriptionID | ||
|
||
accountClient := automation.NewAccountClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID) | ||
accountClient.Authorizer = session.Authorizer | ||
|
||
op, err := accountClient.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// In some cases resource does not give any notFound error | ||
// Instead 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Table: azure_automation_account | ||
|
||
Automation accounts allow you to isolate your Automation resources, runbooks, assets, and configurations from the resources of other accounts. You can use Automation accounts to separate resources into separate logical environments or delegated responsibilities. | ||
|
||
## Examples | ||
|
||
### Basic info | ||
|
||
```sql | ||
select | ||
name, | ||
id, | ||
resource_group, | ||
type | ||
from | ||
azure_automation_account; | ||
``` | ||
|
||
### List accounts that are created in last 30 days | ||
|
||
```sql | ||
select | ||
name, | ||
id, | ||
resource_group, | ||
type, | ||
creation_time | ||
from | ||
azure_automation_account | ||
where | ||
creation_time >= now() - interval '30' day; | ||
``` | ||
|
||
### List accounts that are suspended | ||
|
||
```sql | ||
select | ||
name, | ||
id, | ||
resource_group, | ||
type, | ||
creation_time, | ||
state | ||
from | ||
azure_automation_account | ||
where | ||
state = 'AccountStateSuspended'; | ||
``` |