diff --git a/go.mod b/go.mod index 345b4c243b..6de6c0fc47 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/IBM/code-engine-go-sdk v0.0.0-20230324212854-743a707334f6 github.com/IBM/container-registry-go-sdk v0.0.15 github.com/IBM/continuous-delivery-go-sdk v1.1.0 - github.com/IBM/event-notifications-go-admin-sdk v0.2.1 + github.com/IBM/event-notifications-go-admin-sdk v0.2.2 github.com/IBM/eventstreams-go-sdk v1.2.0 github.com/IBM/go-sdk-core/v5 v5.13.1 github.com/IBM/ibm-cos-sdk-go v1.10.0 @@ -178,3 +178,5 @@ require ( replace github.com/softlayer/softlayer-go v1.0.3 => github.com/IBM-Cloud/softlayer-go v1.0.5-tf replace github.com/dgrijalva/jwt-go v3.2.0+incompatible => github.com/golang-jwt/jwt v3.2.1+incompatible + +replace github.com/IBM/secrets-manager-go-sdk v1.0.49 => github.com/IBM/secrets-manager-go-sdk v1.0.50-0.20230316070833-1e1d44fe67be diff --git a/go.sum b/go.sum index c3ed966a7f..96ef434a61 100644 --- a/go.sum +++ b/go.sum @@ -59,8 +59,8 @@ github.com/IBM/container-registry-go-sdk v0.0.15 h1:sfEXm4qNj9ZCwTlFOsdjF5P/lvaj github.com/IBM/container-registry-go-sdk v0.0.15/go.mod h1:KqSZFO4VIK9QAyF8O1JW6jkyzkfE/BNKUIo+OdzIDk4= github.com/IBM/continuous-delivery-go-sdk v1.1.0 h1:E0hPM4H7Bmn31+4UAMavBngRjTMoqbjkBb4AlIgi0tA= github.com/IBM/continuous-delivery-go-sdk v1.1.0/go.mod h1:JUHFfLCLDMtEQhfDvxBT79O2OcBmSV+is9bKRdnUF1o= -github.com/IBM/event-notifications-go-admin-sdk v0.2.1 h1:MXqf+NTX42jT40EuIKxZ0s0Xt6Ebgi0qmhckBNzEMXc= -github.com/IBM/event-notifications-go-admin-sdk v0.2.1/go.mod h1:1TlGAFP47DybbovJfHtYYgSI8xpLL8Q0wao6vsAlb6c= +github.com/IBM/event-notifications-go-admin-sdk v0.2.2 h1:Aww+OUcKgsbXyY7a/nlMH7nvZGn0sBTr6p6rUjOyy1Y= +github.com/IBM/event-notifications-go-admin-sdk v0.2.2/go.mod h1:1TlGAFP47DybbovJfHtYYgSI8xpLL8Q0wao6vsAlb6c= github.com/IBM/eventstreams-go-sdk v1.2.0 h1:eP0afHArMGjwhGqvZAhhu/3EDKRch2JehpveqF1TUjs= github.com/IBM/eventstreams-go-sdk v1.2.0/go.mod h1:2tuAxaYLctfqfr5jvyqSrxxEQGMwYPm3yJGWSj85YVQ= github.com/IBM/go-sdk-core/v3 v3.0.0/go.mod h1:JI5NS2+iCoY/D8Oq3JNEZNA7qO42agu6fnaUmDsRcJA= diff --git a/ibm/provider/provider.go b/ibm/provider/provider.go index 2bed4a5893..31357568ec 100644 --- a/ibm/provider/provider.go +++ b/ibm/provider/provider.go @@ -758,6 +758,8 @@ func Provider() *schema.Provider { "ibm_en_subscription_sn": eventnotification.DataSourceIBMEnFCMSubscription(), "ibm_en_destination_ce": eventnotification.DataSourceIBMEnCodeEngineDestination(), "ibm_en_subscription_ce": eventnotification.DataSourceIBMEnFCMSubscription(), + "ibm_en_destination_cos": eventnotification.DataSourceIBMEnCOSDestination(), + "ibm_en_subscription_cos": eventnotification.DataSourceIBMEnFCMSubscription(), // // Added for Toolchain "ibm_cd_toolchain": cdtoolchain.DataSourceIBMCdToolchain(), @@ -1222,6 +1224,8 @@ func Provider() *schema.Provider { "ibm_en_subscription_sn": eventnotification.ResourceIBMEnFCMSubscription(), "ibm_en_destination_ce": eventnotification.ResourceIBMEnCodeEngineDestination(), "ibm_en_subscription_ce": eventnotification.ResourceIBMEnFCMSubscription(), + "ibm_en_destination_cos": eventnotification.ResourceIBMEnCOSDestination(), + "ibm_en_subscription_cos": eventnotification.ResourceIBMEnFCMSubscription(), // // Added for Toolchain "ibm_cd_toolchain": cdtoolchain.ResourceIBMCdToolchain(), diff --git a/ibm/service/eventnotification/data_source_ibm_en_destination_cos.go b/ibm/service/eventnotification/data_source_ibm_en_destination_cos.go new file mode 100644 index 0000000000..927bb7e089 --- /dev/null +++ b/ibm/service/eventnotification/data_source_ibm_en_destination_cos.go @@ -0,0 +1,197 @@ +// Copyright IBM Corp. 2021 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +package eventnotification + +import ( + "context" + "fmt" + + "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" + + en "github.com/IBM/event-notifications-go-admin-sdk/eventnotificationsv1" +) + +func DataSourceIBMEnCOSDestination() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceIBMEnCOSDestinationRead, + + Schema: map[string]*schema.Schema{ + "instance_guid": { + Type: schema.TypeString, + Required: true, + Description: "Unique identifier for IBM Cloud Event Notifications instance.", + }, + "destination_id": { + Type: schema.TypeString, + Required: true, + Description: "Unique identifier for Destination.", + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: "Destination name.", + }, + "description": { + Type: schema.TypeString, + Computed: true, + Description: "Destination description.", + }, + "type": { + Type: schema.TypeString, + Computed: true, + Description: "Destination type ibmcf.", + }, + "config": { + Type: schema.TypeList, + Computed: true, + Description: "Payload describing a destination configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "params": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "bucket_name": { + Type: schema.TypeString, + Required: true, + Description: "The COS bucket name", + }, + "instance_id": { + Type: schema.TypeString, + Required: true, + Description: "The instance id for COS instance", + }, + "endpoint": { + Type: schema.TypeString, + Required: true, + Description: "The endpoint for the COS bucket endpoint", + }, + }, + }, + }, + }, + }, + }, + "updated_at": { + Type: schema.TypeString, + Computed: true, + Description: "Last updated time.", + }, + "subscription_count": { + Type: schema.TypeInt, + Computed: true, + Description: "Number of subscriptions.", + }, + "subscription_names": { + Type: schema.TypeList, + Computed: true, + Description: "List of subscriptions.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + } +} + +func dataSourceIBMEnCOSDestinationRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + enClient, err := meta.(conns.ClientSession).EventNotificationsApiV1() + if err != nil { + return diag.FromErr(err) + } + + options := &en.GetDestinationOptions{} + + options.SetInstanceID(d.Get("instance_guid").(string)) + options.SetID(d.Get("destination_id").(string)) + + result, response, err := enClient.GetDestinationWithContext(context, options) + if err != nil { + return diag.FromErr(fmt.Errorf("GetDestination failed %s\n%s", err, response)) + } + + 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)) + } + + if result.Description != nil { + if err = d.Set("description", result.Description); err != nil { + return diag.FromErr(fmt.Errorf("[ERROR] Error setting description: %s", err)) + } + } + + if err = d.Set("type", result.Type); err != nil { + return diag.FromErr(fmt.Errorf("[ERROR] Error setting type: %s", err)) + } + + if result.Config != nil { + err = d.Set("config", enCOSDestinationFlattenConfig(*result.Config)) + if err != nil { + return diag.FromErr(fmt.Errorf("[ERROR] Error setting config %s", err)) + } + } + + 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)) + } + } + + if err = d.Set("updated_at", flex.DateTimeToString(result.UpdatedAt)); err != nil { + return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_at: %s", err)) + } + + if err = d.Set("subscription_count", flex.IntValue(result.SubscriptionCount)); err != nil { + return diag.FromErr(fmt.Errorf("[ERROR] Error setting subscription_count: %s", err)) + } + + return nil +} + +func enCOSDestinationFlattenConfig(result en.DestinationConfig) (finalList []map[string]interface{}) { + finalList = []map[string]interface{}{} + finalMap := enCOSDestinationConfigToMap(result) + finalList = append(finalList, finalMap) + + return finalList +} + +func enCOSDestinationConfigToMap(configItem en.DestinationConfig) (configMap map[string]interface{}) { + configMap = map[string]interface{}{} + + if configItem.Params != nil { + paramsList := []map[string]interface{}{} + paramsMap := enCOSDestinationConfigParamsToMap(configItem.Params) + paramsList = append(paramsList, paramsMap) + configMap["params"] = paramsList + } + + return configMap +} + +func enCOSDestinationConfigParamsToMap(paramsItem en.DestinationConfigOneOfIntf) (paramsMap map[string]interface{}) { + paramsMap = map[string]interface{}{} + + params := paramsItem.(*en.DestinationConfigOneOf) + + if params.BucketName != nil { + paramsMap["bucket_name"] = params.BucketName + } + + if params.InstanceID != nil { + paramsMap["instance_id"] = params.InstanceID + } + + if params.Endpoint != nil { + paramsMap["endpoint"] = params.Endpoint + } + return paramsMap +} diff --git a/ibm/service/eventnotification/data_source_ibm_en_destination_cos_test.go b/ibm/service/eventnotification/data_source_ibm_en_destination_cos_test.go new file mode 100644 index 0000000000..ef8ef5c5e9 --- /dev/null +++ b/ibm/service/eventnotification/data_source_ibm_en_destination_cos_test.go @@ -0,0 +1,69 @@ +// Copyright IBM Corp. 2021 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +package eventnotification_test + +import ( + "fmt" + "testing" + + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccIBMEnCOSDestinationDataSourceBasic(t *testing.T) { + name := fmt.Sprintf("tf_name_%d", acctest.RandIntRange(10, 100)) + instanceName := fmt.Sprintf("tf_name_%d", acctest.RandIntRange(10, 100)) + description := fmt.Sprintf("tf_description_%d", acctest.RandIntRange(10, 100)) + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCheckIBMEnCOSDestinationDataSourceConfigBasic(instanceName, name, description), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.ibm_en_destination_cos.en_destination_data_6", "id"), + resource.TestCheckResourceAttrSet("data.ibm_en_destination_cos.en_destination_data_6", "instance_guid"), + resource.TestCheckResourceAttrSet("data.ibm_en_destination_cos.en_destination_data_6", "name"), + resource.TestCheckResourceAttrSet("data.ibm_en_destination_cos.en_destination_data_6", "description"), + resource.TestCheckResourceAttrSet("data.ibm_en_destination_cos.en_destination_data_6", "type"), + resource.TestCheckResourceAttrSet("data.ibm_en_destination_cos.en_destination_data_6", "updated_at"), + resource.TestCheckResourceAttrSet("data.ibm_en_destination_cos.en_destination_data_6", "destination_id"), + resource.TestCheckResourceAttrSet("data.ibm_en_destination_cos.en_destination_data_6", "subscription_count"), + ), + }, + }, + }) +} + +func testAccCheckIBMEnCOSDestinationDataSourceConfigBasic(instanceName, name, description string) string { + return fmt.Sprintf(` + resource "ibm_resource_instance" "en_destination_datasource2" { + name = "%s" + location = "us-south" + plan = "standard" + service = "event-notifications" + } + + resource "ibm_en_destination_cos" "en_destination_datasource_4" { + instance_guid = ibm_resource_instance.en_destination_resource.guid + name = "%s" + type = "ibmcos" + description = "%s" + config { + params { + bucket_name = "cos-destination-en-bucket" + instance_id = "42e13636e-0548-41a0-a178-e95be28464773" + endpoint = "https://s3.us-west.cloud-object-storage.test.appdomain.cloud" + } + } + } + + data "ibm_en_destination_cos" "en_destination_data_6" { + instance_guid = ibm_resource_instance.en_destination_datasource2.guid + destination_id = ibm_en_destination_cos.en_destination_datasource_4.destination_id + } + `, instanceName, name, description) +} diff --git a/ibm/service/eventnotification/resource_ibm_en_destination_cos.go b/ibm/service/eventnotification/resource_ibm_en_destination_cos.go new file mode 100644 index 0000000000..1551798664 --- /dev/null +++ b/ibm/service/eventnotification/resource_ibm_en_destination_cos.go @@ -0,0 +1,292 @@ +// Copyright IBM Corp. 2021 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +package eventnotification + +import ( + "context" + "fmt" + + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.com/IBM/go-sdk-core/v5/core" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + en "github.com/IBM/event-notifications-go-admin-sdk/eventnotificationsv1" +) + +func ResourceIBMEnCOSDestination() *schema.Resource { + return &schema.Resource{ + CreateContext: resourceIBMEnCOSDestinationCreate, + ReadContext: resourceIBMEnCOSDestinationRead, + UpdateContext: resourceIBMEnCOSDestinationUpdate, + DeleteContext: resourceIBMEnCOSDestinationDelete, + Importer: &schema.ResourceImporter{}, + + Schema: map[string]*schema.Schema{ + "instance_guid": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Unique identifier for IBM Cloud Event Notifications instance.", + }, + "name": { + Type: schema.TypeString, + Required: true, + Description: "The Destintion name.", + }, + "type": { + Type: schema.TypeString, + Required: true, + Description: "The type of Destination Webhook.", + }, + "description": { + Type: schema.TypeString, + Optional: true, + Description: "The Destination description.", + }, + "config": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Description: "Payload describing a destination configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "params": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "bucket_name": { + Type: schema.TypeString, + Required: true, + Description: "The COS bucket name", + }, + "instance_id": { + Type: schema.TypeString, + Required: true, + Description: "The instance id for COS instance", + }, + "endpoint": { + Type: schema.TypeString, + Optional: true, + Description: "The endpoint for the COS bucket endpoint", + }, + }, + }, + }, + }, + }, + }, + "destination_id": { + Type: schema.TypeString, + Computed: true, + Description: "Destination ID", + }, + "updated_at": { + Type: schema.TypeString, + Computed: true, + Description: "Last updated time.", + }, + "subscription_count": { + Type: schema.TypeInt, + Computed: true, + Description: "Number of subscriptions.", + }, + "subscription_names": { + Type: schema.TypeList, + Computed: true, + Description: "List of subscriptions.", + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + } +} + +func resourceIBMEnCOSDestinationCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + enClient, err := meta.(conns.ClientSession).EventNotificationsApiV1() + if err != nil { + return diag.FromErr(err) + } + + options := &en.CreateDestinationOptions{} + + options.SetInstanceID(d.Get("instance_guid").(string)) + options.SetName(d.Get("name").(string)) + options.SetType(d.Get("type").(string)) + + destinationtype := d.Get("type").(string) + if _, ok := d.GetOk("description"); ok { + options.SetDescription(d.Get("description").(string)) + } + if _, ok := d.GetOk("config"); ok { + config := COSdestinationConfigMapToDestinationConfig(d.Get("config.0.params.0").(map[string]interface{}), destinationtype) + options.SetConfig(&config) + } + + result, response, err := enClient.CreateDestinationWithContext(context, options) + if err != nil { + return diag.FromErr(fmt.Errorf("CreateDestinationWithContext failed %s\n%s", err, response)) + } + + d.SetId(fmt.Sprintf("%s/%s", *options.InstanceID, *result.ID)) + + return resourceIBMEnCOSDestinationRead(context, d, meta) +} + +func resourceIBMEnCOSDestinationRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + enClient, err := meta.(conns.ClientSession).EventNotificationsApiV1() + if err != nil { + return diag.FromErr(err) + } + + options := &en.GetDestinationOptions{} + + parts, err := flex.SepIdParts(d.Id(), "/") + if err != nil { + return diag.FromErr(err) + } + + options.SetInstanceID(parts[0]) + options.SetID(parts[1]) + + result, response, err := enClient.GetDestinationWithContext(context, options) + if err != nil { + if response != nil && response.StatusCode == 404 { + d.SetId("") + return nil + } + return diag.FromErr(fmt.Errorf("GetDestinationWithContext failed %s\n%s", err, response)) + } + + if err = d.Set("instance_guid", options.InstanceID); err != nil { + return diag.FromErr(fmt.Errorf("[ERROR] Error setting instance_guid: %s", err)) + } + + if err = d.Set("destination_id", options.ID); err != nil { + return diag.FromErr(fmt.Errorf("[ERROR] Error setting destination_id: %s", err)) + } + + if err = d.Set("name", result.Name); err != nil { + return diag.FromErr(fmt.Errorf("[ERROR] Error setting name: %s", err)) + } + + if err = d.Set("type", result.Type); err != nil { + return diag.FromErr(fmt.Errorf("[ERROR] Error setting type: %s", err)) + } + + if err = d.Set("description", result.Description); err != nil { + return diag.FromErr(fmt.Errorf("[ERROR] Error setting description: %s", err)) + } + + if result.Config != nil { + err = d.Set("config", enCOSDestinationFlattenConfig(*result.Config)) + if err != nil { + return diag.FromErr(fmt.Errorf("[ERROR] Error setting config %s", err)) + } + } + + if err = d.Set("updated_at", flex.DateTimeToString(result.UpdatedAt)); err != nil { + return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_at: %s", err)) + } + + if err = d.Set("subscription_count", flex.IntValue(result.SubscriptionCount)); err != nil { + return diag.FromErr(fmt.Errorf("[ERROR] Error setting subscription_count: %s", err)) + } + + if err = d.Set("subscription_names", result.SubscriptionNames); err != nil { + return diag.FromErr(fmt.Errorf("[ERROR] Error setting subscription_names: %s", err)) + + } + + return nil +} + +func resourceIBMEnCOSDestinationUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + enClient, err := meta.(conns.ClientSession).EventNotificationsApiV1() + if err != nil { + return diag.FromErr(err) + } + + options := &en.UpdateDestinationOptions{} + + parts, err := flex.SepIdParts(d.Id(), "/") + if err != nil { + return diag.FromErr(err) + } + + options.SetInstanceID(parts[0]) + options.SetID(parts[1]) + + if ok := d.HasChanges("name", "description", "config"); ok { + options.SetName(d.Get("name").(string)) + + if _, ok := d.GetOk("description"); ok { + options.SetDescription(d.Get("description").(string)) + } + destinationtype := d.Get("type").(string) + if _, ok := d.GetOk("config"); ok { + config := COSdestinationConfigMapToDestinationConfig(d.Get("config.0.params.0").(map[string]interface{}), destinationtype) + options.SetConfig(&config) + } + _, response, err := enClient.UpdateDestinationWithContext(context, options) + if err != nil { + return diag.FromErr(fmt.Errorf("UpdateDestinationWithContext failed %s\n%s", err, response)) + } + + return resourceIBMEnCOSDestinationRead(context, d, meta) + } + + return nil +} + +func resourceIBMEnCOSDestinationDelete(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + enClient, err := meta.(conns.ClientSession).EventNotificationsApiV1() + if err != nil { + return diag.FromErr(err) + } + + options := &en.DeleteDestinationOptions{} + + parts, err := flex.SepIdParts(d.Id(), "/") + if err != nil { + return diag.FromErr(err) + } + + options.SetInstanceID(parts[0]) + options.SetID(parts[1]) + + response, err := enClient.DeleteDestinationWithContext(context, options) + if err != nil { + if response != nil && response.StatusCode == 404 { + d.SetId("") + return nil + } + return diag.FromErr(fmt.Errorf("DeleteDestinationWithContext failed %s\n%s", err, response)) + } + + d.SetId("") + + return nil +} + +func COSdestinationConfigMapToDestinationConfig(configParams map[string]interface{}, destinationtype string) en.DestinationConfig { + params := new(en.DestinationConfigOneOf) + if configParams["bucket_name"] != nil { + params.BucketName = core.StringPtr(configParams["bucket_name"].(string)) + } + + if configParams["instance_id"] != nil { + params.InstanceID = core.StringPtr(configParams["instance_id"].(string)) + } + + if configParams["endpoint"] != nil { + params.Endpoint = core.StringPtr(configParams["endpoint"].(string)) + } + + destinationConfig := new(en.DestinationConfig) + destinationConfig.Params = params + return *destinationConfig +} diff --git a/ibm/service/eventnotification/resource_ibm_en_destination_cos_test.go b/ibm/service/eventnotification/resource_ibm_en_destination_cos_test.go new file mode 100644 index 0000000000..17295683f6 --- /dev/null +++ b/ibm/service/eventnotification/resource_ibm_en_destination_cos_test.go @@ -0,0 +1,149 @@ +// Copyright IBM Corp. 2021 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +package eventnotification_test + +import ( + "fmt" + "testing" + + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + "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/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + + en "github.com/IBM/event-notifications-go-admin-sdk/eventnotificationsv1" +) + +func TestAccIBMEnCOSDestinationAllArgs(t *testing.T) { + var config en.Destination + name := fmt.Sprintf("tf_name_%d", acctest.RandIntRange(10, 100)) + instanceName := fmt.Sprintf("tf_name_%d", acctest.RandIntRange(10, 100)) + description := fmt.Sprintf("tf_description_%d", acctest.RandIntRange(10, 100)) + newName := fmt.Sprintf("tf_name_%d", acctest.RandIntRange(10, 100)) + newDescription := fmt.Sprintf("tf_description_%d", acctest.RandIntRange(10, 100)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + CheckDestroy: testAccCheckIBMEnCOSDestinationDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCheckIBMEnCOSDestinationConfig(instanceName, name, description), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckIBMEnCOSDestinationExists("ibm_en_destination_cos.en_destination_resource_1", config), + resource.TestCheckResourceAttr("ibm_en_destination_cos.en_destination_resource_1", "name", name), + resource.TestCheckResourceAttr("ibm_en_destination_cos.en_destination_resource_1", "type", "ibmcos"), + resource.TestCheckResourceAttr("ibm_en_destination_cos.en_destination_resource_1", "description", description), + ), + }, + { + Config: testAccCheckIBMEnCOSDestinationConfig(instanceName, newName, newDescription), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("ibm_en_destination_cos.en_destination_resource_1", "name", newName), + resource.TestCheckResourceAttr("ibm_en_destination_cos.en_destination_resource_1", "type", "ibmcos"), + resource.TestCheckResourceAttr("ibm_en_destination_cos.en_destination_resource_1", "description", newDescription), + ), + }, + { + ResourceName: "ibm_en_destination_cos.en_destination_resource_1", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccCheckIBMEnCOSDestinationConfig(instanceName, name, description string) string { + return fmt.Sprintf(` + resource "ibm_resource_instance" "en_destination_resource" { + name = "%s" + location = "us-south" + plan = "standard" + service = "event-notifications" + } + + resource "ibm_en_destination_cos" "en_destination_resource_1" { + instance_guid = ibm_resource_instance.en_destination_resource.guid + name = "%s" + type = "ibmcos" + description = "%s" + config { + params { + bucket_name = "cos-destination-en-bucket" + instance_id = "42e13636e-0548-41a0-a178-e95be28464773" + endpoint = "https://s3.us-west.cloud-object-storage.test.appdomain.cloud" + } + } + } + `, instanceName, name, description) +} + +func testAccCheckIBMEnCOSDestinationExists(n string, obj en.Destination) resource.TestCheckFunc { + + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + enClient, err := acc.TestAccProvider.Meta().(conns.ClientSession).EventNotificationsApiV1() + if err != nil { + return err + } + + options := &en.GetDestinationOptions{} + + parts, err := flex.SepIdParts(rs.Primary.ID, "/") + if err != nil { + return err + } + + options.SetInstanceID(parts[0]) + options.SetID(parts[1]) + + result, _, err := enClient.GetDestination(options) + if err != nil { + return err + } + + obj = *result + return nil + } +} + +func testAccCheckIBMEnCOSDestinationDestroy(s *terraform.State) error { + enClient, err := acc.TestAccProvider.Meta().(conns.ClientSession).EventNotificationsApiV1() + if err != nil { + return err + } + for _, rs := range s.RootModule().Resources { + if rs.Type != "en_destination_resource_1" { + continue + } + + options := &en.GetDestinationOptions{} + + parts, err := flex.SepIdParts(rs.Primary.ID, "/") + if err != nil { + return err + } + + options.SetInstanceID(parts[0]) + options.SetID(parts[1]) + + // Try to find the key + _, response, err := enClient.GetDestination(options) + + if err == nil { + return fmt.Errorf("en_destination still exists: %s", rs.Primary.ID) + } else if response.StatusCode != 404 { + return fmt.Errorf("[ERROR] Error checking for en_destination (%s) has been destroyed: %s", rs.Primary.ID, err) + } + } + + return nil +} diff --git a/website/docs/d/en_destination_cf.html.markdown b/website/docs/d/en_destination_cf.html.markdown index 0f39868b84..cd8605864b 100644 --- a/website/docs/d/en_destination_cf.html.markdown +++ b/website/docs/d/en_destination_cf.html.markdown @@ -41,7 +41,7 @@ In addition to all argument references listed, you can access the following attr - `subscription_names` - (List) List of subscriptions. -- `type` - (String) Destination type push_chrome. +- `type` - (String) Destination type ibmcf. - `config` - (List) Payload describing a destination configuration. Nested scheme for **config**: diff --git a/website/docs/d/en_destination_cos.html.markdown b/website/docs/d/en_destination_cos.html.markdown new file mode 100644 index 0000000000..36974b7e75 --- /dev/null +++ b/website/docs/d/en_destination_cos.html.markdown @@ -0,0 +1,60 @@ +--- +subcategory: 'Event Notifications' +layout: 'ibm' +page_title: 'IBM : ibm_en_destination_cos' +description: |- + Get information about a IBM CLoud Object Storage destination +--- + +# ibm_en_destination_cos + +Provides a read-only data source for IBM Cloud Object Storage 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_cos" "cos_en_destination" { + instance_guid = ibm_resource_instance.en_terraform_test_resource.guid + destination_id = ibm_en_destination_cos.cos_destination.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 `cos_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 ibmcos. + +- `config` - (List) Payload describing a destination configuration. + Nested scheme for **config**: + + - `params` - (List) + + Nested scheme for **params**: + + - `bucket_name` - (Required, string) The bucket name in IBM cloud object storage instance. + + - `instance_id` - (Required, string) The instance id for IBM Cloud object storage instance. + + - `endpoint` - (Required, string) The endpoint for bucket region. + + +- `updated_at` - (String) Last updated time. diff --git a/website/docs/d/en_subscription_cos.html.markdown b/website/docs/d/en_subscription_cos.html.markdown new file mode 100644 index 0000000000..1e59275efc --- /dev/null +++ b/website/docs/d/en_subscription_cos.html.markdown @@ -0,0 +1,44 @@ +--- +subcategory: 'Event Notifications' +layout: 'ibm' +page_title: 'IBM : ibm_en_subscription_cos' +description: |- + Get information about a IBM Cloud Object Storage subscription +--- + +# ibm_en_subscription_cos + +Provides a read-only data source for subscription. 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_subscription_cos" "cos_subscription" { + instance_guid = ibm_resource_instance.en_terraform_test_resource.guid + subscription_id = ibm_en_subscription_cos.subscriptioncos.subscription_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. + +- `subscription_id` - (Required, String) Unique identifier for Subscription. + +## 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 fcm_subscription. + +- `name` - (String) Subscription name. + +- `description` - (String) Subscription description. + +- `destination_id` - (String) The destination ID. + +- `topic_id` - (String) Topic ID. + +- `updated_at` - (String) Last updated time. diff --git a/website/docs/r/en_destination_android.html.markdown b/website/docs/r/en_destination_android.html.markdown index f8ffe6c859..4c9867ef5a 100644 --- a/website/docs/r/en_destination_android.html.markdown +++ b/website/docs/r/en_destination_android.html.markdown @@ -3,7 +3,7 @@ subcategory: 'Event Notifications' layout: 'ibm' page_title: 'IBM : ibm_en_destination_android' description: |- - Manages Event Notifications destinations. + Manages Event Notifications Android destination. --- # ibm_en_destination_android diff --git a/website/docs/r/en_destination_ce.html.markdown b/website/docs/r/en_destination_ce.html.markdown index 6118a362ef..331d376662 100644 --- a/website/docs/r/en_destination_ce.html.markdown +++ b/website/docs/r/en_destination_ce.html.markdown @@ -16,6 +16,7 @@ Create, update, or delete a Code Engine destination by using IBM Cloud™ Event resource "ibm_en_destination_ce" "codeengine_en_destination" { instance_guid = ibm_resource_instance.en_terraform_test_resource.guid name = "Code engine Destination" + type = "ibmce" description = "Code Engine destination for event notification" config { params { diff --git a/website/docs/r/en_destination_chrome.html.markdown b/website/docs/r/en_destination_chrome.html.markdown index 7e4af4fd5f..6a678834e5 100644 --- a/website/docs/r/en_destination_chrome.html.markdown +++ b/website/docs/r/en_destination_chrome.html.markdown @@ -3,7 +3,7 @@ subcategory: 'Event Notifications' layout: 'ibm' page_title: 'IBM : ibm_en_destination_chrome' description: |- - Manages Event Notification Webhook destinations. + Manages Event Notification Chrome destinations. --- # ibm_en_destination_chrome diff --git a/website/docs/r/en_destination_cos.html.markdown b/website/docs/r/en_destination_cos.html.markdown new file mode 100644 index 0000000000..357474d94f --- /dev/null +++ b/website/docs/r/en_destination_cos.html.markdown @@ -0,0 +1,84 @@ +--- +subcategory: 'Event Notifications' +layout: 'ibm' +page_title: 'IBM : ibm_en_destination_cos' +description: |- + Manages Event Notification IBM Cloud Object Storage destinations. +--- + +# ibm_en_destination_cos + +Create, update, or delete a IBM Cloud Object Storage destination by using IBM Cloud™ Event Notifications. + +## Example usage + +```terraform +resource "ibm_en_destination_cos" "cos_en_destination" { + instance_guid = ibm_resource_instance.en_terraform_test_resource.guid + name = "COS Test Destination" + type = "ibmcos" + description = "IBM Cloud Object Storage Destination for event notification" + config { + params { + bucket_name = "cos-test-bucket" + instance_id = "1f7avhy78-3ehu-4d02-b123-8297333e0748399" + endpoint = "https://s3.us-east.cloud-object-storage.appdomain.cloud" + } + } +} +``` + +## Argument reference + +Review the argument reference that you can specify for your resource. + +- `instance_guid` - (Required, Forces new resource, String) Unique identifier for IBM Cloud Event Notifications instance. + +- `name` - (Required, String) The Destintion name. + +- `description` - (Optional, String) The Destination description. + +- `type` - (Required, String) ibmcos. + +- `config` - (Optional, List) Payload describing a destination configuration. + + Nested scheme for **config**: + + - `params` - (Required, List) + + Nested scheme for **params**: + + - `bucket_name` - (Required, string) The bucket name in IBM cloud object storage instance. + - `instance_id` - (Required, string) The instance id for IBM Cloud object storage instance. + - `endpoint` - (Required, string) The endpoint for bucket region. + +## Attribute reference + +In addition to all argument references listed, you can access the following attribute references after your resource is created. + +- `id` - (String) The unique identifier of the `cos_en_destination`. +- `destination_id` - (String) The unique identifier of the created destination. +- `subscription_count` - (Integer) Number of subscriptions. + - Constraints: The minimum value is `0`. +- `subscription_names` - (List) List of subscriptions. +- `updated_at` - (String) Last updated time. + +## Import + +You can import the `ibm_en_destination_cos` resource by using `id`. + +The `id` property can be formed from `instance_guid`, and `destination_id` in the following format: + +``` +/ +``` + +- `instance_guid`: A string. Unique identifier for IBM Cloud Event Notifications instance. + +- `destination_id`: A string. Unique identifier for Destination. + +**Example** + +``` +$ terraform import ibm_en_destination_cos.cos_en_destination / +``` diff --git a/website/docs/r/en_subscription_cos.html.markdown b/website/docs/r/en_subscription_cos.html.markdown new file mode 100644 index 0000000000..b40d6726eb --- /dev/null +++ b/website/docs/r/en_subscription_cos.html.markdown @@ -0,0 +1,66 @@ +--- +subcategory: 'Event Notifications' +layout: 'ibm' +page_title: 'IBM : ibm_en_subscription_cos' +description: |- + Manages Event Notifications IBM Cloud Object storage destination subscription. +--- + +# ibm_en_subscription_cos + +Create, update, or delete a COS subscription by using IBM Cloud™ Event Notifications. + +## Example usage + +```terraform +resource "ibm_en_subscription_cos" "cos_subscription" { + instance_guid = ibm_resource_instance.en_terraform_test_resource.guid + name = "IBM COS Subscription" + description = "IBM Cloud Object Storage destination subscription for Event Notification" + destination_id = ibm_en_destination_cos.cos_destination.destination_id + topic_id = ibm_en_topic.topic1.topic_id +} +``` + +## Argument reference + +Review the argument reference that you can specify for your resource. + +- `instance_guid` - (Required, Forces new resource, String) Unique identifier for IBM Cloud Event Notifications instance. + +- `name` - (Requires, String) Subscription name. + +- `description` - (Optional, String) Subscription description. + +- `destination_id` - (Requires, String) Destination ID. + +- `topic_id` - (Required, String) Topic ID. + + +## Attribute reference + +In addition to all argument references listed, you can access the following attribute references after your resource is created. + +- `id` - (String) The unique identifier of the `cos_subscription`. + +- `subscription_id` - (String) The unique identifier of the created subscription. + +- `updated_at` - (String) Last updated time. + +## Import + +You can import the `ibm_en_subscription_cos` resource by using `id`. +The `id` property can be formed from `instance_guid`, and `subscription_id` in the following format: + +``` +/ +``` + +- `instance_guid`: A string. Unique identifier for IBM Cloud Event Notifications instance. +- `subscription_id`: A string. Unique identifier for Subscription. + +**Example** + +``` +$ terraform import ibm_en_subscription_cos.cos_subscription / +``` diff --git a/website/docs/r/en_subscription_firefox.html.markdown b/website/docs/r/en_subscription_firefox.html.markdown index 6d0e6cac81..66cc9ce604 100644 --- a/website/docs/r/en_subscription_firefox.html.markdown +++ b/website/docs/r/en_subscription_firefox.html.markdown @@ -6,7 +6,7 @@ description: |- Manages Event Notifications Firefox subscription. --- -# ibm_en_subscription_android +# ibm_en_subscription_firefox Create, update, or delete a Firefox subscription by using IBM Cloud™ Event Notifications. @@ -15,8 +15,8 @@ Create, update, or delete a Firefox subscription by using IBM Cloud™ Event Not ```terraform resource "ibm_en_subscription_firefox" "firefox_subscription" { instance_guid = ibm_resource_instance.en_terraform_test_resource.guid - name = "Android Subscription" - description = "Android Subscription for Notification" + name = "Firefox Subscription" + description = "Firefox destination Subscription for Notification" destination_id = ibm_en_destination_firefox.firefx_destination.destination_id topic_id = ibm_en_topic.topic1.topic_id } diff --git a/website/docs/r/en_subscription_slack.html.markdown b/website/docs/r/en_subscription_slack.html.markdown index ea96ef8e25..5d3c005dea 100644 --- a/website/docs/r/en_subscription_slack.html.markdown +++ b/website/docs/r/en_subscription_slack.html.markdown @@ -42,7 +42,7 @@ Review the argument reference that you can specify for your resource. - `attributes` - (Optional, List) Subscription attributes. Nested scheme for **attributes**: - - `attachment_color` - (Optional, Boolean) The color code for slack attachment. + - `attachment_color` - (Optional, String) The color code for slack attachment. ## Attribute reference