Skip to content

Commit

Permalink
Merge pull request #495 from SumoLogic/INVS-1146_Entity_Group_Invento…
Browse files Browse the repository at this point in the history
…ry_enhancements

INVS-1146: Inventory Entity Group enhancements
  • Loading branch information
pmontiel-sumo authored Sep 19, 2023
2 parents b632e21 + 378f7b9 commit 7611847
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 29 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ FEATURES:
* **New Resource:** sumologic_cse_tag_schema (GH-575)
* **New Resource:** sumologic_cse_context_action (GH-573)

ENHANCEMENTS:
* resource/sumologic_cse_inventory_entity_group_configuration: Add new fields to support enhanced functionality. (GH-495)

DEPRECATIONS:
* resource/sumologic_cse_inventory_entity_group_configuration: Deprecated `groups` in favor of `inventory_key`, `inventory_value`. (GH-495)

## 2.26.0 (September 7, 2023)
FEATURES:
* **New Resource:** sumologic_muting_schedule (GH-569)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ func resourceSumologicCSEInventoryEntityGroupConfiguration() *schema.Resource {

Schema: map[string]*schema.Schema{
"criticality": {
Type: schema.TypeString,
Optional: true,
Default: "",
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"description": {
Type: schema.TypeString,
Optional: true,
Default: "",
},
"group": {
Type: schema.TypeString,
Optional: true,
Default: "",
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
Deprecated: "The field `group` is deprecated and will be removed in a future release of the provider -- please make usage of `inventory_key`, `inventory_value` instead.",
},
"inventory_type": {
Type: schema.TypeString,
Expand All @@ -41,9 +41,30 @@ func resourceSumologicCSEInventoryEntityGroupConfiguration() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"inventory_key": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"inventory_value": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"tag_schema": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"dynamic_tags": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"name": {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"suppressed": {
Type: schema.TypeBool,
Expand All @@ -54,7 +75,8 @@ func resourceSumologicCSEInventoryEntityGroupConfiguration() *schema.Resource {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Type: schema.TypeString,
ValidateFunc: validation.StringIsNotEmpty,
},
},
},
Expand Down Expand Up @@ -83,6 +105,10 @@ func resourceSumologicCSEInventoryEntityGroupConfigurationRead(d *schema.Resourc
d.Set("group", CSEInventoryEntityGroupConfigurationGet.Group)
d.Set("inventory_type", CSEInventoryEntityGroupConfigurationGet.InventoryType)
d.Set("inventory_source", CSEInventoryEntityGroupConfigurationGet.InventorySource)
d.Set("inventory_key", CSEInventoryEntityGroupConfigurationGet.InventoryKey)
d.Set("inventory_value", CSEInventoryEntityGroupConfigurationGet.InventoryValue)
d.Set("tag_schema", CSEInventoryEntityGroupConfigurationGet.TagSchema)
d.Set("dynamic_tags", CSEInventoryEntityGroupConfigurationGet.DynamicTags)
d.Set("name", CSEInventoryEntityGroupConfigurationGet.Name)
d.Set("suppressed", CSEInventoryEntityGroupConfigurationGet.Suppressed)
d.Set("tags", CSEInventoryEntityGroupConfigurationGet.Tags)
Expand All @@ -107,6 +133,10 @@ func resourceSumologicCSEInventoryEntityGroupConfigurationCreate(d *schema.Resou
Group: d.Get("group").(string),
InventoryType: d.Get("inventory_type").(string),
InventorySource: d.Get("inventory_source").(string),
InventoryKey: d.Get("inventory_key").(string),
InventoryValue: d.Get("inventory_value").(string),
TagSchema: d.Get("tag_schema").(string),
DynamicTags: d.Get("dynamic_tags").(bool),
Name: d.Get("name").(string),
Suppressed: d.Get("suppressed").(bool),
Tags: resourceToStringArray(d.Get("tags").([]interface{})),
Expand Down Expand Up @@ -148,6 +178,10 @@ func resourceToCSEInventoryEntityGroupConfiguration(d *schema.ResourceData) (CSE
Group: d.Get("group").(string),
InventoryType: d.Get("inventory_type").(string),
InventorySource: d.Get("inventory_source").(string),
InventoryKey: d.Get("inventory_key").(string),
InventoryValue: d.Get("inventory_value").(string),
TagSchema: d.Get("tag_schema").(string),
DynamicTags: d.Get("dynamic_tags").(bool),
Name: d.Get("name").(string),
Suppressed: d.Get("suppressed").(bool),
Tags: resourceToStringArray(d.Get("tags").([]interface{})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ func TestAccSumologicCSEInventoryEntityGroupConfiguration_createAndUpdate(t *tes
var InventoryEntityGroupConfiguration CSEEntityGroupConfiguration
criticality := "HIGH"
description := "Test description"
group := "goo"
inventoryKey := "groups"
inventoryValue := "red"
inventoryType := "computer"
inventorySource := "Active Directory"
name := "Entity Group Configuration Tf test"
suppressed := false
tag := "foo"
nameUpdated := "Updated Entity Group Configuration"
suppressedUpdated := true
tagUpdated := "goo"
inventoryKeyUpdated := "normalizedHostname"
inventoryValueUpdated := "blue"

resourceName := "sumologic_cse_inventory_entity_group_configuration.inventory_entity_group_configuration"
resource.Test(t, resource.TestCase{
Expand All @@ -29,22 +34,22 @@ func TestAccSumologicCSEInventoryEntityGroupConfiguration_createAndUpdate(t *tes
CheckDestroy: testAccCSEInventoryEntityGroupConfigurationDestroy,
Steps: []resource.TestStep{
{
Config: testCreateCSEInventoryEntityGroupConfigurationConfig(criticality, description, group,
inventoryType, inventorySource, name, suppressed, tag),
Config: testCreateCSEInventoryEntityGroupConfigurationConfig(criticality, description,
inventoryType, inventorySource, inventoryKey, inventoryValue, name, suppressed, tag),
Check: resource.ComposeTestCheckFunc(
testCheckCSEInventoryEntityGroupConfigurationExists(resourceName, &InventoryEntityGroupConfiguration),
testCheckInventoryEntityGroupConfigurationValues(&InventoryEntityGroupConfiguration, criticality,
description, group, inventoryType, inventorySource, name, suppressed, tag),
description, inventoryType, inventorySource, inventoryKey, inventoryValue, name, suppressed, tag),
resource.TestCheckResourceAttrSet(resourceName, "id"),
),
},
{
Config: testCreateCSEInventoryEntityGroupConfigurationConfig(criticality, description, group,
inventoryType, inventorySource, nameUpdated, suppressed, tag),
Config: testCreateCSEInventoryEntityGroupConfigurationConfig(criticality, description,
inventoryType, inventorySource, inventoryKeyUpdated, inventoryValueUpdated, nameUpdated, suppressedUpdated, tagUpdated),
Check: resource.ComposeTestCheckFunc(
testCheckCSEInventoryEntityGroupConfigurationExists(resourceName, &InventoryEntityGroupConfiguration),
testCheckInventoryEntityGroupConfigurationValues(&InventoryEntityGroupConfiguration, criticality,
description, group, inventoryType, inventorySource, nameUpdated, suppressed, tag),
description, inventoryType, inventorySource, inventoryKeyUpdated, inventoryValueUpdated, nameUpdated, suppressedUpdated, tagUpdated),
resource.TestCheckResourceAttrSet(resourceName, "id"),
),
},
Expand Down Expand Up @@ -77,20 +82,21 @@ func testAccCSEInventoryEntityGroupConfigurationDestroy(s *terraform.State) erro
}

func testCreateCSEInventoryEntityGroupConfigurationConfig(
criticality string, description string, group string,
inventoryType string, inventorySource string, name string, suppressed bool, tag string) string {
criticality string, description string,
inventoryType string, inventorySource string, inventoryKey string, inventoryValue string, name string, suppressed bool, tag string) string {
return fmt.Sprintf(`
resource "sumologic_cse_inventory_entity_group_configuration" "inventory_entity_group_configuration" {
criticality = "%s"
description = "%s"
group = "%s"
inventory_type = "%s"
inventory_source = "%s"
inventory_key = "%s"
inventory_value = "%s"
name = "%s"
suppressed = %t
tags = ["%s"]
}
`, criticality, description, group, inventoryType, inventorySource, name, suppressed, tag)
`, criticality, description, inventoryType, inventorySource, inventoryKey, inventoryValue, name, suppressed, tag)
}

func testCheckCSEInventoryEntityGroupConfigurationExists(n string, InventoryEntityGroupConfiguration *CSEEntityGroupConfiguration) resource.TestCheckFunc {
Expand All @@ -117,17 +123,23 @@ func testCheckCSEInventoryEntityGroupConfigurationExists(n string, InventoryEnti
}

func testCheckInventoryEntityGroupConfigurationValues(InventoryEntityGroupConfiguration *CSEEntityGroupConfiguration,
criticality string, description string, group string,
inventoryType string, inventorySource string, name string, suppressed bool, tag string) resource.TestCheckFunc {
criticality string, description string,
inventoryType string, inventorySource string, inventoryKey string, inventoryValue string, name string, suppressed bool, tag string) resource.TestCheckFunc {
return func(s *terraform.State) error {
if InventoryEntityGroupConfiguration.Criticality != criticality {
return fmt.Errorf("bad criticality, expected \"%s\", got %#v", criticality, InventoryEntityGroupConfiguration.Criticality)
}
if InventoryEntityGroupConfiguration.Description != description {
return fmt.Errorf("bad description, expected \"%s\", got %#v", description, InventoryEntityGroupConfiguration.Description)
}
if InventoryEntityGroupConfiguration.Group != group {
return fmt.Errorf("bad group, expected \"%s\", got %#v", tag, InventoryEntityGroupConfiguration.Group)
if InventoryEntityGroupConfiguration.InventoryKey != inventoryKey {
return fmt.Errorf("bad inventoryKey, expected \"%s\", got %#v", inventoryKey, InventoryEntityGroupConfiguration.InventoryKey)
}
if InventoryEntityGroupConfiguration.InventoryValue != inventoryValue {
return fmt.Errorf("bad inventoryValue, expected \"%s\", got %#v", inventoryValue, InventoryEntityGroupConfiguration.InventoryValue)
}
if InventoryEntityGroupConfiguration.DynamicTags != false {
return fmt.Errorf("bad dynamicTags, expected false, got %#v", InventoryEntityGroupConfiguration.DynamicTags)
}
if InventoryEntityGroupConfiguration.InventoryType != inventoryType {
return fmt.Errorf("bad inventoryType, expected \"%s\", got %#v", inventoryType, InventoryEntityGroupConfiguration.InventoryType)
Expand Down
4 changes: 4 additions & 0 deletions sumologic/sumologic_cse_entity_group_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ type CSEEntityGroupConfiguration struct {
Group string `json:"group,omitempty"`
InventoryType string `json:"inventoryType,omitempty"`
InventorySource string `json:"inventorySource,omitempty"`
InventoryKey string `json:"inventoryKey,omitempty"`
InventoryValue string `json:"inventoryValue,omitempty"`
DynamicTags bool `json:"dynamicTags,omitempty"`
TagSchema string `json:"tagSchema,omitempty"`
LastUpdated string `json:"lastUpdated,omitempty,omitempty"`
LastUpdatedBy string `json:"lastUpdatedBy,omitempty,omitempty"`
Name string `json:"name,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ description: |-
resource "sumologic_cse_inventory_entity_group_configuration" "inventory_entity_group_configuration" {
criticality = "HIGH"
description = "Inventory entity group description"
group = "admin"
inventory_type = "user"
inventory_type = "username"
inventory_source = "Active Directory"
inventory_key = "groups"
inventory_value = "http_servers"
name = "Inventory entity group configuration"
suppressed = false
tags = ["tag"]
Expand All @@ -25,9 +26,13 @@ The following arguments are supported:

- `criticality` - (Optional) The entity group configuration criticality Examples: "HIGH", "CRITICALITY".
- `description` - (Optional) The entity group configuration description.
- `group` - (Optional) The entity group configuration inventory group.
- `inventory_type` - (Required) The inventory type Examples: "computer", "user".
- `group` - (Optional)(Deprecated) The entity group configuration inventory group. The field `group` is deprecated and will be removed in a future release of the provider -- please make usage of `inventory_key`, `inventory_value` instead.
- `inventory_type` - (Required) The inventory type Examples: "computer", "username".
- `inventory_source` - (Required) The inventory source Examples: "Active Directory", "Okta".
- `inventory_key` - (Required) The inventory key to apply configuration Examples: "groups", "normalizedHostname", "normalizedComputerName".
- `inventory_value` - (Optional) The inventory value to match.
- `dynamic_tags` - (Optional) If dynamic tags are enabled for configuration.
- `tag_schema` - (Optional) The tag schema to be used for dynamic tags.
- `name` - (Required) The entity group configuration name.
- `suppresed` - (Optional) The entity group configuration suppressed value
- `tags` - (Optional) The entity group configuration tags list.
Expand Down

0 comments on commit 7611847

Please sign in to comment.