diff --git a/coralogix/clientset/callPropertiesCreator.go b/coralogix/clientset/callPropertiesCreator.go index 6f60bd02..24a1abb7 100644 --- a/coralogix/clientset/callPropertiesCreator.go +++ b/coralogix/clientset/callPropertiesCreator.go @@ -16,16 +16,9 @@ package clientset import ( "context" - "crypto/tls" - "fmt" - "runtime" - "time" "github.com/google/uuid" - grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry" "google.golang.org/grpc" - "google.golang.org/grpc/credentials" - "google.golang.org/grpc/metadata" ) type CallPropertiesCreator struct { @@ -41,43 +34,6 @@ type CallProperties struct { CallOptions []grpc.CallOption } -func (c CallPropertiesCreator) GetCallProperties(ctx context.Context) (*CallProperties, error) { - ctx = createAuthContext(ctx, c.apiKey, c.correlationID) - - conn, err := createSecureConnection(c.targetUrl) - if err != nil { - return nil, err - } - - callOptions := createCallOptions() - - return &CallProperties{Ctx: ctx, Connection: conn, CallOptions: callOptions}, nil -} - -func createCallOptions() []grpc.CallOption { - var callOptions []grpc.CallOption - callOptions = append(callOptions, grpc_retry.WithMax(5)) - callOptions = append(callOptions, grpc_retry.WithBackoff(grpc_retry.BackoffLinear(time.Second))) - return callOptions -} - -func createSecureConnection(targetUrl string) (*grpc.ClientConn, error) { - return grpc.Dial(targetUrl, - grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{}))) -} - -func createAuthContext(ctx context.Context, apiKey string, correlationID string) context.Context { - md := metadata.New(map[string]string{ - "Authorization": fmt.Sprintf("Bearer %s", apiKey), - "x-cx-sdk-language": "go", - "x-cx-go-version": runtime.Version(), - "x-cx-sdk-version": "terraform-1.18.16", - "x-cx-correlation-id": correlationID, - }) - ctx = metadata.NewOutgoingContext(ctx, md) - return ctx -} - func NewCallPropertiesCreator(targetUrl, apiKey string) *CallPropertiesCreator { return &CallPropertiesCreator{ targetUrl: targetUrl, diff --git a/coralogix/resource_coralogix_alert.go b/coralogix/resource_coralogix_alert.go index c19a2962..53d14051 100644 --- a/coralogix/resource_coralogix_alert.go +++ b/coralogix/resource_coralogix_alert.go @@ -1710,6 +1710,7 @@ func extractAlertProperties(ctx context.Context, plan *AlertResourceModel) (*cxs if diags.HasError() { return nil, diags } + labels, diags := typeMapToStringMap(ctx, plan.Labels) if diags.HasError() { @@ -1724,6 +1725,7 @@ func extractAlertProperties(ctx context.Context, plan *AlertResourceModel) (*cxs IncidentsSettings: incidentsSettings, NotificationGroup: notificationGroup, EntityLabels: labels, + // Schedule is set in the next step } alertProperties, diags = expandAlertsSchedule(ctx, alertProperties, plan.Schedule) diff --git a/coralogix/resource_coralogix_alerts_scheduler_test.go b/coralogix/resource_coralogix_alerts_scheduler_test.go index cb6916e7..9b43d96e 100644 --- a/coralogix/resource_coralogix_alerts_scheduler_test.go +++ b/coralogix/resource_coralogix_alerts_scheduler_test.go @@ -130,3 +130,77 @@ func testAccCoralogixResourceAlertsScheduler() string { } ` } + +func testAccCoralogixResourceAlertsSchedulerRemoveSchedule() string { + return `resource "coralogix_alerts_scheduler" "test_rm_schedule" { +name = "example rm schedule" +description = "example rm schedule" +filter = { + what_expression = "source logs | filter $d.cpodId:string == '122'" + meta_labels = [{ + key = "key" + value = "value" + }] +} +schedule = { + operation = "active" + recurring = { + dynamic = { + repeat_every = 2 + frequency = { + weekly = { + days = ["Sunday"] + } + } + time_frame = { + start_time = "2021-01-04T00:00:00.000" + duration = { + for_over = 2 + frequency = "hours" + } + time_zone = "UTC+2" + } + termination_date = "2025-01-01T00:00:00.000" + } + } +} +} +` +} + +func testAccCoralogixResourceAlertsSchedulerRemoveScheduleUpdated() string { + return `resource "coralogix_alerts_scheduler" "test_rm_schedule" { +name = "example rm schedule" +description = "example rm schedule" +filter = { + what_expression = "source logs | filter $d.cpodId:string == '122'" + meta_labels = [{ + key = "key" + value = "value" + }] +} +schedule = { + operation = "active" + recurring = { + dynamic = { + repeat_every = 2 + frequency = { + weekly = { + days = ["Sunday"] + } + } + time_frame = { + start_time = "2021-01-04T00:00:00.000" + duration = { + for_over = 2 + frequency = "hours" + } + time_zone = "UTC+2" + } + termination_date = "2025-01-01T00:00:00.000" + } + } +} +} +` +}