Skip to content

Commit 391c57e

Browse files
committed
Merge branch 'master' into bugfix/SUMO-193330-monitor-folder-update
2 parents 3edcf7a + 1d0a7a7 commit 391c57e

8 files changed

+379
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ FEATURES:
33
* **New Resource:** sumologic_cse_entity_entity_group_configuration (GH-376)
44
* **New Resource:** sumologic_cse_inventory_entity_group_configuration (GH-376)
55

6+
* Add new optional `obj_permission` set to resource/sumologic_monitor for Fine Grain Permission (FGP) support (GH-397)
7+
68
BUG FIXES:
79
* Allow Monitor move between Monitor folders
810

9-
1011
## 2.16.2 (June 12, 2022)
1112

1213
BUG FIXES:

sumologic/resource_sumologic_generic_polling_source.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ func resourceSumologicGenericPollingSource() *schema.Resource {
125125
Type: schema.TypeString,
126126
Optional: true,
127127
},
128+
"use_versioned_api": {
129+
Type: schema.TypeBool,
130+
Optional: true,
131+
},
128132
"path_expression": {
129133
Type: schema.TypeString,
130134
Optional: true,
@@ -336,6 +340,7 @@ func getPollingThirdPartyPathAttributes(pollingResource []PollingResource) []map
336340
"limit_to_regions": t.Path.LimitToRegions,
337341
"limit_to_namespaces": t.Path.LimitToNamespaces,
338342
"limit_to_services": t.Path.LimitToServices,
343+
"use_versioned_api": t.Path.UseVersionedApi,
339344
"custom_services": flattenCustomServices(t.Path.CustomServices),
340345
"tag_filters": flattenPollingTagFilters(t.Path.TagFilters),
341346
"sns_topic_or_subscription_arn": flattenPollingSnsTopicOrSubscriptionArn(t.Path.SnsTopicOrSubscriptionArn),
@@ -572,6 +577,9 @@ func getPollingPathSettings(d *schema.ResourceData) (PollingPath, error) {
572577
pathSettings.Type = "S3BucketPathExpression"
573578
pathSettings.BucketName = path["bucket_name"].(string)
574579
pathSettings.PathExpression = path["path_expression"].(string)
580+
if path["use_versioned_api"] != nil {
581+
pathSettings.UseVersionedApi = path["use_versioned_api"].(bool)
582+
}
575583
pathSettings.SnsTopicOrSubscriptionArn = getPollingSnsTopicOrSubscriptionArn(d)
576584
case "CloudWatchPath", "AwsInventoryPath":
577585
pathSettings.Type = pathType

sumologic/resource_sumologic_monitors_library_monitor.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ func resourceSumologicMonitorsLibraryMonitor() *schema.Resource {
353353
Optional: true,
354354
ValidateFunc: validation.StringLenBetween(1, 512),
355355
},
356+
357+
"obj_permission": GetCmfFgpObjPermSetSchema(),
356358
},
357359
}
358360
}
@@ -569,6 +571,16 @@ func resourceSumologicMonitorsLibraryMonitorCreate(d *schema.ResourceData, meta
569571
return err
570572
}
571573

574+
permStmts, convErr := ResourceToCmfFgpPermStmts(d, monitorDefinitionID)
575+
if convErr != nil {
576+
return convErr
577+
}
578+
_, fgpErr := c.SetCmfFgp(fgpTargetType, CmfFgpRequest{
579+
PermissionStatements: permStmts,
580+
})
581+
if fgpErr != nil {
582+
return fgpErr
583+
}
572584
d.SetId(monitorDefinitionID)
573585
}
574586
return resourceSumologicMonitorsLibraryMonitorRead(d, meta)
@@ -588,6 +600,18 @@ func resourceSumologicMonitorsLibraryMonitorRead(d *schema.ResourceData, meta in
588600
return nil
589601
}
590602

603+
fgpResponse, fgpErr := c.GetCmfFgp(fgpTargetType, monitor.ID)
604+
if fgpErr != nil {
605+
suppressedErrorCode := HasErrorCode(fgpErr.Error(), []string{"not_implemented_yet", "api_not_enabled"})
606+
if suppressedErrorCode == "" {
607+
return fgpErr
608+
} else {
609+
log.Printf("[WARN] FGP Feature has not been enabled yet. Suppressing \"%s\" error under GetCmfFgp operation.", suppressedErrorCode)
610+
}
611+
} else {
612+
CmfFgpPermStmtsSetToResource(d, fgpResponse.PermissionStatements)
613+
}
614+
591615
d.Set("created_by", monitor.CreatedBy)
592616
d.Set("created_at", monitor.CreatedAt)
593617
d.Set("monitor_type", monitor.MonitorType)
@@ -716,6 +740,43 @@ func resourceSumologicMonitorsLibraryMonitorUpdate(d *schema.ResourceData, meta
716740
if err != nil {
717741
return err
718742
}
743+
744+
// converting Resource FGP to Struct
745+
permStmts, convErr := ResourceToCmfFgpPermStmts(d, monitor.ID)
746+
if convErr != nil {
747+
return convErr
748+
}
749+
750+
// reading FGP from Backend to reconcile
751+
fgpGetResponse, fgpGetErr := c.GetCmfFgp(fgpTargetType, monitor.ID)
752+
if fgpGetErr != nil {
753+
/*
754+
|errCode | len | logic |
755+
|--------------------------------------------------|
756+
|server_error | 0 | return err at Get |
757+
|server_error | 1 | warn; return err at Set |
758+
|not_enabled | 0 | warn |
759+
|not_enabled | 1 | warn; return err at Set |
760+
*/
761+
suppressedErrorCode := HasErrorCode(fgpGetErr.Error(), []string{"not_implemented_yet", "api_not_enabled"})
762+
if suppressedErrorCode == "" && len(permStmts) == 0 {
763+
return fgpGetErr
764+
} else {
765+
log.Printf("[WARN] FGP Feature has not been enabled yet. Suppressing \"%s\" error under GetCmfFgp operation.", suppressedErrorCode)
766+
}
767+
}
768+
769+
if len(permStmts) > 0 || fgpGetResponse != nil {
770+
_, fgpSetErr := c.SetCmfFgp(fgpTargetType, CmfFgpRequest{
771+
PermissionStatements: ReconcileFgpPermStmtsWithEmptyPerms(
772+
permStmts, fgpGetResponse.PermissionStatements,
773+
),
774+
})
775+
if fgpSetErr != nil {
776+
return fgpSetErr
777+
}
778+
}
779+
719780
updatedMonitor := resourceSumologicMonitorsLibraryMonitorRead(d, meta)
720781

721782
return updatedMonitor

0 commit comments

Comments
 (0)