Skip to content

Commit

Permalink
Add new service Logs Router to IBM Terraform Provider (IBM-Cloud#4945)
Browse files Browse the repository at this point in the history
* Added new service Logs Router to IBM Terraform Provider

* Ran detect-secrets and re-generated secrets.baseline

* Added emptycredentialsError check for Logs Router Client Error

Signed-off-by: Ian Reyes <ianreyes99@gmail.com>

* Removed redundant general provider set up information. Fixed Service Subcategories

Signed-off-by: Ian Reyes <ianreyes99@gmail.com>

---------

Signed-off-by: Ian Reyes <ianreyes99@gmail.com>
  • Loading branch information
ianre authored Dec 4, 2023
1 parent dc6d1a9 commit c393b56
Show file tree
Hide file tree
Showing 18 changed files with 881 additions and 6 deletions.
22 changes: 16 additions & 6 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -786,47 +786,47 @@
"hashed_secret": "9184b0c38101bf24d78b2bb0d044deb1d33696fc",
"is_secret": false,
"is_verified": false,
"line_number": 131,
"line_number": 132,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "c427f185ddcb2440be9b77c8e45f1cd487a2e790",
"is_secret": false,
"is_verified": false,
"line_number": 1438,
"line_number": 1449,
"type": "Base64 High Entropy String",
"verified_result": null
},
{
"hashed_secret": "1f7e33de15e22de9d2eaf502df284ed25ca40018",
"is_secret": false,
"is_verified": false,
"line_number": 1505,
"line_number": 1516,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "1f614c2eb6b3da22d89bd1b9fd47d7cb7c8fc670",
"is_secret": false,
"is_verified": false,
"line_number": 3298,
"line_number": 3325,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "7abfce65b8504403afc25c9790f358d513dfbcc6",
"is_secret": false,
"is_verified": false,
"line_number": 3311,
"line_number": 3338,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "0c2d85bf9a9b1579b16f220a4ea8c3d62b2e24b1",
"is_secret": false,
"is_verified": false,
"line_number": 3352,
"line_number": 3379,
"type": "Secret Keyword",
"verified_result": null
}
Expand Down Expand Up @@ -4505,6 +4505,16 @@
"verified_result": null
}
],
"website/docs/r/logs_router_tenant.html.markdown": [
{
"hashed_secret": "d47dcacc720a39e236679ac3e311a0d58bb6519e",
"is_secret": false,
"is_verified": false,
"line_number": 78,
"type": "Secret Keyword",
"verified_result": null
}
],
"website/docs/r/metrics_router_route.html.markdown": [
{
"hashed_secret": "d47dcacc720a39e236679ac3e311a0d58bb6519e",
Expand Down
81 changes: 81 additions & 0 deletions examples/ibm-logs-router/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Example for IBM Logs Router V1

This example illustrates how to use IBM LogsRouterV1

The following types of resources are supported:

* logs_router_tenant

## Usage

To run this example, execute the following commands:

```bash
$ terraform init
$ terraform plan
$ terraform apply
```

Run `terraform destroy` when you don't need these resources.


## IbmLogsRouterV1 resources

logs_router_tenant resource:

```hcl
resource "logs_router_tenant" "logs_router_tenant_instance" {
target_type = var.logs_router_tenant_target_type
target_host = var.logs_router_tenant_target_host
target_port = var.logs_router_tenant_target_port
target_instance_crn = var.logs_router_tenant_target_instance_crn
}
```

## IbmLogsRouterV1 data sources

logs_router_tenant data source:

```hcl
data "logs_router_tenant" "logs_router_tenant_instance" {
tenant_id = ibm_logs_router_tenant.logs_router_tenant_instance.id
}
```

## Assumptions

1. TODO

## Notes

1. TODO

## Requirements

| Name | Version |
|------|---------|
| terraform | ~> 0.12 |

## Providers

| Name | Version |
|------|---------|
| ibm | 1.13.1 |

## Inputs

| Name | Description | Type | Required |
|------|-------------|------|---------|
| ibmcloud\_api\_key | IBM Cloud API key | `string` | true |
| target_type | Type of log-sink. | `string` | true |
| target_host | Host name of log-sink. | `string` | true |
| target_port | Network port of log sink. | `number` | true |
| target_instance_crn | Cloud resource name of the log-sink target instance. | `string` | true |
| tenant_id | The instance ID of the tenant. | `` | true |

## Outputs

| Name | Description |
|------|-------------|
| logs_router_tenant | logs_router_tenant object |
| logs_router_tenant | logs_router_tenant object |
17 changes: 17 additions & 0 deletions examples/ibm-logs-router/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
provider "ibm" {
ibmcloud_api_key = var.ibmcloud_api_key
}

// Provision logs_router_tenant resource instance
resource "ibm_logs_router_tenant" "logs_router_tenant_instance" {
target_type = var.logs_router_tenant_target_type
target_host = var.logs_router_tenant_target_host
target_port = var.logs_router_tenant_target_port
target_instance_crn = var.logs_router_tenant_target_instance_crn
}

// Create logs_router_tenant data source
data "ibm_logs_router_tenant" "logs_router_tenant_instance" {
tenant_id = ibm_logs_router_tenant.logs_router_tenant_instance.id
}

6 changes: 6 additions & 0 deletions examples/ibm-logs-router/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This output allows logs_router_tenant data to be referenced by other resources and the terraform CLI
// Modify this output if only certain data should be exposed
output "ibm_logs_router_tenant" {
value = ibm_logs_router_tenant.logs_router_tenant_instance
description = "logs_router_tenant resource instance"
}
33 changes: 33 additions & 0 deletions examples/ibm-logs-router/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
variable "ibmcloud_api_key" {
description = "IBM Cloud API key"
type = string
}

// Resource arguments for logs_router_tenant
variable "logs_router_tenant_target_type" {
description = "Type of log-sink."
type = string
default = "logdna"
}
variable "logs_router_tenant_target_host" {
description = "Host name of log-sink."
type = string
default = "www.example.com"
}
variable "logs_router_tenant_target_port" {
description = "Network port of log sink."
type = number
default = 10
}
variable "logs_router_tenant_target_instance_crn" {
description = "Cloud resource name of the log-sink target instance."
type = string
default = "crn:v1:bluemix:public:logdna:us-east:a/36ff82794a734d7580b90c97b0327d28:f08aea7c-dde9-4452-b552-225af4b51eaa::"
}

// Data source arguments for logs_router_tenant
variable "logs_router_tenant_tenant_id" {
description = "The instance ID of the tenant."
type = string
default = "f3a466c9-c4db-4eee-95cc-ba82db58e2b5"
}
9 changes: 9 additions & 0 deletions examples/ibm-logs-router/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_version = ">= 1.0"
required_providers {
ibm = {
source = "IBM-Cloud/ibm"
version = "1.52.0-beta0"
}
}
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ require (
github.com/IBM/ibm-hpcs-tke-sdk v0.0.0-20211109141421-a4b61b05f7d1
github.com/IBM/ibm-hpcs-uko-sdk v0.0.20-beta
github.com/IBM/keyprotect-go-client v0.12.2
github.com/IBM/logs-router-go-sdk v1.0.0
github.com/IBM/networking-go-sdk v0.42.2
github.com/IBM/platform-services-go-sdk v0.54.0
github.com/IBM/project-go-sdk v0.1.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ github.com/IBM/ibm-hpcs-uko-sdk v0.0.20-beta/go.mod h1:MLVNHMYoKsvovJZ4v1gQCpIYt
github.com/IBM/keyprotect-go-client v0.5.1/go.mod h1:5TwDM/4FRJq1ZOlwQL1xFahLWQ3TveR88VmL1u3njyI=
github.com/IBM/keyprotect-go-client v0.12.2 h1:Cjxcqin9Pl0xz3MnxdiVd4v/eIa79xL3hQpSbwOr/DQ=
github.com/IBM/keyprotect-go-client v0.12.2/go.mod h1:yr8h2noNgU8vcbs+vhqoXp3Lmv73PI0zAc6VMgFvWwM=
github.com/IBM/logs-router-go-sdk v1.0.0 h1:cGBjf7wJye/WuzFljqN7yB8ToIxLIiffWaQGW9rSTcI=
github.com/IBM/logs-router-go-sdk v1.0.0/go.mod h1:FJpyZctp5DmRms/MtvRUuWBF/CAk76WJzAsJc4EIM/Y=
github.com/IBM/networking-go-sdk v0.42.2 h1:caqjx4jyFHi10Vlf3skHvlL6K3YJRVstsmCBmvdyqkA=
github.com/IBM/networking-go-sdk v0.42.2/go.mod h1:lTUZwtUkMANMnrLHFIgRhHrkBfwASY/Iho1fabaPHxo=
github.com/IBM/platform-services-go-sdk v0.54.0 h1:WjHWm9ZAJvlq07E1WXXtEe+d/B0sazWD6cEWVT7EMLU=
Expand Down
28 changes: 28 additions & 0 deletions ibm/conns/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/IBM/go-sdk-core/v5/core"
cosconfig "github.com/IBM/ibm-cos-sdk-go-config/resourceconfigurationv1"
kp "github.com/IBM/keyprotect-go-client"
"github.com/IBM/logs-router-go-sdk/ibmlogsrouteropenapi30v0"
cisalertsv1 "github.com/IBM/networking-go-sdk/alertsv1"
cisoriginpull "github.com/IBM/networking-go-sdk/authenticatedoriginpullapiv1"
cisbotanalyticsv1 "github.com/IBM/networking-go-sdk/botanalyticsv1"
Expand Down Expand Up @@ -228,6 +229,7 @@ type ClientSession interface {
ResourceManagementAPIv2() (managementv2.ResourceManagementAPIv2, error)
ResourceControllerAPI() (controller.ResourceControllerAPI, error)
ResourceControllerAPIV2() (controllerv2.ResourceControllerAPIV2, error)
IbmLogsRouterOpenApi30V0() (*ibmlogsrouteropenapi30v0.IbmLogsRouterOpenApi30V0, error)
SoftLayerSession() *slsession.Session
IBMPISession() (*ibmpisession.IBMPISession, error)
UserManagementAPI() (usermanagementv2.UserManagementAPI, error)
Expand Down Expand Up @@ -542,6 +544,10 @@ type clientSession struct {
secretsManagerClient *secretsmanagerv2.SecretsManagerV2
secretsManagerClientErr error

// Logs Routing
ibmLogsRouterOpenApi30Client *ibmlogsrouteropenapi30v0.IbmLogsRouterOpenApi30V0
ibmLogsRouterOpenApi30ClientErr error

// Schematics service options
schematicsClient *schematicsv1.SchematicsV1
schematicsClientErr error
Expand Down Expand Up @@ -1169,6 +1175,11 @@ func (session clientSession) MetricsRouterV3() (*metricsrouterv3.MetricsRouterV3
return session.metricsRouterClient, session.metricsRouterClientErr
}

// Logs Router API
func (session clientSession) IbmLogsRouterOpenApi30V0() (*ibmlogsrouteropenapi30v0.IbmLogsRouterOpenApi30V0, error) {
return session.ibmLogsRouterOpenApi30Client, session.ibmLogsRouterOpenApi30ClientErr
}

func (session clientSession) ESschemaRegistrySession() (*schemaregistryv1.SchemaregistryV1, error) {
return session.esSchemaRegistryClient, session.esSchemaRegistryErr
}
Expand Down Expand Up @@ -1296,6 +1307,7 @@ func (c *Config) ClientSession() (interface{}, error) {
session.cdToolchainClientErr = errEmptyBluemixCredentials
session.codeEngineClientErr = errEmptyBluemixCredentials
session.projectClientErr = errEmptyBluemixCredentials
session.ibmLogsRouterOpenApi30ClientErr = errEmptyBluemixCredentials

return session, nil
}
Expand Down Expand Up @@ -1678,6 +1690,22 @@ func (c *Config) ClientSession() (interface{}, error) {
})
}

// LOGS ROUTER service
ibmLogsRouterOpenApi30ClientOptions := &ibmlogsrouteropenapi30v0.IbmLogsRouterOpenApi30V0Options{
Authenticator: authenticator,
}
session.ibmLogsRouterOpenApi30Client, err = ibmlogsrouteropenapi30v0.NewIbmLogsRouterOpenApi30V0(ibmLogsRouterOpenApi30ClientOptions)
if err == nil {
// Enable retries for API calls
session.ibmLogsRouterOpenApi30Client.Service.EnableRetries(c.RetryCount, c.RetryDelay)
// Add custom header for analytics
session.ibmLogsRouterOpenApi30Client.SetDefaultHeaders(gohttp.Header{
"X-Original-User-Agent": {fmt.Sprintf("terraform-provider-ibm/%s", version.Version)},
})
} else {
session.ibmLogsRouterOpenApi30ClientErr = fmt.Errorf("Error occurred while configuring IBM logs-router service: %q", err)
}

// ATRACKER Version 2
var atrackerClientV2URL string
var atrackerURLV2Err error
Expand Down
8 changes: 8 additions & 0 deletions ibm/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/iampolicy"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/kms"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/kubernetes"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/logsrouter"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/metricsrouter"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/power"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/project"
Expand Down Expand Up @@ -743,6 +744,9 @@ func Provider() *schema.Provider {
"ibm_metrics_router_targets": metricsrouter.DataSourceIBMMetricsRouterTargets(),
"ibm_metrics_router_routes": metricsrouter.DataSourceIBMMetricsRouterRoutes(),

// Logs Router
"ibm_logs_router_tenant": logsrouter.DataSourceIbmLogsRouterTenant(),

// Security and Complaince Center(soon to be deprecated)
"ibm_scc_account_location": scc.DataSourceIBMSccAccountLocation(),
"ibm_scc_account_locations": scc.DataSourceIBMSccAccountLocations(),
Expand Down Expand Up @@ -1276,6 +1280,9 @@ func Provider() *schema.Provider {
"ibm_metrics_router_route": metricsrouter.ResourceIBMMetricsRouterRoute(),
"ibm_metrics_router_settings": metricsrouter.ResourceIBMMetricsRouterSettings(),

// Logs Router
"ibm_logs_router_tenant": logsrouter.ResourceIbmLogsRouterTenant(),

// Security and Compliance Center(soon to be deprecated)
"ibm_scc_account_settings": scc.ResourceIBMSccAccountSettings(),
"ibm_scc_rule_attachment": scc.ResourceIBMSccRuleAttachment(),
Expand Down Expand Up @@ -1540,6 +1547,7 @@ func Validator() validate.ValidatorDict {
"ibm_metrics_router_target": metricsrouter.ResourceIBMMetricsRouterTargetValidator(),
"ibm_metrics_router_route": metricsrouter.ResourceIBMMetricsRouterRouteValidator(),
"ibm_metrics_router_settings": metricsrouter.ResourceIBMMetricsRouterSettingsValidator(),
"ibm_logs_router_tenant": logsrouter.ResourceIbmLogsRouterTenantValidator(),
"ibm_satellite_endpoint": satellite.ResourceIBMSatelliteEndpointValidator(),
"ibm_cbr_zone": contextbasedrestrictions.ResourceIBMCbrZoneValidator(),
"ibm_cbr_rule": contextbasedrestrictions.ResourceIBMCbrRuleValidator(),
Expand Down
11 changes: 11 additions & 0 deletions ibm/service/logsrouter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Terraform IBM Provider
<!-- markdownlint-disable MD026 -->
This area is primarily for IBM provider contributors and maintainers. For information on _using_ Terraform and the IBM provider, see the links below.


## Handy Links
* [Find out about contributing](../../../CONTRIBUTING.md) to the IBM provider!
* IBM Provider Docs: [Home](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs)
* IBM Provider Docs: [One of the resources](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/logs_router_tenant)
* IBM API Docs: [IBM API Docs for IBM Cloud Logs Router](https://test.cloud.ibm.com/apidocs/logs-router-service-api)
* IBM SDK: [IBM SDK for IBM Cloud Logs Router](https://github.com/IBM/logs-router-go-sdk)
Loading

0 comments on commit c393b56

Please sign in to comment.