Skip to content

Commit

Permalink
SUMO-245309 Add azure_tag_filters in terraform resource
Browse files Browse the repository at this point in the history
  • Loading branch information
yuting-liu committed Jan 9, 2025
1 parent 5d6282b commit 9ccf1a2
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 12 deletions.
2 changes: 1 addition & 1 deletion sumologic/resource_sumologic_azure_metrics_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ resource "sumologic_azure_event_metrics_source" "azure-metrics" {
type = "AzureMetricsPath"
environment = "Azure"
limit_to_namespaces = ["Microsoft.ClassicStorage/storageAccounts"]
tag_filters {
azure_tag_filters {
type = "AzureTagFilters"
namespace = "Microsoft.ClassicStorage/storageAccounts"
tags {
Expand Down
60 changes: 51 additions & 9 deletions sumologic/resource_sumologic_generic_polling_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,41 @@ func resourceSumologicGenericPollingSource() *schema.Resource {
},
},
},
"azure_tag_filters": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Optional: 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,
},
},
},
},
},
},
},
},
"sns_topic_or_subscription_arn": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -389,6 +424,7 @@ func getPollingThirdPartyPathAttributes(pollingResource []PollingResource) []map
"use_versioned_api": t.Path.UseVersionedApi,
"custom_services": flattenCustomServices(t.Path.CustomServices),
"tag_filters": flattenPollingTagFilters(t.Path.TagFilters),
"azure_tag_filters": flattenPollingAzureTagFilters(t.Path.TagFilters),
"sns_topic_or_subscription_arn": flattenPollingSnsTopicOrSubscriptionArn(t.Path.SnsTopicOrSubscriptionArn),
"namespace": t.Path.Namespace,
"event_hub_name": t.Path.EventHubName,
Expand Down Expand Up @@ -464,26 +500,32 @@ func getCustomServices(path map[string]interface{}) []string {
func flattenPollingTagFilters(v []interface{}) []map[string]interface{} {
var filters []map[string]interface{}
for _, d := range v {
filter := make(map[string]interface{})
switch t := d.(type) {
case TagFilter:
filter = map[string]interface{}{
filter := map[string]interface{}{
"type": t.Type,
"namespace": t.Namespace,
"Tags": t.Tags,
"tags": t.Tags,
}
filters = append(filters, filter)
}
}
return filters
}

func flattenPollingAzureTagFilters(v []interface{}) []map[string]interface{} {
var filters []map[string]interface{}
for _, d := range v {
switch t := d.(type) {
case AzureTagFilter:
filter = map[string]interface{}{
filter := map[string]interface{}{
"type": t.Type,
"namespace": t.Namespace,
"Tags": flattenAzureTagKeyValuePair(t.Tags),
"tags": flattenAzureTagKeyValuePair(t.Tags),
}
default:
continue
filters = append(filters, filter)
}
filters = append(filters, filter)
}

return filters
}

Expand Down
38 changes: 36 additions & 2 deletions sumologic/resource_sumologic_polling_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,43 @@ func resourceSumologicPollingSource() *schema.Resource {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeMap, // Accept both maps (for objects) and strings
Type: schema.TypeString,
},
},
},
},
},
"azure_tag_filters": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Optional: 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,
},
},
},
},
ValidateFunc: validateTags,
},
},
},
Expand Down

0 comments on commit 9ccf1a2

Please sign in to comment.