diff --git a/go.mod b/go.mod index b5ef253e041..d9976fe14f6 100644 --- a/go.mod +++ b/go.mod @@ -19,8 +19,8 @@ require ( github.com/IBM/configuration-aggregator-go-sdk v0.0.2 github.com/IBM/container-registry-go-sdk v1.2.0 github.com/IBM/continuous-delivery-go-sdk/v2 v2.0.6 + github.com/IBM/event-notifications-go-admin-sdk v0.22.0 github.com/IBM/dra-go-sdk v0.0.0-20251210070042-5072d22c26d0 - github.com/IBM/event-notifications-go-admin-sdk v0.21.0 github.com/IBM/eventstreams-go-sdk v1.4.0 github.com/IBM/go-sdk-core/v5 v5.21.2 github.com/IBM/ibm-backup-recovery-sdk-go v1.2.1 diff --git a/go.sum b/go.sum index 79e48154e14..d82134ff9c5 100644 --- a/go.sum +++ b/go.sum @@ -115,10 +115,10 @@ github.com/IBM/container-registry-go-sdk v1.2.0 h1:DX08GSKFvgCcUne9rWwb9+UttevV4 github.com/IBM/container-registry-go-sdk v1.2.0/go.mod h1:fE1iNfehccXBx1wmX/RUWksDteWOOOXJFtHWYlT4zKk= github.com/IBM/continuous-delivery-go-sdk/v2 v2.0.6 h1:CdJWGVzcHngf6un5N2C4KDgIzqViA2Md6pSeZNZzsLQ= github.com/IBM/continuous-delivery-go-sdk/v2 v2.0.6/go.mod h1:Iibf+4gRasEZHakDgnMm7TOX87xex0L+DfghUclcmcg= +github.com/IBM/event-notifications-go-admin-sdk v0.22.0 h1:NiSIgwPAKRiXG27PhE7cp9tlMFNUb4k9QpD5BQBAR0M= +github.com/IBM/event-notifications-go-admin-sdk v0.22.0/go.mod h1:65iLw7V18Kc5duGXJYsUNTZd3doJHLIzYl9I9Fsoz+Y= github.com/IBM/dra-go-sdk v0.0.0-20251210070042-5072d22c26d0 h1:XMWoX+WicTwmve5Rn2Gmt3W/7KRA7nxq9cT0Dr8mQRk= github.com/IBM/dra-go-sdk v0.0.0-20251210070042-5072d22c26d0/go.mod h1:K7r7KEU0eceUdhgj5B4PpLY7XJp9Wj6k88kptv1Rmp0= -github.com/IBM/event-notifications-go-admin-sdk v0.21.0 h1:WqKRm0mQoDKb6VlFrF2Ksz3SEizM1MGxx/HSF3In1ns= -github.com/IBM/event-notifications-go-admin-sdk v0.21.0/go.mod h1:9fG6k1gYRqiChZvmn1iRIjaKCXuDBCOlPH6xPJN+mMU= 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/v5 v5.0.0/go.mod h1:vyNdbFujJtdTj9HbihtvKwwS3k/GKSKpOx9ZIQ6MWDY= diff --git a/ibm/provider/provider.go b/ibm/provider/provider.go index 7ce86549675..0c132a64e5b 100644 --- a/ibm/provider/provider.go +++ b/ibm/provider/provider.go @@ -1072,6 +1072,7 @@ func Provider() *schema.Provider { "ibm_en_destination_app_configuration": eventnotification.DataSourceIBMEnAppConfigurationDestination(), "ibm_en_subscription_app_configuration": eventnotification.DataSourceIBMEnAppConfigurationSubscription(), "ibm_en_app_configuration_template": eventnotification.DataSourceIBMEnAppConfigurationTemplate(), + "ibm_en_bounce_metrics": eventnotification.DataSourceIBMEnBounceMetrics(), // Added for Toolchain "ibm_cd_toolchain": cdtoolchain.DataSourceIBMCdToolchain(), diff --git a/ibm/service/eventnotification/data_source_ibm_en_bounce_metrics.go b/ibm/service/eventnotification/data_source_ibm_en_bounce_metrics.go new file mode 100644 index 00000000000..bcd5a5b3e96 --- /dev/null +++ b/ibm/service/eventnotification/data_source_ibm_en_bounce_metrics.go @@ -0,0 +1,207 @@ +// Copyright IBM Corp. 2024 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +package eventnotification + +import ( + "context" + "fmt" + "log" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.com/IBM/event-notifications-go-admin-sdk/eventnotificationsv1" +) + +func DataSourceIBMEnBounceMetrics() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceIBMEnBounceMetricsRead, + + Schema: map[string]*schema.Schema{ + "instance_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "Unique identifier for IBM Cloud Event Notifications instance.", + }, + "destination_type": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "Destination type. Allowed values are [smtp_custom].", + }, + "gte": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "GTE (greater than equal), start timestamp in UTC.", + }, + "lte": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "LTE (less than equal), end timestamp in UTC.", + }, + "destination_id": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "Unique identifier for Destination.", + }, + "subscription_id": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "Unique identifier for Subscription.", + }, + "source_id": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "Unique identifier for Source.", + }, + "email_to": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "Receiver email id.", + }, + "notification_id": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "Notification Id.", + }, + "subject": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "Email subject.", + }, + "metrics": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "array of bounce metrics.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "email_address": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Email address.", + }, + "subject": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Subject.", + }, + "error_message": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Error message.", + }, + "ip_address": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "IP address.", + }, + "subscription_id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Subscription ID.", + }, + "timestamp": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Bounced at.", + }, + }, + }, + }, + "total_count": &schema.Schema{ + Type: schema.TypeInt, + Computed: true, + Description: "total number of bounce metrics.", + }, + }, + } +} + +func dataSourceIBMEnBounceMetricsRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + eventNotificationsClient, err := meta.(conns.ClientSession).EventNotificationsApiV1() + if err != nil { + tfErr := flex.TerraformErrorf(err, err.Error(), "(Data) ibm_en_bounce_metrics", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + getBounceMetricsOptions := &eventnotificationsv1.GetBounceMetricsOptions{} + + getBounceMetricsOptions.SetInstanceID(d.Get("instance_id").(string)) + getBounceMetricsOptions.SetDestinationType(d.Get("destination_type").(string)) + getBounceMetricsOptions.SetGte(d.Get("gte").(string)) + getBounceMetricsOptions.SetLte(d.Get("lte").(string)) + if _, ok := d.GetOk("destination_id"); ok { + getBounceMetricsOptions.SetDestinationID(d.Get("destination_id").(string)) + } + if _, ok := d.GetOk("subscription_id"); ok { + getBounceMetricsOptions.SetSubscriptionID(d.Get("subscription_id").(string)) + } + if _, ok := d.GetOk("source_id"); ok { + getBounceMetricsOptions.SetSourceID(d.Get("source_id").(string)) + } + if _, ok := d.GetOk("email_to"); ok { + getBounceMetricsOptions.SetEmailTo(d.Get("email_to").(string)) + } + if _, ok := d.GetOk("notification_id"); ok { + getBounceMetricsOptions.SetNotificationID(d.Get("notification_id").(string)) + } + if _, ok := d.GetOk("subject"); ok { + getBounceMetricsOptions.SetSubject(d.Get("subject").(string)) + } + + bounceMetrics, _, err := eventNotificationsClient.GetBounceMetricsWithContext(context, getBounceMetricsOptions) + if err != nil { + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetBounceMetricsWithContext failed: %s", err.Error()), "(Data) ibm_en_bounce_metrics", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + d.SetId(dataSourceIBMEnBounceMetricsID(d)) + + metrics := []map[string]interface{}{} + if bounceMetrics.Metrics != nil { + for _, modelItem := range bounceMetrics.Metrics { + modelMap, err := dataSourceIBMEnBounceMetricsBounceMetricItemToMap(&modelItem) + if err != nil { + tfErr := flex.TerraformErrorf(err, err.Error(), "(Data) ibm_en_bounce_metrics", "read") + return tfErr.GetDiag() + } + metrics = append(metrics, modelMap) + } + } + if err = d.Set("metrics", metrics); err != nil { + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting metrics: %s", err), "(Data) ibm_en_bounce_metrics", "read") + return tfErr.GetDiag() + } + + if err = d.Set("total_count", flex.IntValue(bounceMetrics.TotalCount)); err != nil { + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error setting total_count: %s", err), "(Data) ibm_en_bounce_metrics", "read") + return tfErr.GetDiag() + } + + return nil +} + +// dataSourceIBMEnBounceMetricsID returns a reasonable ID for the list. +func dataSourceIBMEnBounceMetricsID(d *schema.ResourceData) string { + return time.Now().UTC().String() +} + +func dataSourceIBMEnBounceMetricsBounceMetricItemToMap(model *eventnotificationsv1.BounceMetricItem) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["email_address"] = model.EmailAddress + modelMap["subject"] = model.Subject + modelMap["error_message"] = model.ErrorMessage + if model.IPAddress != nil { + modelMap["ip_address"] = model.IPAddress + } + if model.SubscriptionID != nil { + modelMap["subscription_id"] = model.SubscriptionID + } + modelMap["timestamp"] = model.Timestamp.String() + return modelMap, nil +} diff --git a/ibm/service/eventnotification/data_source_ibm_en_bounce_metrics_test.go b/ibm/service/eventnotification/data_source_ibm_en_bounce_metrics_test.go new file mode 100644 index 00000000000..23ad97954a4 --- /dev/null +++ b/ibm/service/eventnotification/data_source_ibm_en_bounce_metrics_test.go @@ -0,0 +1,51 @@ +// Copyright IBM Corp. 2024 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +package eventnotification_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" +) + +func TestAccIBMEnBounceMetricsDataSourceBasic(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckIBMEnBounceMetricsDataSourceConfigBasic(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.ibm_en_bounce_metrics.en_bounce_metrics_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_en_bounce_metrics.en_bounce_metrics_instance", "instance_id"), + resource.TestCheckResourceAttrSet("data.ibm_en_bounce_metrics.en_bounce_metrics_instance", "destination_type"), + resource.TestCheckResourceAttrSet("data.ibm_en_bounce_metrics.en_bounce_metrics_instance", "gte"), + resource.TestCheckResourceAttrSet("data.ibm_en_bounce_metrics.en_bounce_metrics_instance", "lte"), + resource.TestCheckResourceAttrSet("data.ibm_en_bounce_metrics.en_bounce_metrics_instance", "metrics.#"), + resource.TestCheckResourceAttrSet("data.ibm_en_bounce_metrics.en_bounce_metrics_instance", "total_count"), + ), + }, + }, + }) +} + +func testAccCheckIBMEnBounceMetricsDataSourceConfigBasic() string { + return fmt.Sprintf(` + data "ibm_en_bounce_metrics" "en_bounce_metrics_instance" { + instance_id = "instance_id" + destination_type = "smtp_custom" + gte = "gte" + lte = "lte" + destination_id = "destination_id" + subscription_id = "subscription_id" + source_id = "source_id" + email_to = "email_to" + notification_id = "notification_id" + subject = "subject" + } + `) +} diff --git a/ibm/service/eventnotification/data_source_ibm_en_metrics.go b/ibm/service/eventnotification/data_source_ibm_en_metrics.go index 87b639fbae8..0ba75af9359 100644 --- a/ibm/service/eventnotification/data_source_ibm_en_metrics.go +++ b/ibm/service/eventnotification/data_source_ibm_en_metrics.go @@ -47,6 +47,11 @@ func DataSourceIBMEnMetrics() *schema.Resource { Optional: true, Description: "Unique identifier for Destination.", }, + "subscription_id": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "Unique identifier for Subscription.", + }, "source_id": &schema.Schema{ Type: schema.TypeString, Optional: true, @@ -135,6 +140,9 @@ func dataSourceIBMEnMetricsRead(context context.Context, d *schema.ResourceData, if _, ok := d.GetOk("destination_id"); ok { getMetricsOptions.SetDestinationID(d.Get("destination_id").(string)) } + if _, ok := d.GetOk("subscription_id"); ok { + getMetricsOptions.SetSubscriptionID(d.Get("subscription_id").(string)) + } if _, ok := d.GetOk("source_id"); ok { getMetricsOptions.SetSourceID(d.Get("source_id").(string)) } diff --git a/ibm/service/eventnotification/resource_ibm_en_integration.go b/ibm/service/eventnotification/resource_ibm_en_integration.go index 97c60141b13..631845cb9e8 100644 --- a/ibm/service/eventnotification/resource_ibm_en_integration.go +++ b/ibm/service/eventnotification/resource_ibm_en_integration.go @@ -42,6 +42,7 @@ func ResourceIBMEnIntegration() *schema.Resource { Type: schema.TypeString, Required: true, Description: "The type of key integration kms/hs-crypto.", + Deprecated: "The type hs-crypto is deprecated now. No new integration resources with hs-crypto type will be supported", }, "metadata": { Type: schema.TypeList, diff --git a/website/docs/d/en_bounce_metrics.html.markdown b/website/docs/d/en_bounce_metrics.html.markdown new file mode 100644 index 00000000000..25279a406d0 --- /dev/null +++ b/website/docs/d/en_bounce_metrics.html.markdown @@ -0,0 +1,55 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_en_bounce_metrics" +description: |- + Get information about en_bounce_metrics +subcategory: "Event Notifications" +--- + +# ibm_en_bounce_metrics + +Provides a read-only data source to retrieve information about en_bounce_metrics. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. + +## Example Usage + +```hcl +data "ibm_en_bounce_metrics" "en_bounce_metrics" { + destination_type = "smtp_custom" + gte = "gte" + instance_id = "instance_id" + lte = "lte" +} +``` + +## Argument Reference + +You can specify the following arguments for this data source. + +* `destination_id` - (Optional, String) Unique identifier for Destination. +* `destination_type` - (Required, String) Destination type. Allowed values are [smtp_custom]. +* `email_to` - (Optional, String) Receiver email id. +* `gte` - (Required, String) GTE (greater than equal), start timestamp in UTC. +* `instance_id` - (Required, Forces new resource, String) Unique identifier for IBM Cloud Event Notifications instance. +* `lte` - (Required, String) LTE (less than equal), end timestamp in UTC. +* `notification_id` - (Optional, String) Notification Id. +* `source_id` - (Optional, String) Unique identifier for Source. +* `subject` - (Optional, String) Email subject. +* `subscription_id` - (Optional, String) Unique identifier for Subscription. + +## Attribute Reference + +After your data source is created, you can read values from the following attributes. + +* `id` - The unique identifier of the en_bounce_metrics. +* `metrics` - (List) array of bounce metrics. + * Constraints: The maximum length is `100` items. The minimum length is `0` items. +Nested schema for **metrics**: + * `email_address` - (String) Email address. + * `error_message` - (String) Error message. + * `ip_address` - (String) IP address. + * `subject` - (String) Subject. + * `subscription_id` - (String) Subscription ID. + * `timestamp` - (String) Bounced at. +* `total_count` - (Integer) total number of bounce metrics. + * Constraints: The minimum value is `0`. + diff --git a/website/docs/d/en_webhook_destination.html.markdown b/website/docs/d/en_webhook_destination.html.markdown deleted file mode 100644 index d04a8fe4313..00000000000 --- a/website/docs/d/en_webhook_destination.html.markdown +++ /dev/null @@ -1,57 +0,0 @@ ---- -subcategory: 'Event Notifications' -layout: 'ibm' -page_title: 'IBM : ibm_en_destination_webhook' -description: |- - Get information about a webhook destination ---- - -# ibm_en_destination_webhook - -Provides a read-only data source for Webhook destination. You can then reference the fields of the data source in other resources within the same configuration using interpolation syntax. - -## Example usage - -```terraform -data "ibm_en_destination_webhook" "webhook_en_destination" { - instance_guid = ibm_resource_instance.en_terraform_test_resource.guid - destination_id = ibm_en_destination_webhook.destination1.destination_id -} -``` - -## Argument reference - -Review the argument reference that you can specify for your data source. - -- `instance_guid` - (Required, Forces new resource, String) Unique identifier for IBM Cloud Event Notifications instance. - -- `destination_id` - (Required, String) Unique identifier for Destination. - -## Attribute reference - -In addition to all argument references listed, you can access the following attribute references after your data source is created. - -- `id` - The unique identifier of the `webhook_en_destination`. - -- `name` - (String) Destination name. - -- `description` - (String) Destination description. - -- `subscription_count` - (Integer) Number of subscriptions. - -- `subscription_names` - (List) List of subscriptions. - -- `type` - (String) Destination type Webhook. - -- `config` - (List) Payload describing a destination configuration. - Nested scheme for **config**: - - - `params` - (List) - - Nested scheme for **params**: - - - `url` - (String) URL of webhook. - - - `verb` - (String) HTTP method of webhook. Allowable values are: `get`, `post`. - -- `updated_at` - (String) Last updated time. diff --git a/website/docs/r/en_source.html.markdown b/website/docs/r/en_source.html.markdown index 5f481468833..2c67f246cf3 100644 --- a/website/docs/r/en_source.html.markdown +++ b/website/docs/r/en_source.html.markdown @@ -8,7 +8,7 @@ description: |- # ibm_en_source -Create, update, or delete a source by using IBM Cloud™ Event Notifications. +Create, update, or delete a API source by using IBM Cloud™ Event Notifications. ## Example usage @@ -21,6 +21,14 @@ resource "ibm_en_source" "en_source" { } ``` +Note: The IBM Cloud sources, IBM Cloud Platform sources, and the Periodic Timer source documented in the IBM Cloud Event Notifications/Event Streams documentation cannot be created or managed as Terraform resources. +Instead, they are read‑only in Terraform and can be accessed only via data sources, not via resource blocks. + +This means: + - You cannot use Terraform to create, update, or delete these sources. + - You can only import and reference the existing sources using Terraform data blocks. + + ## Argument reference Review the argument reference that you can specify for your resource.