Skip to content

Commit

Permalink
SUMO-245309 Add the doc for the new resource sumologic_azure_metrics_…
Browse files Browse the repository at this point in the history
…source
  • Loading branch information
yuting-liu committed Jan 13, 2025
1 parent df9b4b0 commit 9d5d99d
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 90 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ jobs:
SUMOLOGIC_TEST_ROLE_ARN: ${{ secrets.SUMOLOGIC_TEST_ROLE_ARN }}
SUMOLOGIC_TEST_SAS_KEY: ${{ secrets.SUMOLOGIC_TEST_SAS_KEY }}
SUMOLOGIC_TEST_SAS_KEY_NAME: ${{ secrets.SUMOLOGIC_TEST_SAS_KEY_NAME }}
SUMOLOGIC_TEST_AZURE_TENANT_ID: ${{ secrets.SUMOLOGIC_TEST_AZURE_TENANT_ID }}
SUMOLOGIC_TEST_AZURE_CLIENT_ID: ${{ secrets.SUMOLOGIC_TEST_AZURE_CLIENT_ID }}
SUMOLOGIC_TEST_AZURE_CLIENT_SECRET: ${{ secrets.SUMOLOGIC_TEST_AZURE_CLIENT_SECRET }}

# disable go test timeout. We rely on GitHub action timeout.
run: |
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## X.Y.Z (Unreleased)
* Add new change notes here
FEATURES:
* **New Resource:** sumologic_azure_metrics_source (GH-710)

## 3.0.0 (December 09, 2024)
**REMOVALS:**
Expand Down
89 changes: 0 additions & 89 deletions sumologic/resource_sumologic_polling_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,85 +125,13 @@ func resourceSumologicPollingSource() *schema.Resource {
},
},
},
"azure_tag_filters": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Required: true,
},
"namespace": {
Type: schema.TypeString,
Optional: true,
},
"tags": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"values": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
},
},
},
},
},
}

return pollingSource
}

func validateTags(val interface{}, key string) ([]string, []error) {
var errors []error

if tags, ok := val.([]interface{}); ok {
for i, tag := range tags {
switch t := tag.(type) {
case map[string]interface{}:
// Validate object structure
// Validate "name" to be a string
if _, ok := t["name"]; !ok {
errors = append(errors, fmt.Errorf("%s[%d]: missing required field 'name'", key, i))
} else if _, ok := t["name"].(string); !ok {
errors = append(errors, fmt.Errorf("%s[%d]: 'name' must be a string", key, i))
}

// Validate "values" to be a list of strings
if _, ok := t["values"]; !ok {
errors = append(errors, fmt.Errorf("%s[%d]: missing required field 'values'", key, i))
} else if values, ok := t["values"].([]interface{}); !ok {
errors = append(errors, fmt.Errorf("%s[%d]: 'values' must be a list of strings", key, i))
} else {
for j, value := range values {
if _, ok := value.(string); !ok {
errors = append(errors, fmt.Errorf("%s[%d].values[%d]: must be a string", key, i, j))
}
}
}
case string:
continue
default:
errors = append(errors, fmt.Errorf("%s[%d]: must be either a string or an object with 'name' and 'values'", key, i))
}
}
}
return nil, errors
}

func resourceSumologicPollingSourceCreate(d *schema.ResourceData, meta interface{}) error {

c := meta.(*Client)
Expand Down Expand Up @@ -317,7 +245,6 @@ func getThirdPartyPathAttributes(pollingResource []PollingResource) []map[string
func flattenTagFilters(v []interface{}) []map[string]interface{} {
var filters []map[string]interface{}
for _, d := range v {
log.Printf("[DEBUG] Entering myTerraformFunction" + d.(string))
switch t := d.(type) {
case TagFilter:
filter := map[string]interface{}{
Expand All @@ -326,22 +253,6 @@ func flattenTagFilters(v []interface{}) []map[string]interface{} {
"tags": t.Tags,
}
filters = append(filters, filter)
case AzureTagFilter:
var tags []map[string]interface{}
for _, rawTag := range t.Tags {
tag := map[string]interface{}{
"name": rawTag.Name,
"values": rawTag.Values,
}
tags = append(tags, tag)
}

filter := map[string]interface{}{
"type": t.Type,
"namespace": t.Namespace,
"tags": tags,
}
filters = append(filters, filter)
}
}
return filters
Expand Down
67 changes: 67 additions & 0 deletions website/docs/r/azure_metrics_source.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
layout: "sumologic"
page_title: "SumoLogic: sumologic_azure_metrics_source"
description: |-
Provides a Sumologic Azure Metrics Source.
---

# sumologic_azure_metrics_source
Provides a [Sumologic Azure Metrics Source](https://help.sumologic.com/docs/send-data/hosted-collectors/microsoft-source/azure-metrics-source/)

__IMPORTANT:__ The Azure Event Hub credentials are stored in plain-text in the state. This is a potential security issue.

## Example Usage
```hcl
resource "sumologic_azure_metrics_source" "terraform_azure_metrics_source" {
name = "Azure Metrics Source"
description = "My description"
category = "azure/metrics"
content_type = "AzureMetrics"
collector_id = "${sumologic_collector.collector.id}"
authentication {
type = "AzureClientSecretAuthentication"
tenant_id = "azure_tenant_id"
client_id = "azure_client_id"
client_secret = "azure_client_secret"
}
path {
type = "AzureMetricsPath"
environment = "Azure"
limit_to_namespaces = ["Microsoft.ClassicStorage/storageAccounts"]
azure_tag_filters {
type = "AzureTagFilters"
namespace = "Microsoft.ClassicStorage/storageAccounts"
tags {
name = "test-name-1"
values = ["value1", "value2"]
}
}
}
}
resource "sumologic_collector" "collector" {
name = "my-collector"
description = "Just testing this"
}
```

## Argument reference
In addition to the [Common Source Properties](https://registry.terraform.io/providers/SumoLogic/sumologic/latest/docs#common-source-properties), the following arguments are supported:
- `content_type` - (Required) Must be `AzureMetrics`.
- `authentication` - (Required) Authentication details for connecting to ingest metrics from Azure.
+ `type` - (Required) Must be `AzureClientSecretAuthentication`.
+ `tenant_id` - (Required) Your tenant id collected from [Azure platform](https://help.sumologic.com/docs/send-data/hosted-collectors/microsoft-source/azure-metrics-source/#vendor-configuration).
+ `client_id` - (Required) Your client id collected from [Azure platform](https://help.sumologic.com/docs/send-data/hosted-collectors/microsoft-source/azure-metrics-source/#vendor-configuration).
+ `client_secret` - (Required) Your client secret collected from [Azure platform](https://help.sumologic.com/docs/send-data/hosted-collectors/microsoft-source/azure-metrics-source/#vendor-configuration).
- `path` - (Required) The location to scan for new data.
+ `type` - (Required) Must be `AzureMetricsPath`.
+ `environment` - (Required) The environment to collect Azure metrics.
+ `limit_to_namespaces` - (Opitonal) The list of namespaces to collect metrics. By default all namespaces are selected.
+ `azure_tag_filters` - (Optional) Tag filters allow you to filter the Azure metrics by the tags you have assigned to your Azure resources. You can define tag filters for each supported namespace. If you do not define any tag filters, all metrics will be collected for namespaces you configured for the source above.
+ `type` - (Required) This value has to be set to `AzureTagFilters`
+ `namespace` - Namespace for which you want to define the tag filters.
+ `tags` - List of key and value list of tag filters.
+ `name`: The name of tag.
+ `values`: The list of accepted values for the tag name.

0 comments on commit 9d5d99d

Please sign in to comment.