From dea6bccd4e20ca3e95dddbd0ac0a26c5c692f26f Mon Sep 17 00:00:00 2001 From: Yiting Han Date: Thu, 22 Feb 2024 15:10:54 -0800 Subject: [PATCH 1/9] SUMO-227092: Terraform support for azure source --- CHANGELOG.md | 3 +- sumologic/provider.go | 1 + ...mologic_azure_event_hub_log_source_test.go | 193 ++++++++++++++++++ ...source_sumologic_generic_polling_source.go | 91 +++++++-- sumologic/sumologic_polling_source.go | 26 ++- .../azure_event_hub_log_source.html.markdown | 54 +++++ 6 files changed, 339 insertions(+), 29 deletions(-) create mode 100644 sumologic/resource_sumologic_azure_event_hub_log_source_test.go create mode 100644 website/docs/r/azure_event_hub_log_source.html.markdown diff --git a/CHANGELOG.md b/CHANGELOG.md index 431a1fc7..f994f91d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## 2.28.3 (Unreleased) - +FEATURES: +* **New Resource:** sumologic_azure_event_hub_log_source (GH-626) ## 2.28.2 (February 1, 2024) diff --git a/sumologic/provider.go b/sumologic/provider.go index f4632b8d..c7d65409 100644 --- a/sumologic/provider.go +++ b/sumologic/provider.go @@ -117,6 +117,7 @@ func Provider() terraform.ResourceProvider { "sumologic_log_search": resourceSumologicLogSearch(), "sumologic_metrics_search": resourceSumologicMetricsSearch(), "sumologic_rum_source": resourceSumologicRumSource(), + "sumologic_azure_event_hub_log_source": resourceSumologicGenericPollingSource(), }, DataSourcesMap: map[string]*schema.Resource{ "sumologic_cse_log_mapping_vendor_product": dataSourceCSELogMappingVendorAndProduct(), diff --git a/sumologic/resource_sumologic_azure_event_hub_log_source_test.go b/sumologic/resource_sumologic_azure_event_hub_log_source_test.go new file mode 100644 index 00000000..348029ca --- /dev/null +++ b/sumologic/resource_sumologic_azure_event_hub_log_source_test.go @@ -0,0 +1,193 @@ +package sumologic + +import ( + "fmt" + "os" + "strconv" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" +) + +func TestAccSumologicAzureEventHubLogSource_create(t *testing.T) { + var azureEventHubLogSource PollingSource + var collector Collector + cName, cDescription, cCategory := getRandomizedParams() + sName, sDescription, sCategory := getRandomizedParams() + azureEventHubLogResourceName := "sumologic_azure_event_hub_log_source.azure" + testNamespace := os.Getenv("SUMOLOGIC_TEST_NAMESPACE") + testEventHub := os.Getenv("SUMOLOGIC_TEST_EVENT_HUB") + testConsumerGroup := os.Getenv("SUMOLOGIC_TEST_CONSUMER_GROUP") + testRegion := os.Getenv("SUMOLOGIC_TEST_REGION") + testSASKeyName := os.Getenv("SUMOLOGIC_TEST_SAS_KEY_NAME") + testSASKey := os.Getenv("SUMOLOGIC_TEST_SAS_KEY") + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAzureEventHubLogSourceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccSumologicAzureEventHubLogSourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory, testSASKeyName, testSASKey, testNamespace, testEventHub, testConsumerGroup, testRegion), + Check: resource.ComposeTestCheckFunc( + testAccCheckAzureEventHubLogSourceExists(azureEventHubLogResourceName, &azureEventHubLogSource), + testAccCheckAzureEventHubLogSourceValues(&azureEventHubLogSource, sName, sDescription, sCategory), + testAccCheckCollectorExists("sumologic_collector.test", &collector), + testAccCheckCollectorValues(&collector, cName, cDescription, cCategory, "Etc/UTC", ""), + resource.TestCheckResourceAttrSet(azureEventHubLogResourceName, "id"), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "name", sName), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "description", sDescription), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "category", sCategory), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "content_type", "AzureEventHubLog"), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "path.0.type", "AzureEventHubPath"), + ), + }, + }, + }) +} +func TestAccSumologicAzureEventHubLogSource_update(t *testing.T) { + var azureEventHubLogSource PollingSource + cName, cDescription, cCategory := getRandomizedParams() + sName, sDescription, sCategory := getRandomizedParams() + sNameUpdated, sDescriptionUpdated, sCategoryUpdated := getRandomizedParams() + azureEventHubLogResourceName := "sumologic_azure_event_hub_log_source.azure" + testNamespace := os.Getenv("SUMOLOGIC_TEST_NAMESPACE") + testEventHub := os.Getenv("SUMOLOGIC_TEST_EVENT_HUB") + testConsumerGroup := os.Getenv("SUMOLOGIC_TEST_CONSUMER_GROUP") + testRegion := os.Getenv("SUMOLOGIC_TEST_REGION") + testSASKeyName := os.Getenv("SUMOLOGIC_TEST_SAS_KEY_NAME") + testSASKey := os.Getenv("SUMOLOGIC_TEST_SAS_KEY") + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAzureEventHubLogSourceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccSumologicAzureEventHubLogSourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory, testSASKeyName, testSASKey, testNamespace, testEventHub, testConsumerGroup, testRegion), + Check: resource.ComposeTestCheckFunc( + testAccCheckAzureEventHubLogSourceExists(azureEventHubLogResourceName, &azureEventHubLogSource), + testAccCheckAzureEventHubLogSourceValues(&azureEventHubLogSource, sName, sDescription, sCategory), + resource.TestCheckResourceAttrSet(azureEventHubLogResourceName, "id"), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "name", sName), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "description", sDescription), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "category", sCategory), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "content_type", "AzureEventHubLog"), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "path.0.type", "AzureEventHubPath"), + ), + }, + { + Config: testAccSumologicAzureEventHubLogSourceConfig(cName, cDescription, cCategory, sNameUpdated, sDescriptionUpdated, sCategoryUpdated, testSASKeyName, testSASKey, testNamespace, testEventHub, testConsumerGroup, testRegion), + Check: resource.ComposeTestCheckFunc( + testAccCheckAzureEventHubLogSourceExists(azureEventHubLogResourceName, &azureEventHubLogSource), + testAccCheckAzureEventHubLogSourceValues(&azureEventHubLogSource, sNameUpdated, sDescriptionUpdated, sCategoryUpdated), + resource.TestCheckResourceAttrSet(azureEventHubLogResourceName, "id"), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "name", sNameUpdated), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "description", sDescriptionUpdated), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "category", sCategoryUpdated), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "content_type", "AzureEventHubLog"), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "path.0.type", "AzureEventHubPath"), + ), + }, + }, + }) +} +func testAccCheckAzureEventHubLogSourceDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*Client) + for _, rs := range s.RootModule().Resources { + if rs.Type != "sumologic_azure_event_hub_log_source" { + continue + } + if rs.Primary.ID == "" { + return fmt.Errorf("Azure Event Hub Log Source destruction check: Azure Event Hub Log Source ID is not set") + } + id, err := strconv.Atoi(rs.Primary.ID) + if err != nil { + return fmt.Errorf("Encountered an error: " + err.Error()) + } + collectorID, err := strconv.Atoi(rs.Primary.Attributes["collector_id"]) + if err != nil { + return fmt.Errorf("Encountered an error: " + err.Error()) + } + s, err := client.GetPollingSource(collectorID, id) + if err != nil { + return fmt.Errorf("Encountered an error: " + err.Error()) + } + if s != nil { + return fmt.Errorf("Polling Source still exists") + } + } + return nil +} +func testAccCheckAzureEventHubLogSourceExists(n string, pollingSource *PollingSource) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("not found: %s", n) + } + if rs.Primary.ID == "" { + return fmt.Errorf("Polling Source ID is not set") + } + id, err := strconv.Atoi(rs.Primary.ID) + if err != nil { + return fmt.Errorf("Polling Source id should be int; got %s", rs.Primary.ID) + } + collectorID, err := strconv.Atoi(rs.Primary.Attributes["collector_id"]) + if err != nil { + return fmt.Errorf("Encountered an error: " + err.Error()) + } + c := testAccProvider.Meta().(*Client) + pollingSourceResp, err := c.GetPollingSource(collectorID, id) + if err != nil { + return err + } + *pollingSource = *pollingSourceResp + return nil + } +} +func testAccCheckAzureEventHubLogSourceValues(pollingSource *PollingSource, name, description, category string) resource.TestCheckFunc { + return func(s *terraform.State) error { + if pollingSource.Name != name { + return fmt.Errorf("bad name, expected \"%s\", got: %#v", name, pollingSource.Name) + } + if pollingSource.Description != description { + return fmt.Errorf("bad description, expected \"%s\", got: %#v", description, pollingSource.Description) + } + if pollingSource.Category != category { + return fmt.Errorf("bad category, expected \"%s\", got: %#v", category, pollingSource.Category) + } + return nil + } +} +func testAccSumologicAzureEventHubLogSourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory, testSASKeyName, testSASKey, testNamespace, testEventHub, testConsumerGroup, testRegion string) string { + return fmt.Sprintf(` +resource "sumologic_collector" "test" { + name = "%s" + description = "%s" + category = "%s" +} +resource "sumologic_azure_event_hub_log_source" "azure" { + name = "%s" + description = "%s" + category = "%s" + content_type = "AzureEventHubLog" + collector_id = "${sumologic_collector.test.id}" + + authentication { + type = "AzureEventHubAuthentication" + shared_access_policy_name = "%s" + shared_access_policy_key = "%s" + } + + path { + type = "AzureEventHubPath" + namespace = "%s" + event_hub_name = "%s" + consumer_group = "%s" + region = "%s" + } + + lifecycle { + ignore_changes = [authentication.0.shared_access_policy_key] + } +}`, cName, cDescription, cCategory, sName, sDescription, sCategory, testSASKeyName, testSASKey, testNamespace, testEventHub, testConsumerGroup, testRegion) +} diff --git a/sumologic/resource_sumologic_generic_polling_source.go b/sumologic/resource_sumologic_generic_polling_source.go index ad7b4463..5cbd323f 100644 --- a/sumologic/resource_sumologic_generic_polling_source.go +++ b/sumologic/resource_sumologic_generic_polling_source.go @@ -25,18 +25,19 @@ func resourceSumologicGenericPollingSource() *schema.Resource { Required: true, ForceNew: true, ValidateFunc: validation.StringInSlice([]string{"AwsS3Bucket", "AwsElbBucket", "AwsCloudFrontBucket", - "AwsCloudTrailBucket", "AwsS3AuditBucket", "AwsCloudWatch", "AwsInventory", "AwsXRay", "GcpMetrics", "AwsS3ArchiveBucket"}, false), + "AwsCloudTrailBucket", "AwsS3AuditBucket", "AwsCloudWatch", "AwsInventory", "AwsXRay", "GcpMetrics", "AwsS3ArchiveBucket", "AzureEventHubLog"}, false), } pollingSource.Schema["scan_interval"] = &schema.Schema{ Type: schema.TypeInt, - Required: true, + Optional: true, } pollingSource.Schema["paused"] = &schema.Schema{ Type: schema.TypeBool, - Required: true, + Optional: true, } pollingSource.Schema["url"] = &schema.Schema{ Type: schema.TypeString, + Optional: true, Computed: true, } pollingSource.Schema["authentication"] = &schema.Schema{ @@ -50,7 +51,7 @@ func resourceSumologicGenericPollingSource() *schema.Resource { "type": { Type: schema.TypeString, Required: true, - ValidateFunc: validation.StringInSlice([]string{"S3BucketAuthentication", "AWSRoleBasedAuthentication", "service_account"}, false), + ValidateFunc: validation.StringInSlice([]string{"S3BucketAuthentication", "AWSRoleBasedAuthentication", "service_account", "AzureEventHubAuthentication"}, false), }, "access_key": { Type: schema.TypeString, @@ -104,6 +105,14 @@ func resourceSumologicGenericPollingSource() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "shared_access_policy_name": { + Type: schema.TypeString, + Optional: true, + }, + "shared_access_policy_key": { + Type: schema.TypeString, + Optional: true, + }, }, }, } @@ -119,7 +128,7 @@ func resourceSumologicGenericPollingSource() *schema.Resource { Type: schema.TypeString, Required: true, ValidateFunc: validation.StringInSlice([]string{"S3BucketPathExpression", "CloudWatchPath", - "AwsInventoryPath", "AwsXRayPath", "GcpMetricsPath"}, false), + "AwsInventoryPath", "AwsXRayPath", "GcpMetricsPath", "AzureEventHubPath"}, false), }, "bucket_name": { Type: schema.TypeString, @@ -206,20 +215,39 @@ func resourceSumologicGenericPollingSource() *schema.Resource { }, "sns_topic_or_subscription_arn": { Type: schema.TypeList, + Optional: true, Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "is_success": { Type: schema.TypeBool, + Optional: true, Computed: true, }, "arn": { Type: schema.TypeString, + Optional: true, Computed: true, }, }, }, }, + "namespace": { + Type: schema.TypeString, + Optional: true, + }, + "event_hub_name": { + Type: schema.TypeString, + Optional: true, + }, + "consumer_group": { + Type: schema.TypeString, + Optional: true, + }, + "region": { + Type: schema.TypeString, + Optional: true, + }, }, }, } @@ -315,6 +343,10 @@ func resourceToGenericPollingSource(d *schema.ResourceData) (PollingSource, erro URL: d.Get("url").(string), } + if source.ContentType == "AzureEventHubLog" { + pollingSource.ScanInterval = 300000 + } + authSettings, errAuthSettings := getPollingAuthentication(d) if errAuthSettings != nil { return pollingSource, errAuthSettings @@ -342,17 +374,26 @@ func getPollingThirdPartyPathAttributes(pollingResource []PollingResource) []map for _, t := range pollingResource { mapping := map[string]interface{}{ - "type": t.Path.Type, - "bucket_name": t.Path.BucketName, - "path_expression": t.Path.PathExpression, - "limit_to_regions": t.Path.LimitToRegions, - "limit_to_namespaces": t.Path.LimitToNamespaces, - "limit_to_services": t.Path.LimitToServices, - "use_versioned_api": t.Path.UseVersionedApi, - "custom_services": flattenCustomServices(t.Path.CustomServices), - "tag_filters": flattenPollingTagFilters(t.Path.TagFilters), - "sns_topic_or_subscription_arn": flattenPollingSnsTopicOrSubscriptionArn(t.Path.SnsTopicOrSubscriptionArn), + "type": t.Path.Type, + "bucket_name": t.Path.BucketName, + "path_expression": t.Path.PathExpression, + "limit_to_regions": t.Path.LimitToRegions, + "limit_to_namespaces": t.Path.LimitToNamespaces, + "limit_to_services": t.Path.LimitToServices, + "use_versioned_api": t.Path.UseVersionedApi, + "custom_services": flattenCustomServices(t.Path.CustomServices), + "tag_filters": flattenPollingTagFilters(t.Path.TagFilters), + // "sns_topic_or_subscription_arn": flattenPollingSnsTopicOrSubscriptionArn(t.Path.SnsTopicOrSubscriptionArn), + "namespace": t.Path.Namespace, + "event_hub_name": t.Path.EventHubName, + "consumer_group": t.Path.ConsumerGroup, + "region": t.Path.Region, + } + + if t.Path.SnsTopicOrSubscriptionArn != nil { + mapping["sns_topic_or_subscription_arn"] = flattenPollingSnsTopicOrSubscriptionArn(t.Path.SnsTopicOrSubscriptionArn) } + s = append(s, mapping) } return s @@ -378,6 +419,8 @@ func getPollingThirdPartyAuthenticationAttributes(pollingResource []PollingResou "token_uri": t.Authentication.TokenUrl, "auth_provider_x509_cert_url": t.Authentication.AuthProviderX509CertUrl, "client_x509_cert_url": t.Authentication.ClientX509CertUrl, + "shared_access_policy_name": t.Authentication.SharedAccessPolicyName, + "shared_access_policy_key": t.Authentication.SharedAccessPolicyKey, } s = append(s, mapping) } @@ -454,7 +497,7 @@ func getPollingTagFilters(d *schema.ResourceData) []TagFilter { return filters } -func flattenPollingSnsTopicOrSubscriptionArn(v PollingSnsTopicOrSubscriptionArn) []map[string]interface{} { +func flattenPollingSnsTopicOrSubscriptionArn(v *PollingSnsTopicOrSubscriptionArn) []map[string]interface{} { var snsTopicOrSubscriptionArn []map[string]interface{} snsTopic := map[string]interface{}{ "is_success": v.IsSuccess, @@ -464,7 +507,7 @@ func flattenPollingSnsTopicOrSubscriptionArn(v PollingSnsTopicOrSubscriptionArn) return snsTopicOrSubscriptionArn } -func getPollingSnsTopicOrSubscriptionArn(d *schema.ResourceData) PollingSnsTopicOrSubscriptionArn { +func getPollingSnsTopicOrSubscriptionArn(d *schema.ResourceData) *PollingSnsTopicOrSubscriptionArn { paths := d.Get("path").([]interface{}) path := paths[0].(map[string]interface{}) snsConfig := path["sns_topic_or_subscription_arn"].([]interface{}) @@ -477,7 +520,7 @@ func getPollingSnsTopicOrSubscriptionArn(d *schema.ResourceData) PollingSnsTopic snsTopicOrSubscriptionArn.Arn = config["arn"].(string) } } - return snsTopicOrSubscriptionArn + return &snsTopicOrSubscriptionArn } func addGcpServiceAccountDetailsToAuth(authSettings *PollingAuthentication, auth map[string]interface{}) error { @@ -539,6 +582,10 @@ func getPollingAuthentication(d *schema.ResourceData) (PollingAuthentication, er if err != nil { return authSettings, err } + case "AzureEventHubAuthentication": + authSettings.Type = "AzureEventHubAuthentication" + authSettings.SharedAccessPolicyName = auth["shared_access_policy_name"].(string) + authSettings.SharedAccessPolicyKey = auth["shared_access_policy_key"].(string) default: errorMessage := fmt.Sprintf("[ERROR] Unknown authType: %v", authType) @@ -625,6 +672,14 @@ func getPollingPathSettings(d *schema.ResourceData) (PollingPath, error) { case "GcpMetricsPath": pathSettings.Type = pathType addGcpMetricsPathSettings(&pathSettings, path) + case "AzureEventHubPath": + pathSettings.Type = "AzureEventHubPath" + pathSettings.Namespace = path["namespace"].(string) + pathSettings.EventHubName = path["event_hub_name"].(string) + pathSettings.ConsumerGroup = path["consumer_group"].(string) + if path["region"] != nil { + pathSettings.Region = path["region"].(string) + } default: errorMessage := fmt.Sprintf("[ERROR] Unknown resourceType in path: %v", pathType) log.Print(errorMessage) diff --git a/sumologic/sumologic_polling_source.go b/sumologic/sumologic_polling_source.go index 4765574b..b2a5a83a 100644 --- a/sumologic/sumologic_polling_source.go +++ b/sumologic/sumologic_polling_source.go @@ -39,19 +39,25 @@ type PollingAuthentication struct { TokenUrl string `json:"token_uri"` AuthProviderX509CertUrl string `json:"auth_provider_x509_cert_url"` ClientX509CertUrl string `json:"client_x509_cert_url"` + SharedAccessPolicyName string `json:"sharedAccessPolicyName"` + SharedAccessPolicyKey string `json:"sharedAccessPolicyKey"` } type PollingPath struct { - Type string `json:"type"` - BucketName string `json:"bucketName,omitempty"` - PathExpression string `json:"pathExpression,omitempty"` - LimitToRegions []string `json:"limitToRegions,omitempty"` - LimitToNamespaces []string `json:"limitToNamespaces,omitempty"` - LimitToServices []string `json:"limitToServices,omitempty"` - CustomServices []string `json:"customServices,omitempty"` - TagFilters []TagFilter `json:"tagFilters,omitempty"` - SnsTopicOrSubscriptionArn PollingSnsTopicOrSubscriptionArn `json:"snsTopicOrSubscriptionArn,omitempty"` - UseVersionedApi *bool `json:"useVersionedApi,omitempty"` + Type string `json:"type"` + BucketName string `json:"bucketName,omitempty"` + PathExpression string `json:"pathExpression,omitempty"` + LimitToRegions []string `json:"limitToRegions,omitempty"` + LimitToNamespaces []string `json:"limitToNamespaces,omitempty"` + LimitToServices []string `json:"limitToServices,omitempty"` + CustomServices []string `json:"customServices,omitempty"` + TagFilters []TagFilter `json:"tagFilters,omitempty"` + SnsTopicOrSubscriptionArn *PollingSnsTopicOrSubscriptionArn `json:"snsTopicOrSubscriptionArn,omitempty"` + UseVersionedApi *bool `json:"useVersionedApi,omitempty"` + Namespace string `json:"namespace,omitempty"` + EventHubName string `json:"eventHubName,omitempty"` + ConsumerGroup string `json:"consumerGroup,omitempty"` + Region string `json:"region,omitempty"` } type TagFilter struct { diff --git a/website/docs/r/azure_event_hub_log_source.html.markdown b/website/docs/r/azure_event_hub_log_source.html.markdown new file mode 100644 index 00000000..9581419f --- /dev/null +++ b/website/docs/r/azure_event_hub_log_source.html.markdown @@ -0,0 +1,54 @@ +--- +layout: "sumologic" +page_title: "SumoLogic: sumologic_azure_event_hub_log_source" +description: |- + Provides a Sumologic Azure Event Hub Log Source in GA. +--- + +# sumologic_azure_event_hub_log_source +Provides a [Sumologic Azure Event Hub Log 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_event_hub_log_source" "terraform_azure_event_hub_log_source" { + name = "Azure Event Hub Log Source" + description = "My description" + category = "azure/eventhub" + content_type = "AzureEventHubLog" + collector_id = "${sumologic_collector.collector.id}" + authentication { + type = "AzureEventHubAuthentication" + shared_access_policy_name = "%s" + shared_access_policy_key = "%s" + } + path { + type = "AzureEventHubPath" + namespace = "%s" + event_hub_name = "%s" + consumer_group = "%s" + region = "%s" + } +} +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 `AzureEventHubLog`. + - `authentication` - (Required) Authentication details for connecting to Azure Event Hub. + + `type` - (Required) Must be `AzureEventHubAuthentication`. + + `shared_access_policy_name` - (Required) Your shared access policy name. + + `shared_access_policy_key` - (Required) Your shared access policy key. + - `path` - (Required) The location to scan for new data. + + `type` - (Required) Must be `AzureEventHubPath`. + + `namespace` - (Required) The namespace of the event hub. + + `event_hub_name` - (Required) The name of the event hub. + + `consumer_group` - (Required) The consumer group of the event hub. + + `region` - (Optional) The region of the event hub. The value can be either `Commercial` for Azure, or `US Gov` for Azure Government. Defaults to `Commercial`. From b02130e5a7a231bdba188ce8034f01cfcd690cf6 Mon Sep 17 00:00:00 2001 From: Yiting Han Date: Mon, 22 Apr 2024 14:02:12 -0700 Subject: [PATCH 2/9] SUMO-227092: Delete acc tests temporarily --- ...mologic_azure_event_hub_log_source_test.go | 193 ------------------ 1 file changed, 193 deletions(-) delete mode 100644 sumologic/resource_sumologic_azure_event_hub_log_source_test.go diff --git a/sumologic/resource_sumologic_azure_event_hub_log_source_test.go b/sumologic/resource_sumologic_azure_event_hub_log_source_test.go deleted file mode 100644 index 348029ca..00000000 --- a/sumologic/resource_sumologic_azure_event_hub_log_source_test.go +++ /dev/null @@ -1,193 +0,0 @@ -package sumologic - -import ( - "fmt" - "os" - "strconv" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" -) - -func TestAccSumologicAzureEventHubLogSource_create(t *testing.T) { - var azureEventHubLogSource PollingSource - var collector Collector - cName, cDescription, cCategory := getRandomizedParams() - sName, sDescription, sCategory := getRandomizedParams() - azureEventHubLogResourceName := "sumologic_azure_event_hub_log_source.azure" - testNamespace := os.Getenv("SUMOLOGIC_TEST_NAMESPACE") - testEventHub := os.Getenv("SUMOLOGIC_TEST_EVENT_HUB") - testConsumerGroup := os.Getenv("SUMOLOGIC_TEST_CONSUMER_GROUP") - testRegion := os.Getenv("SUMOLOGIC_TEST_REGION") - testSASKeyName := os.Getenv("SUMOLOGIC_TEST_SAS_KEY_NAME") - testSASKey := os.Getenv("SUMOLOGIC_TEST_SAS_KEY") - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAzureEventHubLogSourceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccSumologicAzureEventHubLogSourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory, testSASKeyName, testSASKey, testNamespace, testEventHub, testConsumerGroup, testRegion), - Check: resource.ComposeTestCheckFunc( - testAccCheckAzureEventHubLogSourceExists(azureEventHubLogResourceName, &azureEventHubLogSource), - testAccCheckAzureEventHubLogSourceValues(&azureEventHubLogSource, sName, sDescription, sCategory), - testAccCheckCollectorExists("sumologic_collector.test", &collector), - testAccCheckCollectorValues(&collector, cName, cDescription, cCategory, "Etc/UTC", ""), - resource.TestCheckResourceAttrSet(azureEventHubLogResourceName, "id"), - resource.TestCheckResourceAttr(azureEventHubLogResourceName, "name", sName), - resource.TestCheckResourceAttr(azureEventHubLogResourceName, "description", sDescription), - resource.TestCheckResourceAttr(azureEventHubLogResourceName, "category", sCategory), - resource.TestCheckResourceAttr(azureEventHubLogResourceName, "content_type", "AzureEventHubLog"), - resource.TestCheckResourceAttr(azureEventHubLogResourceName, "path.0.type", "AzureEventHubPath"), - ), - }, - }, - }) -} -func TestAccSumologicAzureEventHubLogSource_update(t *testing.T) { - var azureEventHubLogSource PollingSource - cName, cDescription, cCategory := getRandomizedParams() - sName, sDescription, sCategory := getRandomizedParams() - sNameUpdated, sDescriptionUpdated, sCategoryUpdated := getRandomizedParams() - azureEventHubLogResourceName := "sumologic_azure_event_hub_log_source.azure" - testNamespace := os.Getenv("SUMOLOGIC_TEST_NAMESPACE") - testEventHub := os.Getenv("SUMOLOGIC_TEST_EVENT_HUB") - testConsumerGroup := os.Getenv("SUMOLOGIC_TEST_CONSUMER_GROUP") - testRegion := os.Getenv("SUMOLOGIC_TEST_REGION") - testSASKeyName := os.Getenv("SUMOLOGIC_TEST_SAS_KEY_NAME") - testSASKey := os.Getenv("SUMOLOGIC_TEST_SAS_KEY") - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAzureEventHubLogSourceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccSumologicAzureEventHubLogSourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory, testSASKeyName, testSASKey, testNamespace, testEventHub, testConsumerGroup, testRegion), - Check: resource.ComposeTestCheckFunc( - testAccCheckAzureEventHubLogSourceExists(azureEventHubLogResourceName, &azureEventHubLogSource), - testAccCheckAzureEventHubLogSourceValues(&azureEventHubLogSource, sName, sDescription, sCategory), - resource.TestCheckResourceAttrSet(azureEventHubLogResourceName, "id"), - resource.TestCheckResourceAttr(azureEventHubLogResourceName, "name", sName), - resource.TestCheckResourceAttr(azureEventHubLogResourceName, "description", sDescription), - resource.TestCheckResourceAttr(azureEventHubLogResourceName, "category", sCategory), - resource.TestCheckResourceAttr(azureEventHubLogResourceName, "content_type", "AzureEventHubLog"), - resource.TestCheckResourceAttr(azureEventHubLogResourceName, "path.0.type", "AzureEventHubPath"), - ), - }, - { - Config: testAccSumologicAzureEventHubLogSourceConfig(cName, cDescription, cCategory, sNameUpdated, sDescriptionUpdated, sCategoryUpdated, testSASKeyName, testSASKey, testNamespace, testEventHub, testConsumerGroup, testRegion), - Check: resource.ComposeTestCheckFunc( - testAccCheckAzureEventHubLogSourceExists(azureEventHubLogResourceName, &azureEventHubLogSource), - testAccCheckAzureEventHubLogSourceValues(&azureEventHubLogSource, sNameUpdated, sDescriptionUpdated, sCategoryUpdated), - resource.TestCheckResourceAttrSet(azureEventHubLogResourceName, "id"), - resource.TestCheckResourceAttr(azureEventHubLogResourceName, "name", sNameUpdated), - resource.TestCheckResourceAttr(azureEventHubLogResourceName, "description", sDescriptionUpdated), - resource.TestCheckResourceAttr(azureEventHubLogResourceName, "category", sCategoryUpdated), - resource.TestCheckResourceAttr(azureEventHubLogResourceName, "content_type", "AzureEventHubLog"), - resource.TestCheckResourceAttr(azureEventHubLogResourceName, "path.0.type", "AzureEventHubPath"), - ), - }, - }, - }) -} -func testAccCheckAzureEventHubLogSourceDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*Client) - for _, rs := range s.RootModule().Resources { - if rs.Type != "sumologic_azure_event_hub_log_source" { - continue - } - if rs.Primary.ID == "" { - return fmt.Errorf("Azure Event Hub Log Source destruction check: Azure Event Hub Log Source ID is not set") - } - id, err := strconv.Atoi(rs.Primary.ID) - if err != nil { - return fmt.Errorf("Encountered an error: " + err.Error()) - } - collectorID, err := strconv.Atoi(rs.Primary.Attributes["collector_id"]) - if err != nil { - return fmt.Errorf("Encountered an error: " + err.Error()) - } - s, err := client.GetPollingSource(collectorID, id) - if err != nil { - return fmt.Errorf("Encountered an error: " + err.Error()) - } - if s != nil { - return fmt.Errorf("Polling Source still exists") - } - } - return nil -} -func testAccCheckAzureEventHubLogSourceExists(n string, pollingSource *PollingSource) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("not found: %s", n) - } - if rs.Primary.ID == "" { - return fmt.Errorf("Polling Source ID is not set") - } - id, err := strconv.Atoi(rs.Primary.ID) - if err != nil { - return fmt.Errorf("Polling Source id should be int; got %s", rs.Primary.ID) - } - collectorID, err := strconv.Atoi(rs.Primary.Attributes["collector_id"]) - if err != nil { - return fmt.Errorf("Encountered an error: " + err.Error()) - } - c := testAccProvider.Meta().(*Client) - pollingSourceResp, err := c.GetPollingSource(collectorID, id) - if err != nil { - return err - } - *pollingSource = *pollingSourceResp - return nil - } -} -func testAccCheckAzureEventHubLogSourceValues(pollingSource *PollingSource, name, description, category string) resource.TestCheckFunc { - return func(s *terraform.State) error { - if pollingSource.Name != name { - return fmt.Errorf("bad name, expected \"%s\", got: %#v", name, pollingSource.Name) - } - if pollingSource.Description != description { - return fmt.Errorf("bad description, expected \"%s\", got: %#v", description, pollingSource.Description) - } - if pollingSource.Category != category { - return fmt.Errorf("bad category, expected \"%s\", got: %#v", category, pollingSource.Category) - } - return nil - } -} -func testAccSumologicAzureEventHubLogSourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory, testSASKeyName, testSASKey, testNamespace, testEventHub, testConsumerGroup, testRegion string) string { - return fmt.Sprintf(` -resource "sumologic_collector" "test" { - name = "%s" - description = "%s" - category = "%s" -} -resource "sumologic_azure_event_hub_log_source" "azure" { - name = "%s" - description = "%s" - category = "%s" - content_type = "AzureEventHubLog" - collector_id = "${sumologic_collector.test.id}" - - authentication { - type = "AzureEventHubAuthentication" - shared_access_policy_name = "%s" - shared_access_policy_key = "%s" - } - - path { - type = "AzureEventHubPath" - namespace = "%s" - event_hub_name = "%s" - consumer_group = "%s" - region = "%s" - } - - lifecycle { - ignore_changes = [authentication.0.shared_access_policy_key] - } -}`, cName, cDescription, cCategory, sName, sDescription, sCategory, testSASKeyName, testSASKey, testNamespace, testEventHub, testConsumerGroup, testRegion) -} From 19145ce2df5d5d078341e0d4080d11e81d888ef7 Mon Sep 17 00:00:00 2001 From: David Gould Date: Mon, 22 Apr 2024 19:17:09 -0700 Subject: [PATCH 3/9] Revert "SUMO-227092: Delete acc tests temporarily" To retry with fixed environment variables. This reverts commit b02130e5a7a231bdba188ce8034f01cfcd690cf6. --- ...mologic_azure_event_hub_log_source_test.go | 193 ++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 sumologic/resource_sumologic_azure_event_hub_log_source_test.go diff --git a/sumologic/resource_sumologic_azure_event_hub_log_source_test.go b/sumologic/resource_sumologic_azure_event_hub_log_source_test.go new file mode 100644 index 00000000..348029ca --- /dev/null +++ b/sumologic/resource_sumologic_azure_event_hub_log_source_test.go @@ -0,0 +1,193 @@ +package sumologic + +import ( + "fmt" + "os" + "strconv" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" +) + +func TestAccSumologicAzureEventHubLogSource_create(t *testing.T) { + var azureEventHubLogSource PollingSource + var collector Collector + cName, cDescription, cCategory := getRandomizedParams() + sName, sDescription, sCategory := getRandomizedParams() + azureEventHubLogResourceName := "sumologic_azure_event_hub_log_source.azure" + testNamespace := os.Getenv("SUMOLOGIC_TEST_NAMESPACE") + testEventHub := os.Getenv("SUMOLOGIC_TEST_EVENT_HUB") + testConsumerGroup := os.Getenv("SUMOLOGIC_TEST_CONSUMER_GROUP") + testRegion := os.Getenv("SUMOLOGIC_TEST_REGION") + testSASKeyName := os.Getenv("SUMOLOGIC_TEST_SAS_KEY_NAME") + testSASKey := os.Getenv("SUMOLOGIC_TEST_SAS_KEY") + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAzureEventHubLogSourceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccSumologicAzureEventHubLogSourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory, testSASKeyName, testSASKey, testNamespace, testEventHub, testConsumerGroup, testRegion), + Check: resource.ComposeTestCheckFunc( + testAccCheckAzureEventHubLogSourceExists(azureEventHubLogResourceName, &azureEventHubLogSource), + testAccCheckAzureEventHubLogSourceValues(&azureEventHubLogSource, sName, sDescription, sCategory), + testAccCheckCollectorExists("sumologic_collector.test", &collector), + testAccCheckCollectorValues(&collector, cName, cDescription, cCategory, "Etc/UTC", ""), + resource.TestCheckResourceAttrSet(azureEventHubLogResourceName, "id"), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "name", sName), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "description", sDescription), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "category", sCategory), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "content_type", "AzureEventHubLog"), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "path.0.type", "AzureEventHubPath"), + ), + }, + }, + }) +} +func TestAccSumologicAzureEventHubLogSource_update(t *testing.T) { + var azureEventHubLogSource PollingSource + cName, cDescription, cCategory := getRandomizedParams() + sName, sDescription, sCategory := getRandomizedParams() + sNameUpdated, sDescriptionUpdated, sCategoryUpdated := getRandomizedParams() + azureEventHubLogResourceName := "sumologic_azure_event_hub_log_source.azure" + testNamespace := os.Getenv("SUMOLOGIC_TEST_NAMESPACE") + testEventHub := os.Getenv("SUMOLOGIC_TEST_EVENT_HUB") + testConsumerGroup := os.Getenv("SUMOLOGIC_TEST_CONSUMER_GROUP") + testRegion := os.Getenv("SUMOLOGIC_TEST_REGION") + testSASKeyName := os.Getenv("SUMOLOGIC_TEST_SAS_KEY_NAME") + testSASKey := os.Getenv("SUMOLOGIC_TEST_SAS_KEY") + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAzureEventHubLogSourceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccSumologicAzureEventHubLogSourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory, testSASKeyName, testSASKey, testNamespace, testEventHub, testConsumerGroup, testRegion), + Check: resource.ComposeTestCheckFunc( + testAccCheckAzureEventHubLogSourceExists(azureEventHubLogResourceName, &azureEventHubLogSource), + testAccCheckAzureEventHubLogSourceValues(&azureEventHubLogSource, sName, sDescription, sCategory), + resource.TestCheckResourceAttrSet(azureEventHubLogResourceName, "id"), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "name", sName), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "description", sDescription), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "category", sCategory), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "content_type", "AzureEventHubLog"), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "path.0.type", "AzureEventHubPath"), + ), + }, + { + Config: testAccSumologicAzureEventHubLogSourceConfig(cName, cDescription, cCategory, sNameUpdated, sDescriptionUpdated, sCategoryUpdated, testSASKeyName, testSASKey, testNamespace, testEventHub, testConsumerGroup, testRegion), + Check: resource.ComposeTestCheckFunc( + testAccCheckAzureEventHubLogSourceExists(azureEventHubLogResourceName, &azureEventHubLogSource), + testAccCheckAzureEventHubLogSourceValues(&azureEventHubLogSource, sNameUpdated, sDescriptionUpdated, sCategoryUpdated), + resource.TestCheckResourceAttrSet(azureEventHubLogResourceName, "id"), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "name", sNameUpdated), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "description", sDescriptionUpdated), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "category", sCategoryUpdated), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "content_type", "AzureEventHubLog"), + resource.TestCheckResourceAttr(azureEventHubLogResourceName, "path.0.type", "AzureEventHubPath"), + ), + }, + }, + }) +} +func testAccCheckAzureEventHubLogSourceDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*Client) + for _, rs := range s.RootModule().Resources { + if rs.Type != "sumologic_azure_event_hub_log_source" { + continue + } + if rs.Primary.ID == "" { + return fmt.Errorf("Azure Event Hub Log Source destruction check: Azure Event Hub Log Source ID is not set") + } + id, err := strconv.Atoi(rs.Primary.ID) + if err != nil { + return fmt.Errorf("Encountered an error: " + err.Error()) + } + collectorID, err := strconv.Atoi(rs.Primary.Attributes["collector_id"]) + if err != nil { + return fmt.Errorf("Encountered an error: " + err.Error()) + } + s, err := client.GetPollingSource(collectorID, id) + if err != nil { + return fmt.Errorf("Encountered an error: " + err.Error()) + } + if s != nil { + return fmt.Errorf("Polling Source still exists") + } + } + return nil +} +func testAccCheckAzureEventHubLogSourceExists(n string, pollingSource *PollingSource) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("not found: %s", n) + } + if rs.Primary.ID == "" { + return fmt.Errorf("Polling Source ID is not set") + } + id, err := strconv.Atoi(rs.Primary.ID) + if err != nil { + return fmt.Errorf("Polling Source id should be int; got %s", rs.Primary.ID) + } + collectorID, err := strconv.Atoi(rs.Primary.Attributes["collector_id"]) + if err != nil { + return fmt.Errorf("Encountered an error: " + err.Error()) + } + c := testAccProvider.Meta().(*Client) + pollingSourceResp, err := c.GetPollingSource(collectorID, id) + if err != nil { + return err + } + *pollingSource = *pollingSourceResp + return nil + } +} +func testAccCheckAzureEventHubLogSourceValues(pollingSource *PollingSource, name, description, category string) resource.TestCheckFunc { + return func(s *terraform.State) error { + if pollingSource.Name != name { + return fmt.Errorf("bad name, expected \"%s\", got: %#v", name, pollingSource.Name) + } + if pollingSource.Description != description { + return fmt.Errorf("bad description, expected \"%s\", got: %#v", description, pollingSource.Description) + } + if pollingSource.Category != category { + return fmt.Errorf("bad category, expected \"%s\", got: %#v", category, pollingSource.Category) + } + return nil + } +} +func testAccSumologicAzureEventHubLogSourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory, testSASKeyName, testSASKey, testNamespace, testEventHub, testConsumerGroup, testRegion string) string { + return fmt.Sprintf(` +resource "sumologic_collector" "test" { + name = "%s" + description = "%s" + category = "%s" +} +resource "sumologic_azure_event_hub_log_source" "azure" { + name = "%s" + description = "%s" + category = "%s" + content_type = "AzureEventHubLog" + collector_id = "${sumologic_collector.test.id}" + + authentication { + type = "AzureEventHubAuthentication" + shared_access_policy_name = "%s" + shared_access_policy_key = "%s" + } + + path { + type = "AzureEventHubPath" + namespace = "%s" + event_hub_name = "%s" + consumer_group = "%s" + region = "%s" + } + + lifecycle { + ignore_changes = [authentication.0.shared_access_policy_key] + } +}`, cName, cDescription, cCategory, sName, sDescription, sCategory, testSASKeyName, testSASKey, testNamespace, testEventHub, testConsumerGroup, testRegion) +} From 9753e811e9c11c87be69776d1ac4243f7c7fde74 Mon Sep 17 00:00:00 2001 From: David Gould Date: Tue, 23 Apr 2024 01:33:27 -0700 Subject: [PATCH 4/9] SUMO-227092 add new secrets to test workflow env --- .github/workflows/test.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bfd5e1bc..27cefdaa 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -90,8 +90,14 @@ jobs: SUMOLOGIC_ACCESSKEY: ${{ secrets.SUMOLOGIC_ACCESSKEY }} SUMOLOGIC_ENVIRONMENT: ${{ secrets.SUMOLOGIC_ENVIRONMENT }} SUMOLOGIC_TEST_BUCKET_NAME: ${{ secrets.SUMOLOGIC_TEST_BUCKET_NAME }} - SUMOLOGIC_TEST_ROLE_ARN: ${{ secrets.SUMOLOGIC_TEST_ROLE_ARN }} + SUMOLOGIC_TEST_CONSUMER_GROUP: ${{ secrets.SUMOLOGIC_TEST_CONSUMER_GROUP }} + SUMOLOGIC_TEST_EVENT_HUB: ${{ secrets.SUMOLOGIC_TEST_EVENT_HUB }} SUMOLOGIC_TEST_GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.SUMOLOGIC_TEST_GOOGLE_APPLICATION_CREDENTIALS }} + SUMOLOGIC_TEST_NAMESPACE: ${{ secrets.SUMOLOGIC_TEST_NAMESPACE }} + SUMOLOGIC_TEST_REGION: ${{ secrets.SUMOLOGIC_TEST_REGION }} + 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 }} # disable go test timeout. We rely on GitHub action timeout. run: | From bf38be5a555588d43cc2e177ac08f463556f2d8b Mon Sep 17 00:00:00 2001 From: Yiting Han Date: Thu, 25 Apr 2024 16:07:25 -0700 Subject: [PATCH 5/9] SUMO-227092: Fixed document --- .../r/azure_event_hub_log_source.html.markdown | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/website/docs/r/azure_event_hub_log_source.html.markdown b/website/docs/r/azure_event_hub_log_source.html.markdown index 9581419f..9ac404a0 100644 --- a/website/docs/r/azure_event_hub_log_source.html.markdown +++ b/website/docs/r/azure_event_hub_log_source.html.markdown @@ -2,11 +2,11 @@ layout: "sumologic" page_title: "SumoLogic: sumologic_azure_event_hub_log_source" description: |- - Provides a Sumologic Azure Event Hub Log Source in GA. + Provides a Sumologic Azure Event Hub Log Source. --- # sumologic_azure_event_hub_log_source -Provides a [Sumologic Azure Event Hub Log Source]. +Provides a [Sumologic Azure Event Hub Log Source](https://help.sumologic.com/docs/send-data/collect-from-other-data-sources/azure-monitoring/ms-azure-event-hubs-source/). __IMPORTANT:__ The Azure Event Hub credentials are stored in plain-text in the state. This is a potential security issue. @@ -20,14 +20,14 @@ resource "sumologic_azure_event_hub_log_source" "terraform_azure_event_hub_log_s collector_id = "${sumologic_collector.collector.id}" authentication { type = "AzureEventHubAuthentication" - shared_access_policy_name = "%s" - shared_access_policy_key = "%s" + shared_access_policy_name = "%s" + shared_access_policy_key = "%s" } path { type = "AzureEventHubPath" - namespace = "%s" - event_hub_name = "%s" - consumer_group = "%s" + namespace = "%s" + event_hub_name = "%s" + consumer_group = "%s" region = "%s" } } From b59c9e7ebbc9b574ae37a5aa35ce5e978dd0d372 Mon Sep 17 00:00:00 2001 From: Yiting Han Date: Tue, 30 Apr 2024 10:11:11 -0700 Subject: [PATCH 6/9] SUMO-227092: Removed changes on SnsTopicOrSubscriptionArn --- ...source_sumologic_generic_polling_source.go | 38 +++++++++---------- sumologic/sumologic_polling_source.go | 28 +++++++------- 2 files changed, 31 insertions(+), 35 deletions(-) diff --git a/sumologic/resource_sumologic_generic_polling_source.go b/sumologic/resource_sumologic_generic_polling_source.go index 5cbd323f..f8fa1f79 100644 --- a/sumologic/resource_sumologic_generic_polling_source.go +++ b/sumologic/resource_sumologic_generic_polling_source.go @@ -374,24 +374,20 @@ func getPollingThirdPartyPathAttributes(pollingResource []PollingResource) []map for _, t := range pollingResource { mapping := map[string]interface{}{ - "type": t.Path.Type, - "bucket_name": t.Path.BucketName, - "path_expression": t.Path.PathExpression, - "limit_to_regions": t.Path.LimitToRegions, - "limit_to_namespaces": t.Path.LimitToNamespaces, - "limit_to_services": t.Path.LimitToServices, - "use_versioned_api": t.Path.UseVersionedApi, - "custom_services": flattenCustomServices(t.Path.CustomServices), - "tag_filters": flattenPollingTagFilters(t.Path.TagFilters), - // "sns_topic_or_subscription_arn": flattenPollingSnsTopicOrSubscriptionArn(t.Path.SnsTopicOrSubscriptionArn), - "namespace": t.Path.Namespace, - "event_hub_name": t.Path.EventHubName, - "consumer_group": t.Path.ConsumerGroup, - "region": t.Path.Region, - } - - if t.Path.SnsTopicOrSubscriptionArn != nil { - mapping["sns_topic_or_subscription_arn"] = flattenPollingSnsTopicOrSubscriptionArn(t.Path.SnsTopicOrSubscriptionArn) + "type": t.Path.Type, + "bucket_name": t.Path.BucketName, + "path_expression": t.Path.PathExpression, + "limit_to_regions": t.Path.LimitToRegions, + "limit_to_namespaces": t.Path.LimitToNamespaces, + "limit_to_services": t.Path.LimitToServices, + "use_versioned_api": t.Path.UseVersionedApi, + "custom_services": flattenCustomServices(t.Path.CustomServices), + "tag_filters": flattenPollingTagFilters(t.Path.TagFilters), + "sns_topic_or_subscription_arn": flattenPollingSnsTopicOrSubscriptionArn(t.Path.SnsTopicOrSubscriptionArn), + "namespace": t.Path.Namespace, + "event_hub_name": t.Path.EventHubName, + "consumer_group": t.Path.ConsumerGroup, + "region": t.Path.Region, } s = append(s, mapping) @@ -497,7 +493,7 @@ func getPollingTagFilters(d *schema.ResourceData) []TagFilter { return filters } -func flattenPollingSnsTopicOrSubscriptionArn(v *PollingSnsTopicOrSubscriptionArn) []map[string]interface{} { +func flattenPollingSnsTopicOrSubscriptionArn(v PollingSnsTopicOrSubscriptionArn) []map[string]interface{} { var snsTopicOrSubscriptionArn []map[string]interface{} snsTopic := map[string]interface{}{ "is_success": v.IsSuccess, @@ -507,7 +503,7 @@ func flattenPollingSnsTopicOrSubscriptionArn(v *PollingSnsTopicOrSubscriptionArn return snsTopicOrSubscriptionArn } -func getPollingSnsTopicOrSubscriptionArn(d *schema.ResourceData) *PollingSnsTopicOrSubscriptionArn { +func getPollingSnsTopicOrSubscriptionArn(d *schema.ResourceData) PollingSnsTopicOrSubscriptionArn { paths := d.Get("path").([]interface{}) path := paths[0].(map[string]interface{}) snsConfig := path["sns_topic_or_subscription_arn"].([]interface{}) @@ -520,7 +516,7 @@ func getPollingSnsTopicOrSubscriptionArn(d *schema.ResourceData) *PollingSnsTopi snsTopicOrSubscriptionArn.Arn = config["arn"].(string) } } - return &snsTopicOrSubscriptionArn + return snsTopicOrSubscriptionArn } func addGcpServiceAccountDetailsToAuth(authSettings *PollingAuthentication, auth map[string]interface{}) error { diff --git a/sumologic/sumologic_polling_source.go b/sumologic/sumologic_polling_source.go index b2a5a83a..cf367d4e 100644 --- a/sumologic/sumologic_polling_source.go +++ b/sumologic/sumologic_polling_source.go @@ -44,20 +44,20 @@ type PollingAuthentication struct { } type PollingPath struct { - Type string `json:"type"` - BucketName string `json:"bucketName,omitempty"` - PathExpression string `json:"pathExpression,omitempty"` - LimitToRegions []string `json:"limitToRegions,omitempty"` - LimitToNamespaces []string `json:"limitToNamespaces,omitempty"` - LimitToServices []string `json:"limitToServices,omitempty"` - CustomServices []string `json:"customServices,omitempty"` - TagFilters []TagFilter `json:"tagFilters,omitempty"` - SnsTopicOrSubscriptionArn *PollingSnsTopicOrSubscriptionArn `json:"snsTopicOrSubscriptionArn,omitempty"` - UseVersionedApi *bool `json:"useVersionedApi,omitempty"` - Namespace string `json:"namespace,omitempty"` - EventHubName string `json:"eventHubName,omitempty"` - ConsumerGroup string `json:"consumerGroup,omitempty"` - Region string `json:"region,omitempty"` + Type string `json:"type"` + BucketName string `json:"bucketName,omitempty"` + PathExpression string `json:"pathExpression,omitempty"` + LimitToRegions []string `json:"limitToRegions,omitempty"` + LimitToNamespaces []string `json:"limitToNamespaces,omitempty"` + LimitToServices []string `json:"limitToServices,omitempty"` + CustomServices []string `json:"customServices,omitempty"` + TagFilters []TagFilter `json:"tagFilters,omitempty"` + SnsTopicOrSubscriptionArn PollingSnsTopicOrSubscriptionArn `json:"snsTopicOrSubscriptionArn,omitempty"` + UseVersionedApi *bool `json:"useVersionedApi,omitempty"` + Namespace string `json:"namespace,omitempty"` + EventHubName string `json:"eventHubName,omitempty"` + ConsumerGroup string `json:"consumerGroup,omitempty"` + Region string `json:"region,omitempty"` } type TagFilter struct { From d1cd0164ec1e93760d3ea3a29020aa483b32a6aa Mon Sep 17 00:00:00 2001 From: Yiting Han Date: Tue, 30 Apr 2024 10:16:06 -0700 Subject: [PATCH 7/9] SUMO-227092: Fix indentation --- .../azure_event_hub_log_source.html.markdown | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/website/docs/r/azure_event_hub_log_source.html.markdown b/website/docs/r/azure_event_hub_log_source.html.markdown index 9ac404a0..ca46b97c 100644 --- a/website/docs/r/azure_event_hub_log_source.html.markdown +++ b/website/docs/r/azure_event_hub_log_source.html.markdown @@ -12,29 +12,30 @@ __IMPORTANT:__ The Azure Event Hub credentials are stored in plain-text in the s ## Example Usage ```hcl -resource "sumologic_azure_event_hub_log_source" "terraform_azure_event_hub_log_source" { - name = "Azure Event Hub Log Source" - description = "My description" - category = "azure/eventhub" - content_type = "AzureEventHubLog" - collector_id = "${sumologic_collector.collector.id}" - authentication { - type = "AzureEventHubAuthentication" - shared_access_policy_name = "%s" - shared_access_policy_key = "%s" + resource "sumologic_azure_event_hub_log_source" "terraform_azure_event_hub_log_source" { + name = "Azure Event Hub Log Source" + description = "My description" + category = "azure/eventhub" + content_type = "AzureEventHubLog" + collector_id = "${sumologic_collector.collector.id}" + authentication { + type = "AzureEventHubAuthentication" + shared_access_policy_name = "%s" + shared_access_policy_key = "%s" + } + path { + type = "AzureEventHubPath" + namespace = "%s" + event_hub_name = "%s" + consumer_group = "%s" + region = "%s" + } } - path { - type = "AzureEventHubPath" - namespace = "%s" - event_hub_name = "%s" - consumer_group = "%s" - region = "%s" + + resource "sumologic_collector" "collector" { + name = "my-collector" + description = "Just testing this" } -} -resource "sumologic_collector" "collector" { - name = "my-collector" - description = "Just testing this" -} ``` ## Argument reference From 0bb88cc97c79d25ef7cee7a13be569b84f7b19bd Mon Sep 17 00:00:00 2001 From: Yiting Han Date: Tue, 7 May 2024 13:46:34 -0700 Subject: [PATCH 8/9] SUMO-227092: Fix scan interval --- .../resource_sumologic_generic_polling_source.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sumologic/resource_sumologic_generic_polling_source.go b/sumologic/resource_sumologic_generic_polling_source.go index f8fa1f79..c8ecce06 100644 --- a/sumologic/resource_sumologic_generic_polling_source.go +++ b/sumologic/resource_sumologic_generic_polling_source.go @@ -30,10 +30,16 @@ func resourceSumologicGenericPollingSource() *schema.Resource { pollingSource.Schema["scan_interval"] = &schema.Schema{ Type: schema.TypeInt, Optional: true, + Default: 300000, + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + contentType := d.Get("content_type").(string) + return contentType == "AzureEventHubLog" + }, } pollingSource.Schema["paused"] = &schema.Schema{ Type: schema.TypeBool, Optional: true, + Default: false, } pollingSource.Schema["url"] = &schema.Schema{ Type: schema.TypeString, @@ -215,18 +221,15 @@ func resourceSumologicGenericPollingSource() *schema.Resource { }, "sns_topic_or_subscription_arn": { Type: schema.TypeList, - Optional: true, Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "is_success": { Type: schema.TypeBool, - Optional: true, Computed: true, }, "arn": { Type: schema.TypeString, - Optional: true, Computed: true, }, }, @@ -344,7 +347,7 @@ func resourceToGenericPollingSource(d *schema.ResourceData) (PollingSource, erro } if source.ContentType == "AzureEventHubLog" { - pollingSource.ScanInterval = 300000 + pollingSource.ScanInterval = -1 } authSettings, errAuthSettings := getPollingAuthentication(d) From 35e50def06142b44033a9d927c4ade2d25649b2a Mon Sep 17 00:00:00 2001 From: Yiting Han Date: Tue, 7 May 2024 13:50:23 -0700 Subject: [PATCH 9/9] SUMO-227092: Nit --- sumologic/resource_sumologic_generic_polling_source.go | 1 - 1 file changed, 1 deletion(-) diff --git a/sumologic/resource_sumologic_generic_polling_source.go b/sumologic/resource_sumologic_generic_polling_source.go index c8ecce06..829fad4b 100644 --- a/sumologic/resource_sumologic_generic_polling_source.go +++ b/sumologic/resource_sumologic_generic_polling_source.go @@ -43,7 +43,6 @@ func resourceSumologicGenericPollingSource() *schema.Resource { } pollingSource.Schema["url"] = &schema.Schema{ Type: schema.TypeString, - Optional: true, Computed: true, } pollingSource.Schema["authentication"] = &schema.Schema{