-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cloudexport azure automation across resourcegroups (#45)
* Add kentik-side cloudexport configuration for azure * Add service principal creation to further automate onboarding * Azure cloudexport across resource groups
- Loading branch information
1 parent
407177d
commit 74a4e20
Showing
19 changed files
with
317 additions
and
128 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
Code for preparing Azure cloud to work with portal.kentik.com [portal.kentik.com](https://portal.kentik.com) | ||
# Automation support for configuring flow log export from Azure to [Kentik](https://portal.kentik.com) | ||
|
||
Currently supported: | ||
* [terraform](terraform/module) | ||
* [ansible](ansible/roles/kentik_az) | ||
Currently supported frameworks: | ||
* [Terraform] (terrafrom/module) | ||
* [Ansible] (ansible/roles/kentik_az) |
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,27 @@ | ||
terraform { | ||
required_providers { | ||
kentik-cloudexport = { | ||
source = "kentik/kentik-cloudexport" | ||
version = ">= 0.4.1" | ||
} | ||
} | ||
} | ||
|
||
# Creates one Kentik CloudExport for each requested Resource Group | ||
resource "kentik-cloudexport_item" "azure_export" { | ||
count = length(var.resource_group_names) | ||
|
||
name = "${var.name}_${var.resource_group_names[count.index]}" # name must be unique | ||
type = "CLOUD_EXPORT_TYPE_KENTIK_MANAGED" | ||
enabled = var.enabled | ||
description = var.description | ||
plan_id = var.plan_id | ||
cloud_provider = "azure" | ||
azure { | ||
location = var.location | ||
resource_group = var.resource_group_names[count.index] | ||
storage_account = azurerm_storage_account.logs_storage_account[count.index].name # storage accounts are mapped to resource groups 1:1 | ||
subscription_id = var.subscription_id | ||
security_principal_enabled = true | ||
} | ||
} |
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 |
---|---|---|
@@ -1,35 +1,51 @@ | ||
# All Network Security Groups in Resource Group | ||
# All Network Security Groups in requested Resource Groups | ||
|
||
Configuration in this directory creates configuration for all Network Security Group in Resource Group. | ||
This example creates cloud export configuration for all Network Security Groups in requested Resource Groups. | ||
|
||
## Requirements | ||
|
||
* Information about Azure deployment: location, resource group names, subscription ID | ||
* Information about Kentik subscription: plan ID | ||
* Azure CLI - [Installation](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli) | ||
* Authenticating Azure CLI to your account - [Logging-in](https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli) | ||
* Kentik API credentials present in execution environment: | ||
```bash | ||
export KTAPI_AUTH_EMAIL="[email protected]" | ||
export KTAPI_AUTH_TOKEN="token123" | ||
``` | ||
|
||
## Usage | ||
|
||
To run this example you need to execute: | ||
``` | ||
$ terraform init | ||
$ terraform plan | ||
$ terraform apply | ||
$ terraform apply \ | ||
--var subscription_id=<azure_subscription_id> \ | ||
--var location=<azure_location> \ | ||
--var resource_group_names=<resource_group_names> \ | ||
--var prefix=<unique_prefix_for_azure_resources> \ | ||
--var plan_id=<kentik_plan_id> \ | ||
--var name=<kentik_cloudexport_name> | ||
``` | ||
|
||
## Requirements | ||
|
||
* Example requires location, resource group name, principal id, subscription | ||
* Installed and logged az-cli [Installation](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli) [Logging](https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli) | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| location | Azure location of the resources to gather logs | `string` | `` | yes | | ||
| subscription_id | Id of the subscription in which resource are located | `string` | `` | yes | | ||
| resource_group_name | Name of the resource group to gather logs from | `string` | `` | yes | | ||
| principal_id | Id of the Service Principal Id for kentik app connection | `string` | `` | yes | | ||
| resource_group_names | List of Resource Group names to gather logs from | `list of strings` | `` | yes | | ||
| prefix| Prefix for the naming resources | `string` | `` | yes | | ||
| plan_id | Billing plan ID | `string` | `` | yes | | ||
| name | Cloudexport entry name in Kentik | `string` | `` | yes | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| network_security_groups | Id's of the Network Security groups that logs will be gathered from | | ||
| subscription_id | Subscription Id | | ||
| resource_group | Resource group name | | ||
| storage_account | Storage account name where logs will be gathered | | ||
| resource_group_names | Resource group names | | ||
| storage_accounts | Storage account names where logs will be gathered | | ||
| principal_id | Principal ID created for Kentik NSG Flow Exporter application | |
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 |
---|---|---|
@@ -1,16 +1,32 @@ | ||
terraform { | ||
required_version = ">= 0.12.0" | ||
required_version = ">= 1.0.0" | ||
required_providers { | ||
azurerm = { | ||
source = "hashicorp/azurerm" | ||
version = ">= 2.85.0" | ||
} | ||
azuread = { | ||
source = "hashicorp/azuread" | ||
version = ">= 2.14.0" | ||
} | ||
kentik-cloudexport = { | ||
source = "kentik/kentik-cloudexport" | ||
version = ">= 0.4.1" | ||
} | ||
} | ||
} | ||
|
||
provider "azurerm" { | ||
version = "=2.20.0" | ||
features {} | ||
} | ||
|
||
|
||
module kentik_azure_integration { | ||
source = "../../" | ||
location = var.location | ||
resource_group_name = var.resource_group_name | ||
principal_id = var.principal_id | ||
subscription_id = var.subscription_id | ||
resource_group_names = var.resource_group_names | ||
prefix = var.prefix | ||
plan_id = var.plan_id | ||
name = var.name | ||
} |
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 |
---|---|---|
@@ -1,22 +1,32 @@ | ||
import sys | ||
from typing import Dict, List | ||
|
||
from az.cli import az | ||
from terraform_external_data import terraform_external_data | ||
|
||
import sys | ||
|
||
|
||
@terraform_external_data | ||
def get_nsg_from_rg(query): | ||
def get_nsg_from_rg(query: Dict[str, str]) -> Dict[str, str]: | ||
""" | ||
Functions that gest all Network Security Groups from Resource Group | ||
Gather all Network Security Groups for each requested Resource Group | ||
""" | ||
|
||
exit_code, result_dict, logs = az( | ||
"network nsg list --resource-group " + str(sys.argv[1]) + " --query '[].id' -o json") | ||
if exit_code == 0: | ||
return {query['network_security_groups']: str(result_dict).strip("[]").replace("'", "").replace(" ", "")} | ||
else: | ||
print(logs) | ||
if query["resource_group_names"] == "": | ||
return {} | ||
|
||
resource_group_names: List[str] = query["resource_group_names"].split(",") | ||
result: Dict[str, str] = {} | ||
|
||
for rg in resource_group_names: | ||
exit_code, result_dict, logs = az(f"network nsg list --resource-group {rg} --query '[].id' -o json") | ||
if exit_code == 0: | ||
network_security_groups = str(result_dict).strip("[]").replace("'", "").replace(" ", "") | ||
result[rg] = network_security_groups | ||
else: | ||
print(logs, file=sys.stderr) | ||
exit(1) | ||
return result # result is consumed by function decorator | ||
|
||
|
||
if __name__ == '__main__': | ||
if __name__ == "__main__": | ||
get_nsg_from_rg() |
Oops, something went wrong.