Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added enablement for error toolchain, Topic resource update to support Scheduler and Added Scheduler Subscription resources #5893

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/IBM/configuration-aggregator-go-sdk v0.0.2
github.com/IBM/container-registry-go-sdk v1.1.0
github.com/IBM/continuous-delivery-go-sdk/v2 v2.0.2
github.com/IBM/event-notifications-go-admin-sdk v0.11.0
github.com/IBM/event-notifications-go-admin-sdk v0.12.0
github.com/IBM/eventstreams-go-sdk v1.4.0
github.com/IBM/go-sdk-core v1.1.0
github.com/IBM/go-sdk-core/v3 v3.2.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ github.com/IBM/container-registry-go-sdk v1.1.0 h1:sYyknIod8R4RJZQqAheiduP6wbSTp
github.com/IBM/container-registry-go-sdk v1.1.0/go.mod h1:4TwsCnQtVfZ4Vkapy/KPvQBKFc3VOyUZYkwRU4FTPrs=
github.com/IBM/continuous-delivery-go-sdk/v2 v2.0.2 h1:yCJJnSLNYkpF7v9n0tw8CpQbSy43E/NbFOopRf1PgoM=
github.com/IBM/continuous-delivery-go-sdk/v2 v2.0.2/go.mod h1:2MajFr6C5H2jyj7qtjBxAPnZAjbPiK4CAJNk3fKNnPo=
github.com/IBM/event-notifications-go-admin-sdk v0.11.0 h1:X/GhBE6dGRx8s79xYrdmv88ljD/8hSCyh9jMSUPCcCc=
github.com/IBM/event-notifications-go-admin-sdk v0.11.0/go.mod h1:za2mdfBpox6hdsKaYTbE5ooCv2im8BYPq5yuKc7x5Ao=
github.com/IBM/event-notifications-go-admin-sdk v0.12.0 h1:sQzXh/e0gTsz1obYUgCSHKQhNE025lH25+11ICP5q90=
github.com/IBM/event-notifications-go-admin-sdk v0.12.0/go.mod h1:za2mdfBpox6hdsKaYTbE5ooCv2im8BYPq5yuKc7x5Ao=
github.com/IBM/eventstreams-go-sdk v1.4.0 h1:yS/Ns29sBOe8W2tynQmz9HTKqQZ0ckse4Py5Oy/F2rM=
github.com/IBM/eventstreams-go-sdk v1.4.0/go.mod h1:2tuAxaYLctfqfr5jvyqSrxxEQGMwYPm3yJGWSj85YVQ=
github.com/IBM/go-sdk-core v1.1.0 h1:pV73lZqr9r1xKb3h08c1uNG3AphwoV5KzUzhS+pfEqY=
Expand Down
2 changes: 2 additions & 0 deletions ibm/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,7 @@ func Provider() *schema.Provider {
"ibm_en_metrics": eventnotification.DataSourceIBMEnMetrics(),
"ibm_en_smtp_allowed_ips": eventnotification.DataSourceIBMEnSMTPAllowedIps(),
"ibm_en_webhook_template": eventnotification.DataSourceIBMEnWebhookTemplate(),
"ibm_en_subscription_scheduler": eventnotification.DataSourceIBMEnFCMSubscription(),

// Added for Toolchain
"ibm_cd_toolchain": cdtoolchain.DataSourceIBMCdToolchain(),
Expand Down Expand Up @@ -1564,6 +1565,7 @@ func Provider() *schema.Provider {
"ibm_en_slack_template": eventnotification.ResourceIBMEnSlackTemplate(),
"ibm_en_smtp_setting": eventnotification.ResourceIBMEnSMTPSetting(),
"ibm_en_webhook_template": eventnotification.ResourceIBMEnWebhookTemplate(),
"ibm_en_subscription_scheduler": eventnotification.ResourceIBMEnFCMSubscription(),

// Added for Toolchain
"ibm_cd_toolchain": cdtoolchain.ResourceIBMCdToolchain(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ package eventnotification
import (
"context"
"fmt"
"log"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"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"

Expand Down Expand Up @@ -61,45 +63,55 @@ func DataSourceIBMEnFCMSubscription() *schema.Resource {
func dataSourceIBMEnFCMSubscriptionRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
enClient, err := meta.(conns.ClientSession).EventNotificationsApiV1()
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, err.Error(), "(Data) ibm_en_subscription", "read")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}

getSubscriptionOptions := &en.GetSubscriptionOptions{}

getSubscriptionOptions.SetInstanceID(d.Get("instance_guid").(string))
getSubscriptionOptions.SetID(d.Get("subscription_id").(string))

result, response, err := enClient.GetSubscriptionWithContext(context, getSubscriptionOptions)
result, _, err := enClient.GetSubscriptionWithContext(context, getSubscriptionOptions)
if err != nil {
return diag.FromErr(fmt.Errorf("GetSubscriptionWithContext failed %s\n%s", err, response))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetSubscriptionWithContext failed: %s", err.Error()), "(Data) ibm_en_subscription", "read")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}

d.SetId(fmt.Sprintf("%s/%s", *getSubscriptionOptions.InstanceID, *getSubscriptionOptions.ID))

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

if result.Description != nil {
if err = d.Set("description", result.Description); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting description: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting description: %s", err), "(Data) ibm_en_subscription", "read")
return tfErr.GetDiag()
}
}
if err = d.Set("updated_at", result.UpdatedAt); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_at: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf(" Error setting updated_at: %s", err), "(Data) ibm_en_subscription", "read")
return tfErr.GetDiag()
}

if err = d.Set("destination_id", result.DestinationID); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting destination_id: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting destination_id: %s", err), "(Data) ibm_en_subscription", "read")
return tfErr.GetDiag()
}

if err = d.Set("topic_id", result.TopicID); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting topic_id: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting topic_id: %s", err), "(Data) ibm_en_subscription", "read")
return tfErr.GetDiag()
}

if result.From != nil {
if err = d.Set("from", result.From); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting from %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting from: %s", err), "(Data) ibm_en_subscription", "read")
return tfErr.GetDiag()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ package eventnotification
import (
"context"
"fmt"
"log"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"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"

Expand Down Expand Up @@ -87,45 +89,55 @@ func DataSourceIBMEnWebhookSubscription() *schema.Resource {
func dataSourceIBMEnWebhookSubscriptionRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
enClient, err := meta.(conns.ClientSession).EventNotificationsApiV1()
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, err.Error(), "(Data) ibm_en_subscription_sms", "read")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}

getSubscriptionOptions := &en.GetSubscriptionOptions{}

getSubscriptionOptions.SetInstanceID(d.Get("instance_guid").(string))
getSubscriptionOptions.SetID(d.Get("subscription_id").(string))

result, response, err := enClient.GetSubscriptionWithContext(context, getSubscriptionOptions)
result, _, err := enClient.GetSubscriptionWithContext(context, getSubscriptionOptions)
if err != nil {
return diag.FromErr(fmt.Errorf("GetSubscriptionWithContext failed %s\n%s", err, response))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetSubscriptionWithContext failed: %s", err.Error()), "(Data) ibm_en_subscription_sms", "read")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}

d.SetId(fmt.Sprintf("%s/%s", *getSubscriptionOptions.InstanceID, *getSubscriptionOptions.ID))

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

if result.Description != nil {
if err = d.Set("description", result.Description); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting description: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting description: %s", err), "(Data) ibm_en_subscription_webhook", "read")
return tfErr.GetDiag()
}
}
if err = d.Set("updated_at", result.UpdatedAt); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_at: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting updated_at: %s", err), "(Data) ibm_en_subscription_webhook", "read")
return tfErr.GetDiag()
}

if err = d.Set("destination_id", result.DestinationID); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting destination_id: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting destination_id: %s", err), "(Data) ibm_en_subscription_webhook", "read")
return tfErr.GetDiag()
}

if err = d.Set("topic_id", result.TopicID); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting topic_id: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting topic_id: %s", err), "(Data) ibm_en_subscription_webhook", "read")
return tfErr.GetDiag()
}

if result.Attributes != nil {
if err = d.Set("attributes", enWebhookSubscriptionFlattenAttributes(result.Attributes)); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting attributes %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting attributes: %s", err), "(Data) ibm_en_subscription_webhook", "read")
return tfErr.GetDiag()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package eventnotification
import (
"context"
"fmt"
"log"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
Expand Down Expand Up @@ -137,67 +138,81 @@ func DataSourceIBMEnAPNSDestination() *schema.Resource {
func dataSourceIBMEnAPNSDestinationRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
enClient, err := meta.(conns.ClientSession).EventNotificationsApiV1()
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, err.Error(), "(Data) ibm_en_destination_ios", "read")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}

options := &en.GetDestinationOptions{}

options.SetInstanceID(d.Get("instance_guid").(string))
options.SetID(d.Get("destination_id").(string))

result, response, err := enClient.GetDestinationWithContext(context, options)
result, _, err := enClient.GetDestinationWithContext(context, options)
if err != nil {
return diag.FromErr(fmt.Errorf("GetDestination failed %s\n%s", err, response))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetDestinationWithContext failed: %s", err.Error()), "(Data) ibm_en_destination_ios", "read")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}

d.SetId(fmt.Sprintf("%s/%s", *options.InstanceID, *options.ID))

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

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

if err = d.Set("type", result.Type); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting type: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting type: %s", err), "(Data) ibm_en_destination_ios", "read")
return tfErr.GetDiag()
}

if err = d.Set("collect_failed_events", result.CollectFailedEvents); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting CollectFailedEvents: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting CollectFailedEvents: %s", err), "(Data) ibm_en_destination_ios", "read")
return tfErr.GetDiag()
}

if err = d.Set("certificate_content_type", result.Type); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting certificate content type: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting certificate content type: %s", err), "(Data) ibm_en_destination_ios", "read")
return tfErr.GetDiag()
}

if err = d.Set("certificate", result.Type); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting certifiacte: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting certifiacte: %s", err), "(Data) ibm_en_destination_ios", "read")
return tfErr.GetDiag()
}

if result.Config != nil {
err = d.Set("config", enAPNSDestinationFlattenConfig(*result.Config))
if err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting config %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting config: %s", err), "(Data) ibm_en_destination_ios", "read")
return tfErr.GetDiag()
}
}

if result.SubscriptionNames != nil {
err = d.Set("subscription_names", result.SubscriptionNames)
if err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting subscription_names %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting subscription_names: %s", err), "(Data) ibm_en_destination_ios", "read")
return tfErr.GetDiag()
}
}

if err = d.Set("updated_at", flex.DateTimeToString(result.UpdatedAt)); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_at: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting updated_at: %s", err), "(Data) ibm_en_destination_ios", "read")
return tfErr.GetDiag()
}

if err = d.Set("subscription_count", flex.IntValue(result.SubscriptionCount)); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting subscription_count: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting subscription_count: %s", err), "(Data) ibm_en_destination_ios", "read")
return tfErr.GetDiag()
}

return nil
Expand Down
35 changes: 24 additions & 11 deletions ibm/service/eventnotification/data_source_ibm_en_destination_ce.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package eventnotification
import (
"context"
"fmt"
"log"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
Expand Down Expand Up @@ -133,59 +134,71 @@ func DataSourceIBMEnCodeEngineDestination() *schema.Resource {
func dataSourceIBMEnCodeEngineDestinationRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
enClient, err := meta.(conns.ClientSession).EventNotificationsApiV1()
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, err.Error(), "(Data) ibm_en_destination_ce", "read")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}

options := &en.GetDestinationOptions{}

options.SetInstanceID(d.Get("instance_guid").(string))
options.SetID(d.Get("destination_id").(string))

result, response, err := enClient.GetDestinationWithContext(context, options)
result, _, err := enClient.GetDestinationWithContext(context, options)
if err != nil {
return diag.FromErr(fmt.Errorf("GetDestination failed %s\n%s", err, response))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetDestinationWithContext failed: %s", err.Error()), "(Data) ibm_en_destination_ce", "read")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}

d.SetId(fmt.Sprintf("%s/%s", *options.InstanceID, *options.ID))

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

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

if err = d.Set("type", result.Type); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting type: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting type: %s", err), "(Data) ibm_en_destination_ce", "read")
return tfErr.GetDiag()
}

if err = d.Set("collect_failed_events", result.CollectFailedEvents); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting CollectFailedEvents: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting CollectFailedEvents: %s", err), "(Data) ibm_en_destination_ce", "read")
return tfErr.GetDiag()
}

if result.Config != nil {
err = d.Set("config", enCodeEngineDestinationFlattenConfig(*result.Config))
if err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting config %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting config: %s", err), "(Data) ibm_en_destination_ce", "read")
return tfErr.GetDiag()
}
}

if result.SubscriptionNames != nil {
err = d.Set("subscription_names", result.SubscriptionNames)
if err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting subscription_names %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting subscription_names: %s", err), "(Data) ibm_en_destination_ce", "read")
return tfErr.GetDiag()
}
}

if err = d.Set("updated_at", flex.DateTimeToString(result.UpdatedAt)); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_at: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting updated_at: %s", err), "(Data) ibm_en_destination_ce", "read")
return tfErr.GetDiag()
}

if err = d.Set("subscription_count", flex.IntValue(result.SubscriptionCount)); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting subscription_count: %s", err))
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting subscription_count: %s", err), "(Data) ibm_en_destination_ce", "read")
return tfErr.GetDiag()
}

return nil
Expand Down
Loading
Loading