Skip to content

Commit

Permalink
fix: HOT FIX to include properties from issue 5579 (#5818)
Browse files Browse the repository at this point in the history
* fix: hot fix to include properties from 5579

- include the following properties to scc_instance_settings:
  - source_description
  - source_name

* added some validation updates
  • Loading branch information
tyao117 authored Nov 26, 2024
1 parent 4854242 commit 24b848b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
38 changes: 29 additions & 9 deletions ibm/service/scc/resource_ibm_scc_instance_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,20 @@ func ResourceIbmSccInstanceSettings() *schema.Resource {
"instance_crn": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The Event Notifications instance CRN.",
},
"source_description": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The description of the source in Event Notifications connected Security and Compliance Center",
},
"source_name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "The name of the Event Notifications source connected Security and Compliance Center instance CRN.",
},
"updated_on": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -123,11 +135,8 @@ func resourceIbmSccInstanceSettingsCreate(context context.Context, d *schema.Res
return diag.FromErr(err)
}
eventNotificationsModel = eventNotificationsData
eventNotificationsModel.SourceName = core.StringPtr("compliance")
eventNotificationsModel.SourceDescription = core.StringPtr("This source is used for integration with IBM Cloud Security and Compliance Center.")
} else {
eventNotificationsModel = &securityandcompliancecenterapiv3.EventNotifications{}
eventNotificationsModel.InstanceCrn = core.StringPtr("")
}
updateSettingsOptions.SetEventNotifications(eventNotificationsModel)

Expand All @@ -139,8 +148,7 @@ func resourceIbmSccInstanceSettingsCreate(context context.Context, d *schema.Res
}
objectStorageModel = objectStorageData
} else {
objectStorageModel := &securityandcompliancecenterapiv3.ObjectStorage{}
objectStorageModel.InstanceCrn = core.StringPtr("")
objectStorageModel = &securityandcompliancecenterapiv3.ObjectStorage{}
}
updateSettingsOptions.SetObjectStorage(objectStorageModel)

Expand Down Expand Up @@ -183,6 +191,13 @@ func resourceIbmSccInstanceSettingsRead(context context.Context, d *schema.Resou
if err != nil {
return diag.FromErr(err)
}
if _, ok := eventNotificationsMap["source_name"]; !ok {
eventNotificationsData, enErr := resourceIbmSccInstanceSettingsMapToEventNotifications(d.Get("event_notifications.0").(map[string]interface{}))
if enErr == nil && core.StringNilMapper(eventNotificationsData.SourceName) != "" {
eventNotificationsMap["source_name"] = eventNotificationsData.SourceName
log.Print("[WARN] event_notifications.source_name grabbed from preexisting state\n")
}
}
if err = d.Set("event_notifications", []map[string]interface{}{eventNotificationsMap}); err != nil {
return diag.FromErr(flex.FmtErrorf("Error setting event_notifications: %s", err))
}
Expand Down Expand Up @@ -217,10 +232,6 @@ func resourceIbmSccInstanceSettingsUpdate(context context.Context, d *schema.Res
if err != nil {
return diag.FromErr(err)
}
if eventNotifications.InstanceCrn != nil && *eventNotifications.InstanceCrn != "" {
eventNotifications.SourceName = core.StringPtr("compliance")
eventNotifications.SourceDescription = core.StringPtr("This source is used for integration with IBM Cloud Security and Compliance Center.")
}
updateSettingsOptions.SetEventNotifications(eventNotifications)
hasChange = true
}
Expand Down Expand Up @@ -266,6 +277,15 @@ func resourceIbmSccInstanceSettingsMapToEventNotifications(modelMap map[string]i
if modelMap["source_id"] != nil && modelMap["source_id"].(string) != "" {
model.SourceID = core.StringPtr(modelMap["source_id"].(string))
}
if modelMap["source_name"] != nil && modelMap["source_name"].(string) != "" {
model.SourceName = core.StringPtr(modelMap["source_name"].(string))
}
if modelMap["source_description"] != nil && modelMap["source_description"].(string) != "" {
model.SourceDescription = core.StringPtr(modelMap["source_description"].(string))
}
if core.StringNilMapper(model.InstanceCrn) != "" && core.StringNilMapper(model.SourceName) == "" {
return model, errors.New("event_notifications.source_name needs to be defined along with event_notifications.instance_crn")
}
return model, nil
}

Expand Down
12 changes: 6 additions & 6 deletions ibm/service/scc/resource_ibm_scc_instance_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestAccIbmSccInstanceSettingsBasic(t *testing.T) {
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckIbmSccInstanceSettingsDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccCheckIbmSccInstanceSettingsConfigBasic(acc.SccInstanceID),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckIbmSccInstanceSettingsExists("ibm_scc_instance_settings.scc_instance_settings_instance", conf),
Expand All @@ -42,19 +42,19 @@ func TestAccIbmSccInstanceSettingsAllArgs(t *testing.T) {
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckIbmSccInstanceSettingsDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccCheckIbmSccInstanceSettingsConfigBasic(acc.SccInstanceID),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckIbmSccInstanceSettingsExists("ibm_scc_instance_settings.scc_instance_settings_instance", conf),
),
},
resource.TestStep{
{
Config: testAccCheckIbmSccInstanceSettingsConfig(acc.SccInstanceID, acc.SccEventNotificationsCRN, acc.SccObjectStorageCRN, acc.SccObjectStorageBucket),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckIbmSccInstanceSettingsExists("ibm_scc_instance_settings.scc_instance_settings_instance", conf),
),
},
resource.TestStep{
{
ResourceName: "ibm_scc_instance_settings.scc_instance_settings_instance",
ImportState: true,
ImportStateVerify: true,
Expand All @@ -66,7 +66,7 @@ func TestAccIbmSccInstanceSettingsAllArgs(t *testing.T) {
func testAccCheckIbmSccInstanceSettingsConfigBasic(instanceID string) string {
return fmt.Sprintf(`
resource "ibm_scc_instance_settings" "scc_instance_settings_instance" {
instance_id = "%s"
instance_id = "%s"
event_notifications { }
object_storage { }
}
Expand All @@ -79,6 +79,7 @@ func testAccCheckIbmSccInstanceSettingsConfig(instanceID, enInstanceCRN, objStor
instance_id = "%s"
event_notifications {
instance_crn = "%s"
source_name = "scc compliance"
}
object_storage {
instance_crn = "%s"
Expand All @@ -89,7 +90,6 @@ func testAccCheckIbmSccInstanceSettingsConfig(instanceID, enInstanceCRN, objStor
}

func testAccCheckIbmSccInstanceSettingsExists(n string, obj securityandcompliancecenterapiv3.Settings) resource.TestCheckFunc {

return func(s *terraform.State) error {
_, ok := s.RootModule().Resources[n]
if !ok {
Expand Down
4 changes: 3 additions & 1 deletion website/docs/r/scc_instance_settings.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Nested schema for **event_notifications**:
* `source_id` - (Computed, String) The connected Security and Compliance Center instance CRN.
* Constraints: The maximum length is `512` characters. The minimum length is `1` character. The value must match regular expression `/([A-Za-z0-9]+(:[A-Za-z0-9]+)+)/`.
* `updated_on` - (Optional, String) The date when the Event Notifications connection was updated.
* `source_description` - (Optional,Computed, String) The description of the Event Notifications connection source.
* `source_name` - (Optional,Computed, String) The name of the Event Notifications connection source.
* `object_storage` - (Optional, List) The Cloud Object Storage settings.
Nested schema for **object_storage**:
* `bucket` - (Optional, String) The connected Cloud Object Storage bucket name.
Expand Down Expand Up @@ -69,4 +71,4 @@ $ terraform import ibm_scc_instance_settings.scc_instance_settings <instance_id>
# Example
```bash
$ terraform import ibm_scc_instance_settings.scc_instance_settings 00000000-1111-2222-3333-444444444444
```
```

0 comments on commit 24b848b

Please sign in to comment.