Skip to content

Commit

Permalink
Added support for IBM Cloud Logs atracker targets (IBM-Cloud#5270)
Browse files Browse the repository at this point in the history
* Adding support for Cloud Logs atracker targets

* Added support for IBM Cloud Logs atracker targets

* update project-go-sdk back to v0.2.8-1
  • Loading branch information
SusanHeller authored Apr 18, 2024
1 parent 056ef78 commit ddfaf60
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 19 deletions.
3 changes: 3 additions & 0 deletions examples/ibm-atracker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ resource "atracker_target" "atracker_target_instance" {
cos_endpoint = var.atracker_target_cos_endpoint
logdna_endpoint = var.atracker_target_logdna_endpoint
eventstreams_endpoint = var.atracker_target_eventstreams_endpoint
cloudlogs_endpoint = var.atracker_target_cloudlogs_instance
}
```
atracker_route resource:
Expand Down Expand Up @@ -101,6 +102,8 @@ data "atracker_routes" "atracker_routes_instance" {
| target_type | The type of the target. | `string` | true |
| cos_endpoint | Property values for a Cloud Object Storage Endpoint. | `` | true |
| eventstreams_endpoint | Property values for the Event Streams Endpoint in responses. | `` | false |
| logdna_endpoint | Property values for a LogDNA Endpoint in responses. | `` | false |
| cloudlogs_endpoint | Property values for the IBM Cloud Logs Endpoint in responses. | `` | false |
| name | The name of the route. The name must be 1000 characters or less and cannot include any special characters other than `(space) - . _ :`. | `string` | true |
| rules | The routing rules that will be evaluated in their order of the array. Once a rule is matched, the remaining rules in the route definition will be skipped. | `list()` | true |
| default_targets | The target ID List. In the event that no routing rule causes the event to be sent to a target, these targets will receive the event. | `list(string)` | false |
Expand Down
9 changes: 9 additions & 0 deletions examples/ibm-atracker/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ resource "ibm_atracker_target" atracker_target_eventstreams_instance {
region = var.atracker_target_region
}

resource "ibm_atracker_target" atracker_target_cloudlogs_instance {
name = var.atracker_target_name
target_type = "cloud_logs"
cloudlogs_endpoint {
target_crn = "crn:v1:bluemix:public:logs:eu-es:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::"
}
region = var.atracker_target_region
}


// Provision atracker_route resource instance
resource "ibm_atracker_route" "atracker_route_instance" {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/IBM/ibm-hpcs-uko-sdk v0.0.20-beta
github.com/IBM/keyprotect-go-client v0.12.2
github.com/IBM/networking-go-sdk v0.45.0
github.com/IBM/platform-services-go-sdk v0.62.0
github.com/IBM/platform-services-go-sdk v0.62.3
github.com/IBM/project-go-sdk v0.2.8-1
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5
github.com/IBM/scc-go-sdk/v5 v5.1.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ github.com/IBM/mqcloud-go-sdk v0.0.4 h1:gqMpoU5a0qJ0GETG4PQrkgeEEoaQLvbxRJnEe6yt
github.com/IBM/mqcloud-go-sdk v0.0.4/go.mod h1:gQptHC6D+rxfg0muRFFGvTDmvl4YfiDE0uXkaRRewRk=
github.com/IBM/networking-go-sdk v0.45.0 h1:tYgDhVDpgKvELNY7tcodbZ4ny9fatpEWM6PwtQcDe20=
github.com/IBM/networking-go-sdk v0.45.0/go.mod h1:NnJPA1e5GWr5opJe+5Hs6e1G6RcBIFz64TrkZsdnSp8=
github.com/IBM/platform-services-go-sdk v0.62.0 h1:IA7kerhjqHHCSirXsLveX6Bk6DnUOA7Z9zaMqLZ5iBY=
github.com/IBM/platform-services-go-sdk v0.62.0/go.mod h1:fd7gUOmsuQYhYLTZVLL+posObT/ISxVV+6JzsfDs5qE=
github.com/IBM/platform-services-go-sdk v0.62.3 h1:utPtD1DYpA2r8Q7vDWoszMYJEsop7U973kyQ6vNizCA=
github.com/IBM/platform-services-go-sdk v0.62.3/go.mod h1:fd7gUOmsuQYhYLTZVLL+posObT/ISxVV+6JzsfDs5qE=
github.com/IBM/project-go-sdk v0.2.8-1 h1:2xGV+bZZ0ZrDzCpmVfcMkdOchARNns7vkUtAdQyDanQ=
github.com/IBM/project-go-sdk v0.2.8-1/go.mod h1:7YN8IpeiDPPrIdm/4xMJhj2aU/TA1TSrvFuUUSGq9BU=
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5 h1:NPUhkoOCRuv3OFWt19PmwjXGGTKlvmbuPg9fUrBUNe4=
Expand Down
29 changes: 29 additions & 0 deletions ibm/service/atracker/data_source_ibm_atracker_targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,20 @@ func DataSourceIBMAtrackerTargets() *schema.Resource {
},
},
},
"cloudlogs_endpoint": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Property values for the IBM Cloud Logs endpoint in responses.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"target_crn": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The CRN of the IBM Cloud Logs instance",
},
},
},
},
"cos_write_status": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -340,6 +354,13 @@ func DataSourceIBMAtrackerTargetsTargetToMap(model *atrackerv2.Target) (map[stri
}
modelMap["eventstreams_endpoint"] = []map[string]interface{}{eventstreamsEndpointMap}
}
if model.CloudlogsEndpoint != nil {
cloudlogsEndpointMap, err := DataSourceIBMAtrackerTargetsCloudlogsEndpointToMap(model.CloudlogsEndpoint)
if err != nil {
return modelMap, err
}
modelMap["cloudlogs_endpoint"] = []map[string]interface{}{cloudlogsEndpointMap}
}
if model.WriteStatus != nil {
writeStatusMap, err := DataSourceIBMAtrackerTargetsWriteStatusToMap(model.WriteStatus)
if err != nil {
Expand Down Expand Up @@ -403,6 +424,14 @@ func DataSourceIBMAtrackerTargetsEventstreamsEndpointToMap(model *atrackerv2.Eve
return modelMap, nil
}

func DataSourceIBMAtrackerTargetsCloudlogsEndpointToMap(model *atrackerv2.CloudLogsEndpoint) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.TargetCRN != nil {
modelMap["target_crn"] = *model.TargetCRN
}
return modelMap, nil
}

func DataSourceIBMAtrackerTargetsWriteStatusToMap(model *atrackerv2.WriteStatus) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.Status != nil {
Expand Down
4 changes: 4 additions & 0 deletions ibm/service/atracker/data_source_ibm_atracker_targets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,13 @@ func testAccCheckIBMAtrackerTargetsDataSourceConfig(targetName string, targetTar
topic = "my-topic"
api_key = "%s" // pragma: allowlist secret
}
cloudlogs_endpoint {
target_crn = "crn:v1:bluemix:public:logs:eu-es:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::"
}
}
data "ibm_atracker_targets" "atracker_targets" {
name = ibm_atracker_target.atracker_target.name
}
`, targetName, targetTargetType, targetRegion, acc.COSApiKey, acc.IngestionKey, acc.IesApiKey)
}
58 changes: 55 additions & 3 deletions ibm/service/atracker/resource_ibm_atracker_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func ResourceIBMAtrackerTarget() *schema.Resource {
Required: true,
ForceNew: true,
ValidateFunc: validate.InvokeValidator("ibm_atracker_target", "target_type"),
Description: "The type of the target. It can be cloud_object_storage, logdna or event_streams. Based on this type you must include cos_endpoint, logdna_endpoint or eventstreams_endpoint.",
Description: "The type of the target. It can be cloud_object_storage, logdna, event_streams, or cloud_logs. Based on this type you must include cos_endpoint, logdna_endpoint, eventstreams_endpoint or cloudlogs_endpoint.",
},
"cos_endpoint": {
Type: schema.TypeList,
Expand Down Expand Up @@ -135,6 +135,21 @@ func ResourceIBMAtrackerTarget() *schema.Resource {
},
},
},
"cloudlogs_endpoint": &schema.Schema{
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Description: "Property values for an IBM Cloud Logs endpoint in requests.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"target_crn": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "The CRN of the IBM Cloud Logs instance.",
},
},
},
},
"region": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -255,7 +270,7 @@ func ResourceIBMAtrackerTargetValidator() *validate.ResourceValidator {
ValidateFunctionIdentifier: validate.ValidateAllowedStringValue,
Type: validate.TypeString,
Required: true,
AllowedValues: "cloud_object_storage, logdna, event_streams",
AllowedValues: "cloud_object_storage, logdna, event_streams, cloud_logs",
},
validate.ValidateSchema{
Identifier: "region",
Expand Down Expand Up @@ -303,6 +318,13 @@ func resourceIBMAtrackerTargetCreate(context context.Context, d *schema.Resource
}
createTargetOptions.SetEventstreamsEndpoint(eventstreamsEndpointModel)
}
if _, ok := d.GetOk("cloudlogs_endpoint"); ok {
cloudLogsEndpointModel, err := resourceIBMAtrackerTargetMapToCloudLogsEndpointPrototype(d.Get("cloudlogs_endpoint.0").(map[string]interface{}))
if err != nil {
return diag.FromErr(err)
}
createTargetOptions.SetCloudlogsEndpoint(cloudLogsEndpointModel)
}
if _, ok := d.GetOk("region"); ok {
createTargetOptions.SetRegion(d.Get("region").(string))
}
Expand Down Expand Up @@ -390,6 +412,16 @@ func resourceIBMAtrackerTargetRead(context context.Context, d *schema.ResourceDa
}
}

if target.CloudlogsEndpoint != nil {
cloudLogsEndpointMap, err := resourceIBMAtrackerTargetCloudLogsEndpointPrototypeToMap(target.CloudlogsEndpoint)
if err != nil {
return diag.FromErr(err)
}
if err = d.Set("cloudlogs_endpoint", []map[string]interface{}{cloudLogsEndpointMap}); err != nil {
return diag.FromErr(fmt.Errorf("Error setting cloudlogs_endpoint: %s", err))
}
}

if target.CRN != nil {
if err = d.Set("crn", target.CRN); err != nil {
return diag.FromErr(fmt.Errorf("Error setting crn: %s", err))
Expand Down Expand Up @@ -443,7 +475,7 @@ func resourceIBMAtrackerTargetUpdate(context context.Context, d *schema.Resource

hasChange := false

if d.HasChange("name") || d.HasChange("cos_endpoint") || d.HasChange("region") || d.HasChange("logdna_endpoint") || d.HasChange("eventstreams_endpoint") {
if d.HasChange("name") || d.HasChange("cos_endpoint") || d.HasChange("region") || d.HasChange("logdna_endpoint") || d.HasChange("eventstreams_endpoint") || d.HasChange("cloudlogs_endpoint") {
replaceTargetOptions.SetName(d.Get("name").(string))

_, hasCosEndpoint := d.GetOk("cos_endpoint.0")
Expand Down Expand Up @@ -471,6 +503,14 @@ func resourceIBMAtrackerTargetUpdate(context context.Context, d *schema.Resource
}
replaceTargetOptions.SetEventstreamsEndpoint(eventstreamsEndpoint)
}
_, hasCloudLogsEndpoint := d.GetOk("cloudlogs_endpoint.0")
if hasCloudLogsEndpoint {
cloudlogsEndpoint, err := resourceIBMAtrackerTargetMapToCloudLogsEndpointPrototype(d.Get("cloudlogs_endpoint.0").(map[string]interface{}))
if err != nil {
return diag.FromErr(err)
}
replaceTargetOptions.SetCloudlogsEndpoint(cloudlogsEndpoint)
}

hasChange = true
}
Expand Down Expand Up @@ -539,6 +579,12 @@ func resourceIBMAtrackerTargetMapToEventstreamsEndpointPrototype(modelMap map[st
return model, nil
}

func resourceIBMAtrackerTargetMapToCloudLogsEndpointPrototype(modelMap map[string]interface{}) (*atrackerv2.CloudLogsEndpointPrototype, error) {
model := &atrackerv2.CloudLogsEndpointPrototype{}
model.TargetCRN = core.StringPtr(modelMap["target_crn"].(string))
return model, nil
}

func resourceIBMAtrackerTargetCosEndpointPrototypeToMap(model *atrackerv2.CosEndpoint) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["endpoint"] = model.Endpoint
Expand Down Expand Up @@ -568,6 +614,12 @@ func resourceIBMAtrackerTargetEventstreamsEndpointPrototypeToMap(model *atracker
return modelMap, nil
}

func resourceIBMAtrackerTargetCloudLogsEndpointPrototypeToMap(model *atrackerv2.CloudLogsEndpoint) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["target_crn"] = model.TargetCRN
return modelMap, nil
}

func resourceIBMAtrackerTargetWriteStatusToMap(model *atrackerv2.WriteStatus) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["status"] = model.Status
Expand Down
26 changes: 15 additions & 11 deletions website/docs/d/atracker_targets.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Nested scheme for **targets**:
* `name` - (String) The name of the target resource.
* `crn` - (String) The crn of the target resource.
* `target_type` - (String) The type of the target.
* Constraints: Allowable values are: `cloud_object_storage`, `logdna`, `event_streams`.
* Constraints: Allowable values are: `cloud_object_storage`, `logdna`, `event_streams`, `cloud_logs`.
* `encrypt_key` - (String) The encryption key that is used to encrypt events before Activity Tracker services buffer them on storage. This credential is masked in the response.
* `region` - (String) Included this optional field if you used it to create a target in a different region other than the one you are connected.
* `cos_endpoint` - (List) Property values for a Cloud Object Storage Endpoint.
Expand All @@ -55,16 +55,20 @@ Nested scheme for **targets**:
* Constraints: The maximum length is `1000` characters. The minimum length is `3` characters. The value must match regular expression `/^[a-zA-Z0-9 -._:\/]+$/`.
* `target_crn` - (String) The CRN of the LogDNA instance.
* Constraints: The maximum length is `1000` characters. The minimum length is `3` characters. The value must match regular expression `/^[a-zA-Z0-9 -._:\/]+$/`.
* `eventstreams_endpoint` - (List) Property values for Event streams Endpoint.
Nested scheme for **eventstreams_endpoint**:
* `api_key` - (String) The IAM API key that has access to the Event streams instance.
* Constraints: The maximum length is `1000` characters. The minimum length is `3` characters. The value must match regular expression `/^[a-zA-Z0-9 -._:]+$/`.
* `topic` - (String) The topic name defined under the Event streams instance.
* Constraints: The maximum length is `1000` characters. The minimum length is `3` characters. The value must match regular expression `/^[a-zA-Z0-9 -._:\/]+$/`.
* `brokers` - (List) The list of brokers defined under the Event streams instance and used in the event streams endpoint.
* Constraints: The list items must match regular expression `/^[a-zA-Z0-9 -._:]+$/`.
* `target_crn` - (String) The CRN of the Event streams instance.
* Constraints: The maximum length is `1000` characters. The minimum length is `3` characters. The value must match regular expression `/^[a-zA-Z0-9 -._:\/]+$/`.
* `eventstreams_endpoint` - (List) Property values for Event streams Endpoint.
Nested scheme for **eventstreams_endpoint**:
* `api_key` - (String) The IAM API key that has access to the Event streams instance.
* Constraints: The maximum length is `1000` characters. The minimum length is `3` characters. The value must match regular expression `/^[a-zA-Z0-9 -._:]+$/`.
* `topic` - (String) The topic name defined under the Event streams instance.
* Constraints: The maximum length is `1000` characters. The minimum length is `3` characters. The value must match regular expression `/^[a-zA-Z0-9 -._:\/]+$/`.
* `brokers` - (List) The list of brokers defined under the Event streams instance and used in the event streams endpoint.
* Constraints: The list items must match regular expression `/^[a-zA-Z0-9 -._:]+$/`.
* `target_crn` - (String) The CRN of the Event streams instance.
* Constraints: The maximum length is `1000` characters. The minimum length is `3` characters. The value must match regular expression `/^[a-zA-Z0-9 -._:\/]+$/`.
* `cloudlogs_endpoint` - (List) Property values for an IBM Cloud Logs endpoint.
Nested scheme for **cloudlogs_endpoint**:
* `target_crn` - (String) The CRN of the IBM Cloud Logs instance.
* Constraints: The maximum length is `1000` characters. The minimum length is `3` characters. The value must match regular expression `/^[a-zA-Z0-9 -._:\/]+$/`.
* `write_status` - (List) The status of the write attempt to the target with the provided endpoint parameters.
Nested scheme for **write_status**:
* `last_failure` - (String) The timestamp of the failure.
Expand Down
14 changes: 12 additions & 2 deletions website/docs/r/atracker_target.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ resource "ibm_atracker_target" "atracker_target" {
}
resource "ibm_atracker_target" "atracker_logdna_target" {
target_type = "logdna"
logdna_endpoint {
target_crn = "crn:v1:bluemix:public:logdna:us-south:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::"
ingestion_key = "xxxxxxxxxxxxxx"
Expand All @@ -37,7 +36,6 @@ resource "ibm_atracker_target" "atracker_logdna_target" {
}
resource "ibm_atracker_target" "atracker_eventstreams_target" {
target_type = "event_streams"
eventstreams_endpoint {
target_crn = "crn:v1:bluemix:public:logdna:us-south:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::"
brokers = ["xxxxx.cloud.ibm.com:9093","yyyyy.cloud.ibm.com:9093"]
Expand All @@ -49,6 +47,15 @@ resource "ibm_atracker_target" "atracker_eventstreams_target" {
region = "us-south"
}
resource "ibm_atracker_target" "atracker_cloudlogs_target" {
cloudlogs_endpoint {
target_crn = "crn:v1:bluemix:public:logs:eu-es:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::"
}
name = "my-cloudlogs-target"
target_type = "cloud_logs"
region = "us-south"
}
```

## Argument reference
Expand Down Expand Up @@ -82,6 +89,9 @@ Nested scheme for **eventstreams_endpoint**:
* Constraints: The list items must match regular expression `/^[a-zA-Z0-9 -._:]+$/`.
* `target_crn` - (String) The CRN of the Event streams instance.
* Constraints: The maximum length is `1000` characters. The minimum length is `3` characters. The value must match regular expression `/^[a-zA-Z0-9 -._:\/]+$/`.
* `cloudlogs_endpoint` - (Optional, List) Property Values for IBM Cloud Logs Endpoint.
* `target_crn` - (String) The CRN of the IBM Cloud Logs instance.
* Constraints: The maximum length is `1000` characters. The minimum length is `3` characters. The value must match regular expression `/^[a-zA-Z0-9 -._:\/]+$/`.
* `name` - (Required, String) The name of the target. The name must be 1000 characters or less, and cannot include any special characters other than `(space) - . _ :`.
* Constraints: The maximum length is `1000` characters. The minimum length is `1` character. The value must match regular expression `/^[a-zA-Z0-9 -._:]+$/`.
* `region` - (Optional, String) Include this optional field if you want to create a target in a different region other than the one you are connected.
Expand Down

0 comments on commit ddfaf60

Please sign in to comment.