Skip to content

Commit f05dae2

Browse files
authored
SM event notification datasource should not fail when no registration exists (#6692)
1 parent 403ce71 commit f05dae2

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

ibm/service/secretsmanager/data_source_ibm_sm_en_registration.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,16 @@ func dataSourceIbmSmEnRegistrationRead(context context.Context, d *schema.Resour
4242

4343
getNotificationsRegistrationOptions := &secretsmanagerv2.GetNotificationsRegistrationOptions{}
4444

45+
enInstanceCrn := "" // default value if event notification registration doesn't exist
4546
notificationsRegistration, response, err := secretsManagerClient.GetNotificationsRegistrationWithContext(context, getNotificationsRegistrationOptions)
4647
if err != nil {
47-
log.Printf("[DEBUG] GetNotificationsRegistrationWithContext failed %s\n%s", err, response)
48-
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetNotificationsRegistrationWithContext failed %s\n%s", err, response), fmt.Sprintf("(Data) %s", EnRegistrationResourceName), "read")
49-
return tfErr.GetDiag()
48+
if response.StatusCode != 404 {
49+
log.Printf("[DEBUG] GetNotificationsRegistrationWithContext failed %s\n%s", err, response)
50+
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetNotificationsRegistrationWithContext failed %s\n%s", err, response), fmt.Sprintf("(Data) %s", EnRegistrationResourceName), "read")
51+
return tfErr.GetDiag()
52+
}
53+
} else {
54+
enInstanceCrn = *notificationsRegistration.EventNotificationsInstanceCrn
5055
}
5156

5257
d.SetId(fmt.Sprintf("%s/%s", region, instanceId))
@@ -55,7 +60,7 @@ func dataSourceIbmSmEnRegistrationRead(context context.Context, d *schema.Resour
5560
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting region"), fmt.Sprintf("(Data) %s", EnRegistrationResourceName), "read")
5661
return tfErr.GetDiag()
5762
}
58-
if err = d.Set("event_notifications_instance_crn", notificationsRegistration.EventNotificationsInstanceCrn); err != nil {
63+
if err = d.Set("event_notifications_instance_crn", enInstanceCrn); err != nil {
5964
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting event_notifications_instance_crn"), fmt.Sprintf("(Data) %s", EnRegistrationResourceName), "read")
6065
return tfErr.GetDiag()
6166
}

website/docs/d/sm_en_registration.html.markdown

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,5 @@ Review the argument reference that you can specify for your data source.
3333
In addition to all argument references listed, you can access the following attribute references after your data source is created.
3434

3535
* `id` - The unique identifier of the data source.
36-
* `event_notifications_instance_crn` - (String) A CRN that uniquely identifies an IBM Cloud resource.
37-
* Constraints: The maximum length is `512` characters. The minimum length is `9` characters. The value must match regular expression `/^crn:v[0-9](:([A-Za-z0-9-._~!$&'()*+,;=@\/]|%[0-9A-Z]{2})*){8}$/`.
36+
* `event_notifications_instance_crn` - (String) A CRN that uniquely identifies an IBM Cloud resource. If event notification registration does not exist for the Secret Mnager instance the value is an empty string.
3837

0 commit comments

Comments
 (0)