Skip to content

Commit

Permalink
Add ibm cloud observability service support (GoogleCloudPlatform#1456)
Browse files Browse the repository at this point in the history
  • Loading branch information
anilkumarnagaraj authored Sep 13, 2022
1 parent 72ccbe9 commit 4632dc6
Show file tree
Hide file tree
Showing 11 changed files with 428 additions and 126 deletions.
9 changes: 8 additions & 1 deletion docs/ibmcloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ List of supported IBM Cloud resources:
* `ibm_container_cluster`
* `ibm_container_cluster`
* `ibm_container_worker_pool`
* `ibm_container_worker_pool_zone_attachment`
* `ibm_container_nlb_dns`
* `ibm_certificate_manager`
* `ibm_resource_instance`
* `ibm_certificate_manager_import`
Expand All @@ -147,3 +147,10 @@ List of supported IBM Cloud resources:
* `ibm_is_ssh_key`
* `ibm_is_security_group`
* `ibm_is_subnet`
* `ibm_secrets_manager`
* `ibm_continuous_delivery`
* `ibm_cloud_sysdig_monitor`
* `ibm_cloud_logdna`
* `ibm_cloud_atracker`
* `ibm_cloud_watson_studio`
* `ibm_cloud_watson_machine_learning`
16 changes: 1 addition & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/Azure/azure-storage-blob-go v0.10.0
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Azure/go-autorest/autorest v0.11.27
github.com/DataDog/datadog-api-client-go v1.14.0
github.com/IBM-Cloud/bluemix-go v0.0.0-20220624043500-d538cb4fd9be
github.com/IBM/go-sdk-core/v3 v3.3.1
github.com/IBM/go-sdk-core/v4 v4.9.0
Expand Down Expand Up @@ -348,9 +347,9 @@ require (
cloud.google.com/go/iam v0.3.0
cloud.google.com/go/monitoring v1.4.0
github.com/DataDog/datadog-api-client-go/v2 v2.1.0
github.com/manicminer/hamilton v0.44.0
github.com/Myra-Security-GmbH/myrasec-go/v2 v2.19.0
github.com/manicminer/hamilton v0.44.0
gopkg.in/ns1/ns1-go.v2 v2.6.5
)

require (
Expand All @@ -361,29 +360,16 @@ require (
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/clbanning/mxj v1.8.4 // indirect
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
github.com/fatih/color v1.7.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/golang-jwt/jwt/v4 v4.3.0 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/gops v0.3.25 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/manicminer/hamilton-autorest v0.2.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/shirou/gopsutil/v3 v3.22.4 // indirect
github.com/tklauser/go-sysconf v0.3.10 // indirect
github.com/tklauser/numcpus v0.4.0 // indirect
github.com/xlab/treeprint v1.1.0 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
gopkg.in/ns1/ns1-go.v2 v2.6.5 // indirect
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect
rsc.io/goversion v1.2.0 // indirect
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
)

Expand Down
54 changes: 8 additions & 46 deletions go.sum

Large diffs are not rendered by default.

30 changes: 20 additions & 10 deletions providers/ibm/cis.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ func (g *CISGenerator) InitResources() error {
if err != nil {
return err
}

for _, gblm := range gblmList.Result {
if gblm.Port != nil {
port := strconv.FormatInt(*gblm.Port, 10)
Expand Down Expand Up @@ -560,6 +561,7 @@ func (g *CISGenerator) InitResources() error {
wasGrpList, _, err := cisWAFGroupClient.ListWafRuleGroups(&wafrulegroupsapiv1.ListWafRuleGroupsOptions{
PkgID: wafPkg.Result.ID,
})

if err != nil {
return err
}
Expand All @@ -580,11 +582,13 @@ func (g *CISGenerator) InitResources() error {
rateLimitService, _ := zoneratelimitsv1.NewZoneRateLimitsV1(rateLimitPoolOpts)
rateLimitList, _, err := rateLimitService.ListAllZoneRateLimits(&zoneratelimitsv1.ListAllZoneRateLimitsOptions{})
if err != nil {
return err
fmt.Printf("Error in getting rate limit.")
}

for _, rl := range rateLimitList.Result {
g.Resources = append(g.Resources, g.loadRateLimit(crn, *z.ID, *rl.ID, domainDependsOn))
if rateLimitList != nil {
for _, rl := range rateLimitList.Result {
g.Resources = append(g.Resources, g.loadRateLimit(crn, *z.ID, *rl.ID, domainDependsOn))
}
}

// Firewall - Lockdown
Expand Down Expand Up @@ -631,9 +635,11 @@ func (g *CISGenerator) InitResources() error {
return err
}

for _, f := range firewalAccesslList.Result {
if f.Configuration.Target != nil {
g.Resources = append(g.Resources, g.loadFirewall(crn, *z.ID, *f.ID, "access_rules", domainDependsOn))
if firewalAccesslList != nil {
for _, f := range firewalAccesslList.Result {
if f.Configuration.Target != nil {
g.Resources = append(g.Resources, g.loadFirewall(crn, *z.ID, *f.ID, "access_rules", domainDependsOn))
}
}
}

Expand Down Expand Up @@ -705,11 +711,13 @@ func (g *CISGenerator) InitResources() error {
rangeAppClient, _ := rangeapplicationsv1.NewRangeApplicationsV1(rangeAppOpt)
ranegAppList, _, err := rangeAppClient.ListRangeApps(&rangeapplicationsv1.ListRangeAppsOptions{})
if err != nil {
return err
fmt.Printf("Error in getting range app list.")
}

for _, r := range ranegAppList.Result {
g.Resources = append(g.Resources, g.loadRangeApp(crn, *z.ID, *r.ID, domainDependsOn))
if ranegAppList != nil {
for _, r := range ranegAppList.Result {
g.Resources = append(g.Resources, g.loadRangeApp(crn, *z.ID, *r.ID, domainDependsOn))
}
}

// Page Rules
Expand Down Expand Up @@ -789,10 +797,12 @@ func (g *CISGenerator) InitResources() error {
if err != nil {
return err
}

routingList, _, err := routingClient.GetSmartRouting(&routingv1.GetSmartRoutingOptions{})
if err != nil {
return err
fmt.Printf("Error in getting routing list.")
}

if routingList != nil {
g.Resources = append(g.Resources, g.loadCISRouting(crn, *z.ID, domainDependsOn))
}
Expand Down
10 changes: 5 additions & 5 deletions providers/ibm/cloud_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type CloudFunctionGenerator struct {
func (g CloudFunctionGenerator) loadPackages(namespace, pkgName string) terraformutils.Resource {
resource := terraformutils.NewResource(
fmt.Sprintf("%s:%s", namespace, pkgName),
pkgName,
normalizeResourceName(pkgName, true),
"ibm_function_package",
"ibm",
map[string]string{},
Expand All @@ -50,7 +50,7 @@ func (g CloudFunctionGenerator) loadPackages(namespace, pkgName string) terrafor
func (g CloudFunctionGenerator) loadRules(namespace, ruleName string) terraformutils.Resource {
resource := terraformutils.NewResource(
fmt.Sprintf("%s:%s", namespace, ruleName),
normalizeResourceName(ruleName, false),
normalizeResourceName(ruleName, true),
"ibm_function_rule",
"ibm",
map[string]string{},
Expand All @@ -62,7 +62,7 @@ func (g CloudFunctionGenerator) loadRules(namespace, ruleName string) terraformu
func (g CloudFunctionGenerator) loadTriggers(namespace, triggerName string) terraformutils.Resource {
resource := terraformutils.NewResource(
fmt.Sprintf("%s:%s", namespace, triggerName),
normalizeResourceName(triggerName, false),
normalizeResourceName(triggerName, true),
"ibm_function_trigger",
"ibm",
map[string]string{},
Expand Down Expand Up @@ -185,7 +185,7 @@ func (g *CloudFunctionGenerator) InitResources() error {
actionID = fmt.Sprintf("%s/%s", parts[1], a.Name)
g.Resources = append(g.Resources, terraformutils.NewResource(
fmt.Sprintf("%s:%s", n.GetName(), actionID),
normalizeResourceName(a.Name, false),
normalizeResourceName(a.Name, true),
"ibm_function_action",
"ibm",
map[string]string{},
Expand All @@ -196,7 +196,7 @@ func (g *CloudFunctionGenerator) InitResources() error {
} else {
g.Resources = append(g.Resources, terraformutils.NewResource(
fmt.Sprintf("%s:%s", n.GetName(), a.Name),
normalizeResourceName(a.Name, false),
normalizeResourceName(a.Name, true),
"ibm_function_action",
"ibm",
map[string]string{},
Expand Down
84 changes: 84 additions & 0 deletions providers/ibm/cloud_log_analysis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2019 The Terraformer Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package ibm

import (
"os"

"github.com/GoogleCloudPlatform/terraformer/terraformutils"
"github.com/IBM-Cloud/bluemix-go"
"github.com/IBM-Cloud/bluemix-go/api/resource/resourcev1/catalog"
"github.com/IBM-Cloud/bluemix-go/api/resource/resourcev2/controllerv2"
"github.com/IBM-Cloud/bluemix-go/session"
)

// LogAnalysisGenerator ..
type LogAnalysisGenerator struct {
IBMService
}

// loadCloudMonitoring ..
func (g LogAnalysisGenerator) loadCloudMonitoring(logID string, logName string) terraformutils.Resource {
resources := terraformutils.NewSimpleResource(
logID,
normalizeResourceName(logName, false),
"ibm_resource_instance",
"ibm",
[]string{})
return resources
}

// InitResources ...
func (g *LogAnalysisGenerator) InitResources() error {
region := g.Args["region"].(string)
bmxConfig := &bluemix.Config{
BluemixAPIKey: os.Getenv("IC_API_KEY"),
Region: region,
}
sess, err := session.New(bmxConfig)
if err != nil {
return err
}

catalogClient, err := catalog.New(sess)
if err != nil {
return err
}

controllerClient, err := controllerv2.New(sess)
if err != nil {
return err
}

serviceID, err := catalogClient.ResourceCatalog().FindByName("logdna", true)
if err != nil {
return err
}
query := controllerv2.ServiceInstanceQuery{
ServiceID: serviceID[0].ID,
}
logAnalysisInstances, err := controllerClient.ResourceServiceInstanceV2().ListInstances(query)
if err != nil {
return err
}

for _, logDNA := range logAnalysisInstances {
if logDNA.RegionID == region {
g.Resources = append(g.Resources, g.loadCloudMonitoring(logDNA.ID, logDNA.Name))
}
}

return nil
}
84 changes: 84 additions & 0 deletions providers/ibm/cloud_log_atracker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2019 The Terraformer Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package ibm

import (
"os"

"github.com/GoogleCloudPlatform/terraformer/terraformutils"
"github.com/IBM-Cloud/bluemix-go"
"github.com/IBM-Cloud/bluemix-go/api/resource/resourcev1/catalog"
"github.com/IBM-Cloud/bluemix-go/api/resource/resourcev2/controllerv2"
"github.com/IBM-Cloud/bluemix-go/session"
)

// ActivityTrackerGenerator ..
type ActivityTrackerGenerator struct {
IBMService
}

// loadCloudAtracker ..
func (g ActivityTrackerGenerator) loadCloudAtracker(aTrackerID string, aTrackerName string) terraformutils.Resource {
resources := terraformutils.NewSimpleResource(
aTrackerID,
normalizeResourceName(aTrackerName, false),
"ibm_resource_instance",
"ibm",
[]string{})
return resources
}

// InitResources ...
func (g *ActivityTrackerGenerator) InitResources() error {
region := g.Args["region"].(string)
bmxConfig := &bluemix.Config{
BluemixAPIKey: os.Getenv("IC_API_KEY"),
Region: region,
}
sess, err := session.New(bmxConfig)
if err != nil {
return err
}

catalogClient, err := catalog.New(sess)
if err != nil {
return err
}

controllerClient, err := controllerv2.New(sess)
if err != nil {
return err
}

serviceID, err := catalogClient.ResourceCatalog().FindByName("logdnaat", true)
if err != nil {
return err
}
query := controllerv2.ServiceInstanceQuery{
ServiceID: serviceID[0].ID,
}
aTrackerInstances, err := controllerClient.ResourceServiceInstanceV2().ListInstances(query)
if err != nil {
return err
}

for _, aTracker := range aTrackerInstances {
if aTracker.RegionID == region {
g.Resources = append(g.Resources, g.loadCloudAtracker(aTracker.ID, aTracker.Name))
}
}

return nil
}
4 changes: 2 additions & 2 deletions providers/ibm/cloud_monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import (
"github.com/IBM-Cloud/bluemix-go/session"
)

// DatabaseRedisGenerator ...
// MonitoringGenerator ...
type MonitoringGenerator struct {
IBMService
}

// loadRedisDB ...
// loadCloudMonitoring ...
func (g MonitoringGenerator) loadCloudMonitoring(cdID string, cdName string) terraformutils.Resource {
resources := terraformutils.NewSimpleResource(
cdID,
Expand Down
Loading

0 comments on commit 4632dc6

Please sign in to comment.