Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SUMO-245309 Add the terraform support for Azure metric sources #710

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

yuting-liu
Copy link
Contributor

@yuting-liu yuting-liu commented Jan 6, 2025

In this PR, we added the terraform support for Azure metrics sources.

Changes

  1. Added new authentication type used by Azure metrics sources. Eg:
authentication {
  type = "AzureClientSecretAuthentication"
  tenant_id = "<azure_tenant_id>"
  client_id = "<azure_client_id>"
  client_secret = "<azure_client_id>"
}
  1. Added new path type used by Azure metric sources.
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"]
		}
	}
}

One thing to mention here for TagFilters field in Azure metrics sources, we added a new azure_tag_filters instead of using the same tag_filters as CloudWatch sources and kinesis metrics sources. The major reason is that for tags, the schemas are different and it requires to have a detailed schema definition in terraform world, which is why we added this new field. And for azure_tag_filters, we required type = "AzureTagFilters" to be required.

Test

  • Added the unit test for azure metrics source
  • Run the test locally
--- PASS: TestAccSumologicAzureMetricsSource_create (4.36s)
PASS
ok  	github.com/SumoLogic/terraform-provider-sumologic/sumologic	4.891s
--- PASS: TestAccSumologicAzureMetricsSource_update (5.58s)
PASS
ok  	github.com/SumoLogic/terraform-provider-sumologic/sumologic	6.100s
  • However Tests / Matrix Test (1.0.3) (pull_request) are not passing with the following error:
  
  Error: ***
    "status" : 400,
    "id" : "57TBO-MK628-NNH3R",
    "code" : "collectors.validation.fields.invalid",
    "message" : "Permission denied for Azure API: 'reason=Self-suppression not permitted'."
  ***

The reason is that we need to ask the terraform team to help us to configure the following secrets for the test to run:

        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 }}

I'll work with the team on fixing it: slack: #terraform-team

@yuting-liu yuting-liu force-pushed the yuting-SUMO-245309-terraform-support branch 4 times, most recently from f59c28c to 68ade3d Compare January 7, 2025 18:41
@yuting-liu yuting-liu force-pushed the yuting-SUMO-245309-terraform-support branch from 68ade3d to 5397700 Compare January 8, 2025 00:31
@yuting-liu yuting-liu force-pushed the yuting-SUMO-245309-terraform-support branch 2 times, most recently from de76dfc to 9ccf1a2 Compare January 9, 2025 18:34
@yuting-liu yuting-liu force-pushed the yuting-SUMO-245309-terraform-support branch 6 times, most recently from 2a5c0b5 to a10c426 Compare January 13, 2025 10:00
@yuting-liu yuting-liu force-pushed the yuting-SUMO-245309-terraform-support branch from a10c426 to df9b4b0 Compare January 13, 2025 18:51
@yuting-liu yuting-liu force-pushed the yuting-SUMO-245309-terraform-support branch from 9606f54 to c0deeeb Compare January 14, 2025 00:21
@yuting-liu yuting-liu marked this pull request as ready for review January 14, 2025 01:17
@yuting-liu yuting-liu requested review from maimaisie, vsinghal13 and a team as code owners January 14, 2025 01:17
@yuting-liu yuting-liu requested a review from samjsong January 14, 2025 01:18
@yuting-liu yuting-liu added the collection Item is related to data collection aspect of Sumo Logic. label Jan 14, 2025
environment = "Azure"
limit_to_namespaces = ["Microsoft.ClassicStorage/storageAccounts"]
azure_tag_filters {
type = "AzureTagFilters"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we require this type inside azure_tag_filters? since you created this azure_tag_filters field specifically for Azure source, it means azure_tag_filters field should only be of type AzureTagFilters, there wouldn't be other types of azure_tag_filters. for this one-to-one mapping, we still require user to specify this type?

Copy link
Contributor Author

@yuting-liu yuting-liu Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we require user to specify type = "AzureTagFilters" explicitly is due to the reason that it will make it easier for the conversion from API json back to terraform resource.

When type is defined in api, the responses body of the CREATE/UPDATE API will also include the type of tag filters. Otherwise, type will also won't display in responses. Thus, by checking the type from the response body, we can easily know that we should convert TagFilters filed to azure_tag_filters or tag_filters. Thus, it's not required for user clarification, it's for backend conversion convenience.

name = "test-name-2"
values = ["value2"]
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the array representation here looks very different that the API layer, in the API layer if I want to specify tags for two different namespaces where each namespace there are two tag names, it would look like this

{
    "tagFilters":[
        {
            "type":"AzureTagFilters",
            "namespace":"Microsoft.Web/namespace1",
            "tags":[
                {
                    "name":"name1",
                    "values":["value1", "value2"]
                },
                {
                    "name":"name2",
                    "values":["value1", "value2"]
                }
            ]
        },
        {
            "type":"AzureTagFilters",
            "namespace":"Microsoft.Web/namespace2",
            "tags":[
                {
                    "name":"name1",
                    "values":["value1", "value2"]
                },
                {
                    "name":"name2",
                    "values":["value1", "value2"]
                }
            ]
        }
    ]
}

but it seems based on your example here, the above API config translated to TF config would look like this:

	azure_tag_filters {
		type = "AzureTagFilters"
		namespace = "Microsoft.Web/namespace1"
		tags {
			name = "name1"
			values = ["value1", "value2"]
		}
		tags {
			name = "name2"
			values = ["value1", "value2"]
		}
	}
	azure_tag_filters {
		type = "AzureTagFilters"
		namespace = "Microsoft.Web/namespace1"
		tags {
			name = "test-name-1"
			values = ["value1", "value2"]
		}
		tags {
			name = "test-name-1"
			values = ["value1", "value2"]
		}
	}

azure_tag_filters keyword is repeated for each array element and same goes for tags, which is not the same in API layer. Is that expected and ideal for what we should use here? I notice that values = ["value1", "value2"] is still following the normal array representation, so you have two different array representation in the same section and I'm not sure if that's a good thing.

also if we keep this, then the naming needs to change, basically these two fields should both change from plural to singular because each represents a single array element. In the normal array representation like values = ["value1", "value2"] you have plural values because all the array elements are under this name

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the cloudwatch tagFilters field is what I expected the azure_tag_filters to look like https://registry.terraform.io/providers/SumoLogic/sumologic/latest/docs/resources/polling_source#example-usage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed the way kinesis metric source defined the tag_filters: https://registry.terraform.io/providers/SumoLogic/sumologic/latest/docs/resources/kinesis_metrics_source:

  path {
    type = "KinesisMetricPath"
    tag_filters {
        type = "TagFilters"
        namespace = "All"
        tags = ["k3=v3"]
    }
    tag_filters {
        type = "TagFilters"
        namespace = "AWS/Route53"
        tags = ["k1=v1"]
    }
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I'm currently suspecting if these two forms are equivalent in terraform world. I can do some experiments around this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
collection Item is related to data collection aspect of Sumo Logic.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants