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

feat(CIS): Logpush to cloud logs and generic destination #5872

Merged
merged 41 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
4121186
feat(PDNS): update custom resolver profile and views
arjunchauhanibm Sep 6, 2024
8df588a
fix minor warnigns
arjunchauhanibm Sep 6, 2024
c379260
add example
arjunchauhanibm Sep 6, 2024
d20fbf8
add documentation
arjunchauhanibm Sep 6, 2024
afb56ac
change variable names
arjunchauhanibm Sep 6, 2024
dc780d6
fix styling
arjunchauhanibm Sep 6, 2024
a04bd55
add validator for profile
arjunchauhanibm Sep 6, 2024
3ba5012
modify example
arjunchauhanibm Sep 7, 2024
1097e5b
improve error message
arjunchauhanibm Sep 22, 2024
8d124a4
modified docs
arjunchauhanibm Sep 23, 2024
31780ce
fix error message
arjunchauhanibm Sep 23, 2024
b7ed734
incorporate review comments for documentation
arjunchauhanibm Oct 13, 2024
57c87c0
add order in views and fix minor bugs
arjunchauhanibm Oct 16, 2024
50bbf8e
change the variable instance
arjunchauhanibm Oct 16, 2024
f6ddd4e
changing update logic for views
arjunchauhanibm Oct 19, 2024
0335f54
modified test for linked zone
arjunchauhanibm Oct 22, 2024
95ecf4d
add test for custom resolver profile
arjunchauhanibm Oct 22, 2024
4c72d23
add test for forwarding rule views
arjunchauhanibm Oct 22, 2024
5c37702
fix acceptance test FR
arjunchauhanibm Oct 27, 2024
47963f4
Merge branch 'master' into add_views
arjunchauhanibm Oct 27, 2024
004b648
change message format
arjunchauhanibm Nov 4, 2024
3c9d284
change fields to computed in data source file
arjunchauhanibm Nov 12, 2024
0617476
feat(CIS): Logpush to cloud logs and generic destination
arjunchauhanibm Dec 13, 2024
c2de7c7
add support for get job api
arjunchauhanibm Dec 13, 2024
201c595
modify create resource
arjunchauhanibm Dec 15, 2024
f54dd39
modify update resource logic
arjunchauhanibm Dec 15, 2024
fc65c99
add remaining computed fields
arjunchauhanibm Dec 15, 2024
4468958
add examples
arjunchauhanibm Dec 15, 2024
361eac1
add documentation
arjunchauhanibm Dec 15, 2024
468c0eb
fix key
arjunchauhanibm Dec 15, 2024
4328e8e
incorporated doc review changes
arjunchauhanibm Jan 6, 2025
2df0ad2
Merge branch 'master' into add_views
arjunchauhanibm Jan 11, 2025
3565838
fix go mod issues
arjunchauhanibm Jan 11, 2025
46288f3
Merge branch 'master' into logpush_gen_dest
arjunchauhanibm Jan 12, 2025
ffe8323
Merge branch 'add_views' into logpush_gen_dest
arjunchauhanibm Jan 12, 2025
47a99cd
add go dependency
arjunchauhanibm Jan 12, 2025
9dbc5c3
incorporated doc review changes
arjunchauhanibm Jan 13, 2025
f1c4204
Merge branch 'master' into logpush_gen_dest
arjunchauhanibm Jan 16, 2025
61f34ca
syncing with go sdk
arjunchauhanibm Jan 16, 2025
ed30c43
Merge branch 'master' into logpush_gen_dest
arjunchauhanibm Jan 17, 2025
1b95da0
add use_daily_subfolder attribute in document.
arjunchauhanibm Jan 20, 2025
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
52 changes: 51 additions & 1 deletion examples/ibm-cis/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ data "ibm_cis_bot_analytics" "tests" {
}

# CIS Logpush Job
# logdna
resource "ibm_cis_logpush_job" "test" {
cis_id = data.ibm_cis.cis.id
domain_id = data.ibm_cis_domain.cis_domain.domain_id
Expand All @@ -519,16 +520,65 @@ resource "ibm_cis_logpush_job" "test" {
frequency = "high"
logdna =<<LOG
{
"hostname": "cistest-load.com",
"hostname": "cistest-load.com",
"ingress_key": "e2f7xxxxx73a251caxxxxxxxxxxxx",
"region": "in-che"
}
LOG
}

# IBM Cloud Logs
resource "ibm_cis_logpush_job" "test" {
cis_id = "crn:v1:staging:public:internet-svcs-ci:global:a/01652b251c3ae2787110a995d8db0135:1a9174b6-0106-417a-844b-c8eb43a72f63::"
domain_id = "601b728b86e630c744c81740f72570c3"
name = "MylogpushJob"
enabled = false
logpull_options = "timestamps=rfc3339&timestamps=rfc3339"
dataset = "http_requests"
frequency = "high"
ibmcl {
instance_id ="604a309c-585c-4a42-955d-76239ccc1905"
api_key = "zxzeNQI22dxxxxxxxxxxxxxtn1EVK"
region = "us-south"
}
}

# COS
resource "ibm_cis_logpush_job" "test" {
cis_id = "crn:v1:staging:public:internet-svcs-ci:global:a/01652b251c3ae2787110a995d8db0135:1a9174b6-0106-417a-844b-c8eb43a72f63::"
domain_id = "601b728b86e630c744c81740f72570c3"
name = "MylogpushJob"
enabled = false
logpull_options = "timestamps=rfc3339&timestamps=rfc3339"
dataset = "http_requests"
frequency = "high"
ownership_challenge = "xxx"
cos =<<COS
{
"bucket_name": "examplse.cistest-load.com",
"id": "e2f72cxxxxxxxxxxxxa0b87859e",
"region": "in-che"
}
COS
}

# Genral destination
resource "ibm_cis_logpush_job" "test" {
cis_id = "crn:v1:staging:public:internet-svcs-ci:global:a/01652b251c3ae2787110a995d8db0135:1a9174b6-0106-417a-844b-c8eb43a72f63::"
domain_id = "601b728b86e630c744c81740f72570c3"
name = "MylogpushJob"
enabled = false
logpull_options = "timestamps=rfc3339&timestamps=rfc3339"
dataset = "http_requests"
frequency = "high"
destination_conf = "s3://mybucket/logs?region=us-west-2"
}
# CIS Logpush Job Data source

data "ibm_cis_logpush_jobs" "test" {
cis_id = data.ibm_cis.cis.id
domain_id = data.ibm_cis_domain.cis_domain.domain_id
job_id = data.ibm_cis_domain.job.job_id
}

#CIS MTLS instance
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ require (
github.com/IBM/logs-go-sdk v0.4.0
github.com/IBM/logs-router-go-sdk v1.0.5
github.com/IBM/mqcloud-go-sdk v0.2.0
github.com/IBM/networking-go-sdk v0.50.0
github.com/IBM/networking-go-sdk v0.51.1
github.com/IBM/platform-services-go-sdk v0.72.0
github.com/IBM/project-go-sdk v0.3.5
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ github.com/IBM/logs-router-go-sdk v1.0.5 h1:r0kC1+HfmSeQCD6zQTUp4PDI/zp4Ueo1Zo19
github.com/IBM/logs-router-go-sdk v1.0.5/go.mod h1:tCN2vFgu5xG0ob9iJcxi5M4bJ6mWmu3nhmRPnvlwev0=
github.com/IBM/mqcloud-go-sdk v0.2.0 h1:QOWk8ZGk0QfIL0MOGTKzNdM3Qe0Hk+ifAFtNSFQo5HU=
github.com/IBM/mqcloud-go-sdk v0.2.0/go.mod h1:VZQKMtqmcdXKhmLhLiPuS/UHMs/5yo2tA/nD83cQt9E=
github.com/IBM/networking-go-sdk v0.50.0 h1:3BHO1GrFnkkZ4mYyn2nQc+Djw48/g3znJe3k4a4p1Yk=
github.com/IBM/networking-go-sdk v0.50.0/go.mod h1:aDKmbdfJG+JnoV9RvxOPg7nmgTKReyBgX8aAZHolcm8=
github.com/IBM/networking-go-sdk v0.51.1 h1:xRlDFxSMejMmJ7JPFZ9cflL86uJpbqUzuL/1D/pP7/g=
github.com/IBM/networking-go-sdk v0.51.1/go.mod h1:5aBaPKkm47LHECEOOZ4ltbwypOhapVo5aSCP3MTxmgQ=
github.com/IBM/platform-services-go-sdk v0.72.0 h1:AfJe6bgqmTQU4ff/2URu3wkRLZD0XIzojn7SLf2yIns=
github.com/IBM/platform-services-go-sdk v0.72.0/go.mod h1:ApFkvqw7NaluWJ5Uq+afdM/2jQqo5ILc0SzKSVobYNw=
github.com/IBM/project-go-sdk v0.3.5 h1:L+YClFUa14foS0B/hOOY9n7sIdsT5/XQicnXOyJSpyM=
Expand Down
95 changes: 79 additions & 16 deletions ibm/service/cis/datasource_ibm_cis_logpush_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cis

import (
"log"
"strconv"
"time"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
Expand Down Expand Up @@ -36,6 +37,11 @@ func DataSourceIBMCISLogPushJobs() *schema.Resource {
Required: true,
DiffSuppressFunc: suppressDomainIDDiff,
},
cisLogpushJobID: {
Type: schema.TypeInt,
Description: "ID of the Job",
Optional: true,
},
cisLogpushJobs: {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -77,6 +83,21 @@ func DataSourceIBMCISLogPushJobs() *schema.Resource {
Computed: true,
Description: "The frequency at which CIS sends batches of logs to your destination",
},
cisLogpushLastComplete: {
Type: schema.TypeString,
Computed: true,
Description: "Records the last time for which logs have been successfully pushed.",
},
cisLogpushLastError: {
Type: schema.TypeString,
Computed: true,
Description: "Records the last time the job failed.",
},
cisLogpushErrorMessage: {
Type: schema.TypeString,
Computed: true,
Description: "The last failure message.",
},
},
},
},
Expand Down Expand Up @@ -110,30 +131,72 @@ func ResourceIBMCISLogpushJobsRead(d *schema.ResourceData, meta interface{}) err
sess.Crn = core.StringPtr(crn)
zoneID, _, _ := flex.ConvertTftoCisTwoVar(d.Get(cisDomainID).(string))
sess.ZoneID = core.StringPtr(zoneID)
opt := sess.NewGetLogpushJobsV2Options()
result, resp, err := sess.GetLogpushJobsV2(opt)
if err != nil {
log.Printf("[WARN] List all Logpush jobs failed: %v\n", resp)
return err
}
jobId := d.Get(cisLogpushJobID).(int)
logPushList := make([]map[string]interface{}, 0)
for _, logpushObj := range result.Result {

if jobId != 0 {
opt := sess.NewGetLogpushJobV2Options(strconv.Itoa(jobId))
result, resp, err := sess.GetLogpushJobV2(opt)
if err != nil {
log.Printf("[WARN] Get Logpush job failed: %v\n", resp)
return err
}
logPushOpt := map[string]interface{}{}
logPushOpt[cisLogpushJobID] = int64(*logpushObj.ID)
logPushOpt[cisLogpushName] = *logpushObj.Name
logPushOpt[cisLogpullOpt] = *logpushObj.LogpullOptions
logPushOpt[cisLogpushEnabled] = *logpushObj.Enabled
logPushOpt[cisLogpushDataset] = *logpushObj.Dataset
logPushOpt[cisLogpushFreq] = *logpushObj.Frequency
logPushOpt[cisLogpushDestConf] = *logpushObj.DestinationConf
logPushOpt[cisLogpushJobID] = int64(*result.Result.ID)
logPushOpt[cisLogpushName] = *result.Result.Name
logPushOpt[cisLogpullOpt] = *result.Result.LogpullOptions
logPushOpt[cisLogpushEnabled] = *result.Result.Enabled
logPushOpt[cisLogpushDataset] = *result.Result.Dataset
logPushOpt[cisLogpushFreq] = *result.Result.Frequency
logPushOpt[cisLogpushDestConf] = *result.Result.DestinationConf
if result.Result.LastComplete != nil {
logPushOpt[cisLogpushLastComplete] = *result.Result.LastComplete
}
if result.Result.LastError != nil {
logPushOpt[cisLogpushLastError] = *result.Result.LastError
}
if result.Result.ErrorMessage != nil {
logPushOpt[cisLogpushErrorMessage] = *result.Result.ErrorMessage
}
logPushList = append(logPushList, logPushOpt)

} else {

opt := sess.NewGetLogpushJobsV2Options()
result, resp, err := sess.GetLogpushJobsV2(opt)
if err != nil {
log.Printf("[WARN] List all Logpush jobs failed: %v\n", resp)
return err
}

for _, logpushObj := range result.Result {
logPushOpt := map[string]interface{}{}
logPushOpt[cisLogpushJobID] = int64(*logpushObj.ID)
logPushOpt[cisLogpushName] = *logpushObj.Name
logPushOpt[cisLogpullOpt] = *logpushObj.LogpullOptions
logPushOpt[cisLogpushEnabled] = *logpushObj.Enabled
logPushOpt[cisLogpushDataset] = *logpushObj.Dataset
logPushOpt[cisLogpushFreq] = *logpushObj.Frequency
logPushOpt[cisLogpushDestConf] = *logpushObj.DestinationConf
if logpushObj.LastComplete != nil {
logPushOpt[cisLogpushLastComplete] = *logpushObj.LastComplete
}
if logpushObj.LastError != nil {
logPushOpt[cisLogpushLastError] = *logpushObj.LastError
}
if logpushObj.ErrorMessage != nil {
logPushOpt[cisLogpushErrorMessage] = *logpushObj.ErrorMessage
}

logPushList = append(logPushList, logPushOpt)
}
}
d.SetId(dataSourceCISLogpushJobsCheckID(d))
d.SetId(dataSourceCISLogpushJobsCheckID())
d.Set(cisID, crn)
d.Set(cisDomainID, zoneID)
d.Set(cisLogpushJobs, logPushList)
return nil
}
func dataSourceCISLogpushJobsCheckID(d *schema.ResourceData) string {
func dataSourceCISLogpushJobsCheckID() string {
return time.Now().UTC().String()
}
Loading
Loading