Skip to content

Commit 9d1a10a

Browse files
feat(CIS): Logpush to cloud logs and generic destination (IBM-Cloud#5872)
* feat(PDNS): update custom resolver profile and views * fix minor warnigns * add example * add documentation * change variable names * fix styling * add validator for profile * modify example * improve error message * modified docs * fix error message * incorporate review comments for documentation * add order in views and fix minor bugs * change the variable instance * changing update logic for views * modified test for linked zone * add test for custom resolver profile * add test for forwarding rule views * fix acceptance test FR * change message format * change fields to computed in data source file * feat(CIS): Logpush to cloud logs and generic destination * add support for get job api * modify create resource * modify update resource logic * add remaining computed fields * add examples * add documentation * fix key * incorporated doc review changes * fix go mod issues * add go dependency * incorporated doc review changes * syncing with go sdk * add use_daily_subfolder attribute in document.
1 parent d8d4052 commit 9d1a10a

File tree

7 files changed

+426
-82
lines changed

7 files changed

+426
-82
lines changed

examples/ibm-cis/main.tf

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ data "ibm_cis_bot_analytics" "tests" {
509509
}
510510

511511
# CIS Logpush Job
512+
# logdna
512513
resource "ibm_cis_logpush_job" "test" {
513514
cis_id = data.ibm_cis.cis.id
514515
domain_id = data.ibm_cis_domain.cis_domain.domain_id
@@ -519,16 +520,65 @@ resource "ibm_cis_logpush_job" "test" {
519520
frequency = "high"
520521
logdna =<<LOG
521522
{
522-
"hostname": "cistest-load.com",
523+
"hostname": "cistest-load.com",
523524
"ingress_key": "e2f7xxxxx73a251caxxxxxxxxxxxx",
524525
"region": "in-che"
525526
}
526527
LOG
527528
}
529+
530+
# IBM Cloud Logs
531+
resource "ibm_cis_logpush_job" "test" {
532+
cis_id = "crn:v1:staging:public:internet-svcs-ci:global:a/01652b251c3ae2787110a995d8db0135:1a9174b6-0106-417a-844b-c8eb43a72f63::"
533+
domain_id = "601b728b86e630c744c81740f72570c3"
534+
name = "MylogpushJob"
535+
enabled = false
536+
logpull_options = "timestamps=rfc3339&timestamps=rfc3339"
537+
dataset = "http_requests"
538+
frequency = "high"
539+
ibmcl {
540+
instance_id ="604a309c-585c-4a42-955d-76239ccc1905"
541+
api_key = "zxzeNQI22dxxxxxxxxxxxxxtn1EVK"
542+
region = "us-south"
543+
}
544+
}
545+
546+
# COS
547+
resource "ibm_cis_logpush_job" "test" {
548+
cis_id = "crn:v1:staging:public:internet-svcs-ci:global:a/01652b251c3ae2787110a995d8db0135:1a9174b6-0106-417a-844b-c8eb43a72f63::"
549+
domain_id = "601b728b86e630c744c81740f72570c3"
550+
name = "MylogpushJob"
551+
enabled = false
552+
logpull_options = "timestamps=rfc3339&timestamps=rfc3339"
553+
dataset = "http_requests"
554+
frequency = "high"
555+
ownership_challenge = "xxx"
556+
cos =<<COS
557+
{
558+
"bucket_name": "examplse.cistest-load.com",
559+
"id": "e2f72cxxxxxxxxxxxxa0b87859e",
560+
"region": "in-che"
561+
}
562+
COS
563+
}
564+
565+
# Genral destination
566+
resource "ibm_cis_logpush_job" "test" {
567+
cis_id = "crn:v1:staging:public:internet-svcs-ci:global:a/01652b251c3ae2787110a995d8db0135:1a9174b6-0106-417a-844b-c8eb43a72f63::"
568+
domain_id = "601b728b86e630c744c81740f72570c3"
569+
name = "MylogpushJob"
570+
enabled = false
571+
logpull_options = "timestamps=rfc3339&timestamps=rfc3339"
572+
dataset = "http_requests"
573+
frequency = "high"
574+
destination_conf = "s3://mybucket/logs?region=us-west-2"
575+
}
528576
# CIS Logpush Job Data source
577+
529578
data "ibm_cis_logpush_jobs" "test" {
530579
cis_id = data.ibm_cis.cis.id
531580
domain_id = data.ibm_cis_domain.cis_domain.domain_id
581+
job_id = data.ibm_cis_domain.job.job_id
532582
}
533583

534584
#CIS MTLS instance

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ require (
3232
github.com/IBM/logs-go-sdk v0.4.0
3333
github.com/IBM/logs-router-go-sdk v1.0.5
3434
github.com/IBM/mqcloud-go-sdk v0.2.0
35-
github.com/IBM/networking-go-sdk v0.50.0
35+
github.com/IBM/networking-go-sdk v0.51.1
3636
github.com/IBM/platform-services-go-sdk v0.72.0
3737
github.com/IBM/project-go-sdk v0.3.5
3838
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ github.com/IBM/logs-router-go-sdk v1.0.5 h1:r0kC1+HfmSeQCD6zQTUp4PDI/zp4Ueo1Zo19
154154
github.com/IBM/logs-router-go-sdk v1.0.5/go.mod h1:tCN2vFgu5xG0ob9iJcxi5M4bJ6mWmu3nhmRPnvlwev0=
155155
github.com/IBM/mqcloud-go-sdk v0.2.0 h1:QOWk8ZGk0QfIL0MOGTKzNdM3Qe0Hk+ifAFtNSFQo5HU=
156156
github.com/IBM/mqcloud-go-sdk v0.2.0/go.mod h1:VZQKMtqmcdXKhmLhLiPuS/UHMs/5yo2tA/nD83cQt9E=
157-
github.com/IBM/networking-go-sdk v0.50.0 h1:3BHO1GrFnkkZ4mYyn2nQc+Djw48/g3znJe3k4a4p1Yk=
158-
github.com/IBM/networking-go-sdk v0.50.0/go.mod h1:aDKmbdfJG+JnoV9RvxOPg7nmgTKReyBgX8aAZHolcm8=
157+
github.com/IBM/networking-go-sdk v0.51.1 h1:xRlDFxSMejMmJ7JPFZ9cflL86uJpbqUzuL/1D/pP7/g=
158+
github.com/IBM/networking-go-sdk v0.51.1/go.mod h1:5aBaPKkm47LHECEOOZ4ltbwypOhapVo5aSCP3MTxmgQ=
159159
github.com/IBM/platform-services-go-sdk v0.72.0 h1:AfJe6bgqmTQU4ff/2URu3wkRLZD0XIzojn7SLf2yIns=
160160
github.com/IBM/platform-services-go-sdk v0.72.0/go.mod h1:ApFkvqw7NaluWJ5Uq+afdM/2jQqo5ILc0SzKSVobYNw=
161161
github.com/IBM/project-go-sdk v0.3.5 h1:L+YClFUa14foS0B/hOOY9n7sIdsT5/XQicnXOyJSpyM=

ibm/service/cis/datasource_ibm_cis_logpush_jobs.go

Lines changed: 79 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package cis
55

66
import (
77
"log"
8+
"strconv"
89
"time"
910

1011
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
@@ -36,6 +37,11 @@ func DataSourceIBMCISLogPushJobs() *schema.Resource {
3637
Required: true,
3738
DiffSuppressFunc: suppressDomainIDDiff,
3839
},
40+
cisLogpushJobID: {
41+
Type: schema.TypeInt,
42+
Description: "ID of the Job",
43+
Optional: true,
44+
},
3945
cisLogpushJobs: {
4046
Type: schema.TypeList,
4147
Computed: true,
@@ -77,6 +83,21 @@ func DataSourceIBMCISLogPushJobs() *schema.Resource {
7783
Computed: true,
7884
Description: "The frequency at which CIS sends batches of logs to your destination",
7985
},
86+
cisLogpushLastComplete: {
87+
Type: schema.TypeString,
88+
Computed: true,
89+
Description: "Records the last time for which logs have been successfully pushed.",
90+
},
91+
cisLogpushLastError: {
92+
Type: schema.TypeString,
93+
Computed: true,
94+
Description: "Records the last time the job failed.",
95+
},
96+
cisLogpushErrorMessage: {
97+
Type: schema.TypeString,
98+
Computed: true,
99+
Description: "The last failure message.",
100+
},
80101
},
81102
},
82103
},
@@ -110,30 +131,72 @@ func ResourceIBMCISLogpushJobsRead(d *schema.ResourceData, meta interface{}) err
110131
sess.Crn = core.StringPtr(crn)
111132
zoneID, _, _ := flex.ConvertTftoCisTwoVar(d.Get(cisDomainID).(string))
112133
sess.ZoneID = core.StringPtr(zoneID)
113-
opt := sess.NewGetLogpushJobsV2Options()
114-
result, resp, err := sess.GetLogpushJobsV2(opt)
115-
if err != nil {
116-
log.Printf("[WARN] List all Logpush jobs failed: %v\n", resp)
117-
return err
118-
}
134+
jobId := d.Get(cisLogpushJobID).(int)
119135
logPushList := make([]map[string]interface{}, 0)
120-
for _, logpushObj := range result.Result {
136+
137+
if jobId != 0 {
138+
opt := sess.NewGetLogpushJobV2Options(strconv.Itoa(jobId))
139+
result, resp, err := sess.GetLogpushJobV2(opt)
140+
if err != nil {
141+
log.Printf("[WARN] Get Logpush job failed: %v\n", resp)
142+
return err
143+
}
121144
logPushOpt := map[string]interface{}{}
122-
logPushOpt[cisLogpushJobID] = int64(*logpushObj.ID)
123-
logPushOpt[cisLogpushName] = *logpushObj.Name
124-
logPushOpt[cisLogpullOpt] = *logpushObj.LogpullOptions
125-
logPushOpt[cisLogpushEnabled] = *logpushObj.Enabled
126-
logPushOpt[cisLogpushDataset] = *logpushObj.Dataset
127-
logPushOpt[cisLogpushFreq] = *logpushObj.Frequency
128-
logPushOpt[cisLogpushDestConf] = *logpushObj.DestinationConf
145+
logPushOpt[cisLogpushJobID] = int64(*result.Result.ID)
146+
logPushOpt[cisLogpushName] = *result.Result.Name
147+
logPushOpt[cisLogpullOpt] = *result.Result.LogpullOptions
148+
logPushOpt[cisLogpushEnabled] = *result.Result.Enabled
149+
logPushOpt[cisLogpushDataset] = *result.Result.Dataset
150+
logPushOpt[cisLogpushFreq] = *result.Result.Frequency
151+
logPushOpt[cisLogpushDestConf] = *result.Result.DestinationConf
152+
if result.Result.LastComplete != nil {
153+
logPushOpt[cisLogpushLastComplete] = *result.Result.LastComplete
154+
}
155+
if result.Result.LastError != nil {
156+
logPushOpt[cisLogpushLastError] = *result.Result.LastError
157+
}
158+
if result.Result.ErrorMessage != nil {
159+
logPushOpt[cisLogpushErrorMessage] = *result.Result.ErrorMessage
160+
}
129161
logPushList = append(logPushList, logPushOpt)
162+
163+
} else {
164+
165+
opt := sess.NewGetLogpushJobsV2Options()
166+
result, resp, err := sess.GetLogpushJobsV2(opt)
167+
if err != nil {
168+
log.Printf("[WARN] List all Logpush jobs failed: %v\n", resp)
169+
return err
170+
}
171+
172+
for _, logpushObj := range result.Result {
173+
logPushOpt := map[string]interface{}{}
174+
logPushOpt[cisLogpushJobID] = int64(*logpushObj.ID)
175+
logPushOpt[cisLogpushName] = *logpushObj.Name
176+
logPushOpt[cisLogpullOpt] = *logpushObj.LogpullOptions
177+
logPushOpt[cisLogpushEnabled] = *logpushObj.Enabled
178+
logPushOpt[cisLogpushDataset] = *logpushObj.Dataset
179+
logPushOpt[cisLogpushFreq] = *logpushObj.Frequency
180+
logPushOpt[cisLogpushDestConf] = *logpushObj.DestinationConf
181+
if logpushObj.LastComplete != nil {
182+
logPushOpt[cisLogpushLastComplete] = *logpushObj.LastComplete
183+
}
184+
if logpushObj.LastError != nil {
185+
logPushOpt[cisLogpushLastError] = *logpushObj.LastError
186+
}
187+
if logpushObj.ErrorMessage != nil {
188+
logPushOpt[cisLogpushErrorMessage] = *logpushObj.ErrorMessage
189+
}
190+
191+
logPushList = append(logPushList, logPushOpt)
192+
}
130193
}
131-
d.SetId(dataSourceCISLogpushJobsCheckID(d))
194+
d.SetId(dataSourceCISLogpushJobsCheckID())
132195
d.Set(cisID, crn)
133196
d.Set(cisDomainID, zoneID)
134197
d.Set(cisLogpushJobs, logPushList)
135198
return nil
136199
}
137-
func dataSourceCISLogpushJobsCheckID(d *schema.ResourceData) string {
200+
func dataSourceCISLogpushJobsCheckID() string {
138201
return time.Now().UTC().String()
139202
}

0 commit comments

Comments
 (0)