Skip to content

Commit

Permalink
SM New error formatting + crypto_key label name changes (IBM-Cloud#5562)
Browse files Browse the repository at this point in the history
* SC addition

* SC addition

* SC addition

* update function updated

* SC unit tests added

* SC unit tests added

* d

* tests fixes

* tests fixes

* update sdk

* .secrets.baseline update

* .secrets.baseline update

* .secrets.baseline update

* Update sm_service_credentials_secret_metadata.html.markdown

* bugs fixes

* bugs fixes

* bugs fixes

* docs bugs fixes

* preferred_chain added for public cert lets encrypt configuration

* support for creating secret version for username password & version_custom_metadata for all

* support for creating secret version for username password & version_custom_metadata for all

* support for creating secret version for username password & version_custom_metadata for all

* support for creating secret version for username password & version_custom_metadata for all

* support for creating secret version for username password & version_custom_metadata for all

* support for creating secret version for username password & version_custom_metadata for all

* preferred chain docs update

* support for creating secret version for username password & version_custom_metadata for all

* support for creating secret version for username password & version_custom_metadata for all

* support for creating secret version for username password & version_custom_metadata for all

* fix public cert bug

* update docs

* reordering bug in alt_names

* name regex fix in docs

* imported cert bug fix

* crypto_key addition

* crypto_key addition

* crypto_key addition

* crypto_key addition

* rejections fixes

* rejections fixes

* rejections fixes

* rejections fixes

* rejections fixes

* test label name changed

* test label name changed

* error formating update

* go sdk version update

---------

Co-authored-by: Yonathan-Yellin <yonathan.yellin@ibm.com>
Co-authored-by: Avi Ribchinsky <avir@il.ibm.com>
Co-authored-by: Tatyana <tatyanab@il.ibm.com>
Co-authored-by: Idan Adar <iadar@il.ibm.com>
  • Loading branch information
5 people authored and Ramya-c4 committed Sep 27, 2024
1 parent 4712cab commit fe5fd7e
Show file tree
Hide file tree
Showing 53 changed files with 2,518 additions and 1,267 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ require (
github.com/IBM/sarama v1.41.2
github.com/IBM/scc-go-sdk/v5 v5.4.1
github.com/IBM/schematics-go-sdk v0.2.3
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.5
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.6
github.com/IBM/vmware-go-sdk v0.1.2
github.com/IBM/vpc-beta-go-sdk v0.6.0
github.com/IBM/vpc-go-sdk v0.57.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ github.com/IBM/schematics-go-sdk v0.2.3 h1:lgTt0Sbudii3cuSk1YSQgrtiZAXDbBABAoVj3
github.com/IBM/schematics-go-sdk v0.2.3/go.mod h1:Tw2OSAPdpC69AxcwoyqcYYaGTTW6YpERF9uNEU+BFRQ=
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.5 h1:VMc/Zd6RzB8j60CqZekkwYT2wQsCfrkGV2n01Gviuaw=
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.5/go.mod h1:5kUgJ1dG9cdiAcPDqVz46m362bPnoqZQSth24NiowSg=
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.6 h1:bF6bAdI4wDZSje6+Yx1mJxvirboxO+uMuKhzgfRCNxE=
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.6/go.mod h1:XWYnbcc5vN1RnKwk/fCzfD8aZd7At/Y1/b6c+oDyliU=
github.com/IBM/vmware-go-sdk v0.1.2 h1:5lKWFyInWz9e2hwGsoFTEoLa1jYkD30SReN0fQ10w9M=
github.com/IBM/vmware-go-sdk v0.1.2/go.mod h1:2UGPBJju3jiv5VKKBBm9a5L6bzF/aJdKOKAzJ7HaOjA=
github.com/IBM/vpc-beta-go-sdk v0.6.0 h1:wfM3AcW3zOM3xsRtZ+EA6+sESlGUjQ6Yf4n5QQyz4uc=
Expand Down
57 changes: 37 additions & 20 deletions ibm/service/secretsmanager/data_source_ibm_sm_arbitrary_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ func DataSourceIbmSmArbitrarySecret() *schema.Resource {
}

func dataSourceIbmSmArbitrarySecretRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {

secret, region, instanceId, diagError := getSecretByIdOrByName(context, d, meta, ArbitrarySecretType)
secret, region, instanceId, diagError := getSecretByIdOrByName(context, d, meta, ArbitrarySecretType, ArbitrarySecretResourceName)
if diagError != nil {
return diagError
}
Expand All @@ -142,18 +141,22 @@ func dataSourceIbmSmArbitrarySecretRead(context context.Context, d *schema.Resou

var err error
if err = d.Set("region", region); err != nil {
return diag.FromErr(fmt.Errorf("Error setting region: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting region"), fmt.Sprintf("(Data) %s", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}
if err = d.Set("created_by", arbitrarySecret.CreatedBy); err != nil {
return diag.FromErr(fmt.Errorf("Error setting created_by: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting created_by"), fmt.Sprintf("(Data) %s", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("created_at", DateTimeToRFC3339(arbitrarySecret.CreatedAt)); err != nil {
return diag.FromErr(fmt.Errorf("Error setting created_at: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting created_at"), fmt.Sprintf("(Data) %s", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("crn", arbitrarySecret.Crn); err != nil {
return diag.FromErr(fmt.Errorf("Error setting crn: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting crn"), fmt.Sprintf("(Data) %s", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if arbitrarySecret.CustomMetadata != nil {
Expand All @@ -163,59 +166,73 @@ func dataSourceIbmSmArbitrarySecretRead(context context.Context, d *schema.Resou
}

if err = d.Set("custom_metadata", flex.Flatten(convertedMap)); err != nil {
return diag.FromErr(fmt.Errorf("Error setting custom_metadata: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting custom_metadata"), fmt.Sprintf("(Data) %s", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}
if err != nil {
return diag.FromErr(fmt.Errorf("Error setting custom_metadata %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting custom_metadata"), fmt.Sprintf("(Data) %s", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}
}

if err = d.Set("description", arbitrarySecret.Description); err != nil {
return diag.FromErr(fmt.Errorf("Error setting description: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting description"), fmt.Sprintf("(Data) %s", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("downloaded", arbitrarySecret.Downloaded); err != nil {
return diag.FromErr(fmt.Errorf("Error setting downloaded: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting downloaded"), fmt.Sprintf("(Data) %s", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("locks_total", flex.IntValue(arbitrarySecret.LocksTotal)); err != nil {
return diag.FromErr(fmt.Errorf("Error setting locks_total: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting locks_total"), fmt.Sprintf("(Data) %s", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("name", arbitrarySecret.Name); err != nil {
return diag.FromErr(fmt.Errorf("Error setting name: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting name"), fmt.Sprintf("(Data) %s", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("secret_group_id", arbitrarySecret.SecretGroupID); err != nil {
return diag.FromErr(fmt.Errorf("Error setting secret_group_id: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting secret_group_id"), fmt.Sprintf("(Data) %s", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("secret_type", arbitrarySecret.SecretType); err != nil {
return diag.FromErr(fmt.Errorf("Error setting secret_type: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting secret_type"), fmt.Sprintf("(Data) %s", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("state", flex.IntValue(arbitrarySecret.State)); err != nil {
return diag.FromErr(fmt.Errorf("Error setting state: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting state"), fmt.Sprintf("(Data) %s", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("state_description", arbitrarySecret.StateDescription); err != nil {
return diag.FromErr(fmt.Errorf("Error setting state_description: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting state_description"), fmt.Sprintf("(Data) %s", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("updated_at", DateTimeToRFC3339(arbitrarySecret.UpdatedAt)); err != nil {
return diag.FromErr(fmt.Errorf("Error setting updated_at: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting updated_at"), fmt.Sprintf("(Data) %s", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("versions_total", flex.IntValue(arbitrarySecret.VersionsTotal)); err != nil {
return diag.FromErr(fmt.Errorf("Error setting versions_total: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting versions_total"), fmt.Sprintf("(Data) %s", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("expiration_date", DateTimeToRFC3339(arbitrarySecret.ExpirationDate)); err != nil {
return diag.FromErr(fmt.Errorf("Error setting expiration_date: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting expiration_date"), fmt.Sprintf("(Data) %s", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("payload", arbitrarySecret.Payload); err != nil {
return diag.FromErr(fmt.Errorf("Error setting payload: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting payload"), fmt.Sprintf("(Data) %s", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ func DataSourceIbmSmArbitrarySecretMetadata() *schema.Resource {
func dataSourceIbmSmArbitrarySecretMetadataRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
secretsManagerClient, err := meta.(conns.ClientSession).SecretsManagerV2()
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, "", fmt.Sprintf("(Data) %s_metadata", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

region := getRegion(secretsManagerClient, d)
Expand All @@ -134,27 +135,32 @@ func dataSourceIbmSmArbitrarySecretMetadataRead(context context.Context, d *sche
arbitrarySecretMetadataIntf, response, err := secretsManagerClient.GetSecretMetadataWithContext(context, getSecretMetadataOptions)
if err != nil {
log.Printf("[DEBUG] GetSecretMetadataWithContext failed %s\n%s", err, response)
return diag.FromErr(fmt.Errorf("GetSecretMetadataWithContext failed %s\n%s", err, response))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetSecretMetadataWithContext failed %s\n%s", err, response), fmt.Sprintf("(Data) %s_metadata", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

arbitrarySecretMetadata := arbitrarySecretMetadataIntf.(*secretsmanagerv2.ArbitrarySecretMetadata)

d.SetId(fmt.Sprintf("%s/%s/%s", region, instanceId, secretId))

if err = d.Set("created_by", arbitrarySecretMetadata.CreatedBy); err != nil {
return diag.FromErr(fmt.Errorf("Error setting created_by: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting created_by"), fmt.Sprintf("(Data) %s_metadata", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("region", region); err != nil {
return diag.FromErr(fmt.Errorf("Error setting region: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting region"), fmt.Sprintf("(Data) %s_metadata", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("created_at", DateTimeToRFC3339(arbitrarySecretMetadata.CreatedAt)); err != nil {
return diag.FromErr(fmt.Errorf("Error setting created_at: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting created_at"), fmt.Sprintf("(Data) %s_metadata", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("crn", arbitrarySecretMetadata.Crn); err != nil {
return diag.FromErr(fmt.Errorf("Error setting crn: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting crn"), fmt.Sprintf("(Data) %s_metadata", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if arbitrarySecretMetadata.CustomMetadata != nil {
Expand All @@ -164,55 +170,68 @@ func dataSourceIbmSmArbitrarySecretMetadataRead(context context.Context, d *sche
}

if err = d.Set("custom_metadata", flex.Flatten(convertedMap)); err != nil {
return diag.FromErr(fmt.Errorf("Error setting custom_metadata: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting custom_metadata"), fmt.Sprintf("(Data) %s_metadata", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}
if err != nil {
return diag.FromErr(fmt.Errorf("Error setting custom_metadata %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting custom_metadata"), fmt.Sprintf("(Data) %s_metadata", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}
}

if err = d.Set("description", arbitrarySecretMetadata.Description); err != nil {
return diag.FromErr(fmt.Errorf("Error setting description: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting description"), fmt.Sprintf("(Data) %s_metadata", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("downloaded", arbitrarySecretMetadata.Downloaded); err != nil {
return diag.FromErr(fmt.Errorf("Error setting downloaded: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting downloaded"), fmt.Sprintf("(Data) %s_metadata", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("locks_total", flex.IntValue(arbitrarySecretMetadata.LocksTotal)); err != nil {
return diag.FromErr(fmt.Errorf("Error setting locks_total: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting locks_total"), fmt.Sprintf("(Data) %s_metadata", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("name", arbitrarySecretMetadata.Name); err != nil {
return diag.FromErr(fmt.Errorf("Error setting name: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting name"), fmt.Sprintf("(Data) %s_metadata", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("secret_group_id", arbitrarySecretMetadata.SecretGroupID); err != nil {
return diag.FromErr(fmt.Errorf("Error setting secret_group_id: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting secret_group_id"), fmt.Sprintf("(Data) %s_metadata", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("secret_type", arbitrarySecretMetadata.SecretType); err != nil {
return diag.FromErr(fmt.Errorf("Error setting secret_type: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting secret_type"), fmt.Sprintf("(Data) %s_metadata", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("state", flex.IntValue(arbitrarySecretMetadata.State)); err != nil {
return diag.FromErr(fmt.Errorf("Error setting state: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting state"), fmt.Sprintf("(Data) %s_metadata", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("state_description", arbitrarySecretMetadata.StateDescription); err != nil {
return diag.FromErr(fmt.Errorf("Error setting state_description: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting state_description"), fmt.Sprintf("(Data) %s_metadata", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("updated_at", DateTimeToRFC3339(arbitrarySecretMetadata.UpdatedAt)); err != nil {
return diag.FromErr(fmt.Errorf("Error setting updated_at: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting updated_at"), fmt.Sprintf("(Data) %s_metadata", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("versions_total", flex.IntValue(arbitrarySecretMetadata.VersionsTotal)); err != nil {
return diag.FromErr(fmt.Errorf("Error setting versions_total: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting versions_total"), fmt.Sprintf("(Data) %s_metadata", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

if err = d.Set("expiration_date", DateTimeToRFC3339(arbitrarySecretMetadata.ExpirationDate)); err != nil {
return diag.FromErr(fmt.Errorf("Error setting expiration_date: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting expiration_date"), fmt.Sprintf("(Data) %s_metadata", ArbitrarySecretResourceName), "read")
return tfErr.GetDiag()
}

return nil
Expand Down
19 changes: 13 additions & 6 deletions ibm/service/secretsmanager/data_source_ibm_sm_configurations.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package secretsmanager
import (
"context"
"fmt"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"log"
"time"

Expand Down Expand Up @@ -201,7 +202,8 @@ func DataSourceIbmSmConfigurations() *schema.Resource {
func dataSourceIbmSmConfigurationsRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
secretsManagerClient, err := meta.(conns.ClientSession).SecretsManagerV2()
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, "", fmt.Sprintf("(Data) %s", ConfigurationsResourceName), "read")
return tfErr.GetDiag()
}

region := getRegion(secretsManagerClient, d)
Expand Down Expand Up @@ -231,13 +233,15 @@ func dataSourceIbmSmConfigurationsRead(context context.Context, d *schema.Resour
var pager *secretsmanagerv2.ConfigurationsPager
pager, err = secretsManagerClient.NewConfigurationsPager(listConfigurationsOptions)
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, "", fmt.Sprintf("(Data) %s", ConfigurationsResourceName), "read")
return tfErr.GetDiag()
}

allItems, err := pager.GetAll()
if err != nil {
log.Printf("[DEBUG] ConfigurationsPager.GetAll() failed %s", err)
return diag.FromErr(fmt.Errorf("ConfigurationsPager.GetAll() failed %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("ConfigurationsPager.GetAll() %s", err), fmt.Sprintf("(Data) %s", ConfigurationsResourceName), "read")
return tfErr.GetDiag()
}

d.SetId(dataSourceIbmSmConfigurationsID(d))
Expand All @@ -246,16 +250,19 @@ func dataSourceIbmSmConfigurationsRead(context context.Context, d *schema.Resour
for _, modelItem := range allItems {
modelMap, err := dataSourceIbmSmConfigurationsConfigurationMetadataToMap(modelItem)
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, "", fmt.Sprintf("(Data) %s", ConfigurationsResourceName), "read")
return tfErr.GetDiag()
}
mapSlice = append(mapSlice, modelMap)
}

if err = d.Set("configurations", mapSlice); err != nil {
return diag.FromErr(fmt.Errorf("Error setting configurations %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting configurations"), fmt.Sprintf("(Data) %s", ConfigurationsResourceName), "read")
return tfErr.GetDiag()
}
if err = d.Set("total_count", len(mapSlice)); err != nil {
return diag.FromErr(fmt.Errorf("Error setting locks_total: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting total_count"), fmt.Sprintf("(Data) %s", ConfigurationsResourceName), "read")
return tfErr.GetDiag()
}

return nil
Expand Down
13 changes: 9 additions & 4 deletions ibm/service/secretsmanager/data_source_ibm_sm_en_registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package secretsmanager
import (
"context"
"fmt"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"log"
Expand All @@ -31,7 +32,8 @@ func DataSourceIbmSmEnRegistration() *schema.Resource {
func dataSourceIbmSmEnRegistrationRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
secretsManagerClient, err := meta.(conns.ClientSession).SecretsManagerV2()
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, "", fmt.Sprintf("(Data) %s", EnRegistrationResourceName), "read")
return tfErr.GetDiag()
}

region := getRegion(secretsManagerClient, d)
Expand All @@ -43,16 +45,19 @@ func dataSourceIbmSmEnRegistrationRead(context context.Context, d *schema.Resour
notificationsRegistration, response, err := secretsManagerClient.GetNotificationsRegistrationWithContext(context, getNotificationsRegistrationOptions)
if err != nil {
log.Printf("[DEBUG] GetNotificationsRegistrationWithContext failed %s\n%s", err, response)
return diag.FromErr(fmt.Errorf("GetNotificationsRegistrationWithContext failed %s\n%s", err, response))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetNotificationsRegistrationWithContext failed %s\n%s", err, response), fmt.Sprintf("(Data) %s", EnRegistrationResourceName), "read")
return tfErr.GetDiag()
}

d.SetId(fmt.Sprintf("%s/%s", region, instanceId))

if err = d.Set("region", region); err != nil {
return diag.FromErr(fmt.Errorf("Error setting region: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting region"), fmt.Sprintf("(Data) %s", EnRegistrationResourceName), "read")
return tfErr.GetDiag()
}
if err = d.Set("event_notifications_instance_crn", notificationsRegistration.EventNotificationsInstanceCrn); err != nil {
return diag.FromErr(fmt.Errorf("Error setting event_notifications_instance_crn: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting event_notifications_instance_crn"), fmt.Sprintf("(Data) %s", EnRegistrationResourceName), "read")
return tfErr.GetDiag()
}

return nil
Expand Down
Loading

0 comments on commit fe5fd7e

Please sign in to comment.