Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ website/vendor
*.old
vendor/
*.lock.hcl
.envrc

# Test exclusions
!command/test-fixtures/**/*.tfstate
Expand All @@ -46,4 +47,4 @@ vendor/
!deleteaddon.sh
!deletecrd.sh
!updatecrd.sh
!updateodf.sh
!updateodf.sh
169 changes: 98 additions & 71 deletions examples/ibm-metrics-router/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# Example for IBM Cloud Metrics Routing
# Examples for Metrics Routing API Version 3

This example illustrates how to use the MetricsRouterV3
These examples illustrate how to use the resources and data sources associated with Metrics Routing API Version 3.

These types of resources are supported:
The following resources are supported:
* ibm_metrics_router_target
* ibm_metrics_router_route
* ibm_metrics_router_settings

* metrics_router_target
* metrics_router_route
* metrics_router_settings
The following data sources are supported:
* ibm_metrics_router_targets
* ibm_metrics_router_routes

## Usage

To run this example you need to execute:
To run this example, execute the following commands:

```bash
$ terraform init
Expand All @@ -20,30 +23,69 @@ $ terraform apply

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

## Metrics Routing API Version 3 resources

## MetricsRouterV3 resources

metrics_router_target resource:
### Resource: ibm_metrics_router_target

```hcl
resource "metrics_router_target" "metrics_router_target_instance" {
resource "ibm_metrics_router_target" "metrics_router_target_instance" {
name = var.metrics_router_target_name
destination_crn = var.metrics_router_target_destination_crn
region = var.metrics_router_target_region
managed_by = var.metrics_router_target_managed_by
}
```
metrics_router_route resource:

#### Inputs

| Name | Description | Type | Required |
|------|-------------|------|---------|
| ibmcloud\_api\_key | IBM Cloud API key | `string` | true |
| name | The name of the target resource. | `string` | true |
| destination_crn | Cloud Resource Name (CRN) of the destination resource. Ensure you have a service authorization between IBM Cloud Metrics Routing and your Cloud resource. See [service-to-service authorization](https://cloud.ibm.com/docs/metrics-router?topic=metrics-router-target-monitoring&interface=ui#target-monitoring-ui) for details. | `string` | true |
| region | Include this optional field if you used it to create a target in a different region other than the one you are connected. | `string` | false |
| managed_by | Present when the target is enterprise-managed (`managed_by: enterprise`). For account-managed targets this field is omitted. | `string` | false |

#### Outputs

| Name | Description |
|------|-------------|
| crn | The crn of the target resource. |
| target_type | The type of the target. |
| created_at | The timestamp of the target creation time. |
| updated_at | The timestamp of the target last updated time. |

### Resource: ibm_metrics_router_route

```hcl
resource "metrics_router_route" "metrics_router_route_instance" {
resource "ibm_metrics_router_route" "metrics_router_route_instance" {
name = var.metrics_router_route_name
rules = var.metrics_router_route_rules
managed_by = var.metrics_router_route_managed_by
}
```
metrics_router_settings resource:

#### Inputs

| Name | Description | Type | Required |
|------|-------------|------|---------|
| ibmcloud\_api\_key | IBM Cloud API key | `string` | true |
| name | The name of the route. | `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 |
| managed_by | Present when the route is enterprise-managed (`managed_by: enterprise`). | `string` | false |

#### Outputs

| Name | Description |
|------|-------------|
| crn | The crn of the route resource. |
| created_at | The timestamp of the route creation time. |
| updated_at | The timestamp of the route last updated time. |

### Resource: ibm_metrics_router_settings

```hcl
resource "metrics_router_settings" "metrics_router_settings_instance" {
resource "ibm_metrics_router_settings" "metrics_router_settings_instance" {
default_targets = var.metrics_router_settings_default_targets
permitted_target_regions = var.metrics_router_settings_permitted_target_regions
primary_metadata_region = var.metrics_router_settings_primary_metadata_region
Expand All @@ -52,23 +94,59 @@ resource "metrics_router_settings" "metrics_router_settings_instance" {
}
```

## MetricsRouterV3 Data sources
#### Inputs

| Name | Description | Type | Required |
|------|-------------|------|---------|
| ibmcloud\_api\_key | IBM Cloud API key | `string` | true |
| default_targets | A list of default target references. Enterprise-managed targets are not supported. | `list()` | false |
| permitted_target_regions | If present then only these regions may be used to define a target. | `list(string)` | false |
| primary_metadata_region | To store all your meta data in a single region. | `string` | false |
| backup_metadata_region | To backup all your meta data in a different region. | `string` | false |
| private_api_endpoint_only | If you set this true then you cannot access api through public network. | `bool` | false |

## Metrics Routing API Version 3 data sources

metrics_router_targets data source:
### Data source: ibm_metrics_router_targets

```hcl
data "metrics_router_targets" "metrics_router_targets_instance" {
data "ibm_metrics_router_targets" "metrics_router_targets_instance" {
name = var.metrics_router_targets_name
}
```
metrics_router_routes data source:

#### Inputs

| Name | Description | Type | Required |
|------|-------------|------|---------|
| name | The name of the target resource. | `string` | false |

#### Outputs

| Name | Description |
|------|-------------|
| targets | A list of target resources. |

### Data source: ibm_metrics_router_routes

```hcl
data "metrics_router_routes" "metrics_router_routes_instance" {
data "ibm_metrics_router_routes" "metrics_router_routes_instance" {
name = var.metrics_router_routes_name
}
```

#### Inputs

| Name | Description | Type | Required |
|------|-------------|------|---------|
| name | The name of the route. | `string` | false |

#### Outputs

| Name | Description |
|------|-------------|
| routes | A list of route resources. |

## Assumptions

1. TODO
Expand All @@ -88,54 +166,3 @@ data "metrics_router_routes" "metrics_router_routes_instance" {
| Name | Version |
|------|---------|
| ibm | 1.13.1 |

## Inputs

### Target

| Name | Description | Type | Required |
|------|-------------|------|---------|
| ibmcloud\_api\_key | IBM Cloud API key | `string` | true |
| name | The name of the target. The name must be 1000 characters or less, and cannot include any special characters other than `(space) - . _ :`. Do not include any personal identifying information (PII) in any resource names. | `string` | true |
| destination_crn | The CRN of the destination resource. Ensure you have a service authorization between IBM Cloud Metrics Routing and your Cloud resource. Read [S2S authorization](https://cloud.ibm.com/docs/metrics-router?topic=metrics-router-target-monitoring&interface=ui#target-monitoring-ui) for details.| `string` | true |
| region | Include this optional field if you want to create a target in a different region other than the one you are connected. | `string` | false |

### Route

| Name | Description | Type | Required |
|------|-------------|------|---------|
| name | The name of the route. The name must be 1000 characters or less and cannot include any special characters other than `(space) - . _ :`. Do not include any personal identifying information (PII) in any resource names. | `string` | true |
| rules | Routing rules that will be evaluated in their order of the array. | `list()` | true |

### Settings

| Name | Description | Type | Required |
|------|-------------|------|---------|
| default_targets | A list of default target references. | `list()` | false |
| permitted_target_regions | If present then only these regions may be used to define a target. | `list(string)` | false |
| primary_metadata_region | To store all your meta data in a single region. For new accounts, all target / route creation will fail until primary_metadata_region is set. | `string` | false |
| backup_metadata_region | To backup all your meta data in a different region. | `string` | false |
| private_api_endpoint_only | If you set this true then you cannot access api through public network. | `bool` | false |

### Data Source For Target

| Name | Description | Type | Required |
|------|-------------|------|---------|
| name | The name of the target resource. | `string` | false |

### Data Source For Route

| Name | Description | Type | Required |
|------|-------------|------|---------|
| name | The name of the route. | `string` | false |

## Outputs


| Name | Description |
|------|-------------|
| metrics_router_target | metrics_router_target object |
| metrics_router_route | metrics_router_route object |
| metrics_router_settings | metrics_router_settings object |
| metrics_router_targets | metrics_router_targets object |
| metrics_router_routes | metrics_router_routes object |
30 changes: 29 additions & 1 deletion examples/ibm-metrics-router/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ provider "ibm" {
ibmcloud_api_key = var.ibmcloud_api_key
}



// Provision metrics_router_target resource instance
resource "ibm_metrics_router_target" "metrics_router_target_instance" {
name = var.metrics_router_target_name
destination_crn = var.metrics_router_target_destination_crn
region = var.metrics_router_target_region

}

// Provision metrics_router_route resource instance
Expand All @@ -25,10 +28,35 @@ resource "ibm_metrics_router_route" "metrics_router_route_instance" {
}
}

// Provision metrics_router_target resource instance
resource "ibm_metrics_router_target" "metrics_router_target_instance_enterprise" {
name = var.metrics_router_target_name
destination_crn = var.metrics_router_target_destination_crn
region = var.metrics_router_target_region
managed_by = "enterprise"
}

// Provision metrics_router_route resource instance
resource "ibm_metrics_router_route" "metrics_router_route_instanc_enterprise" {
name = var.metrics_router_route_name
rules {
action = "send"
targets {
id = ibm_metrics_router_target.metrics_router_target_instance.id
}
inclusion_filters {
operand = "location"
operator = "is"
values = [ "us-south" ]
}
}
managed_by = "enterprise"
}

// Provision metrics_router_settings resource instance
resource "ibm_metrics_router_settings" "metrics_router_settings_instance" {
default_targets {
id = ibm_metrics_router_target.metrics_router_target_instance.id
id = ibm_metrics_router_target.metrics_router_target_instance.id
}
permitted_target_regions = var.metrics_router_settings_permitted_target_regions
primary_metadata_region = var.metrics_router_settings_primary_metadata_region
Expand Down
12 changes: 6 additions & 6 deletions examples/ibm-metrics-router/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// This allows metrics_router_target data to be referenced by other resources and the terraform CLI
// Modify this if only certain data should be exposed
// This output allows metrics_router_target data to be referenced by other resources and the terraform CLI
// Modify this output if only certain data should be exposed
output "ibm_metrics_router_target" {
value = ibm_metrics_router_target.metrics_router_target_instance
description = "metrics_router_target resource instance"
}
// This allows metrics_router_route data to be referenced by other resources and the terraform CLI
// Modify this if only certain data should be exposed
// This output allows metrics_router_route data to be referenced by other resources and the terraform CLI
// Modify this output if only certain data should be exposed
output "ibm_metrics_router_route" {
value = ibm_metrics_router_route.metrics_router_route_instance
description = "metrics_router_route resource instance"
}
// This allows metrics_router_settings data to be referenced by other resources and the terraform CLI
// Modify this if only certain data should be exposed
// This output allows metrics_router_settings data to be referenced by other resources and the terraform CLI
// Modify this output if only certain data should be exposed
output "ibm_metrics_router_settings" {
value = ibm_metrics_router_settings.metrics_router_settings_instance
description = "metrics_router_settings resource instance"
Expand Down
14 changes: 10 additions & 4 deletions examples/ibm-metrics-router/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,34 @@ variable "ibmcloud_api_key" {

// Resource arguments for metrics_router_target
variable "metrics_router_target_name" {
description = "The name of the target. The name must be 1000 characters or less, and cannot include any special characters other than `(space) - . _ :`. Do not include any personal identifying information (PII) in any resource names."
description = "The name of the target resource."
type = string
default = "my-mr-target"
}
variable "metrics_router_target_destination_crn" {
description = "The CRN of a destination service instance or resource. Ensure you have a service authorization between IBM Cloud Metrics Routing and your Cloud resource. Read [S2S authorization](https://cloud.ibm.com/docs/metrics-router?topic=metrics-router-target-monitoring&interface=ui#target-monitoring-ui) for details."
description = "Cloud Resource Name (CRN) of the destination resource. Ensure you have a service authorization between IBM Cloud Metrics Routing and your Cloud resource. See [service-to-service authorization](https://cloud.ibm.com/docs/metrics-router?topic=metrics-router-target-monitoring&interface=ui#target-monitoring-ui) for details."
type = string
default = "crn:v1:bluemix:public:sysdig-monitor:us-south:a/0be5ad401ae913d8ff665d92680664ed:22222222-2222-2222-2222-222222222222::"
}
variable "metrics_router_target_region" {
description = "Include this optional field if you want to create a target in a different region other than the one you are connected."
description = "Include this optional field if you used it to create a target in a different region other than the one you are connected."
type = string
default = "us-south"
}
variable "metrics_router_target_managed_by" {
description = "Present when the target is enterprise-managed (`managed_by: enterprise`). For account-managed targets this field is omitted."
type = string
default = "enterprise"
}

// Resource arguments for metrics_router_route
variable "metrics_router_route_name" {
description = "The name of the route. The name must be 1000 characters or less and cannot include any special characters other than `(space) - . _ :`. Do not include any personal identifying information (PII) in any resource names."
description = "The name of the route."
type = string
default = "my-route"
}


// Resource arguments for metrics_router_settings
variable "metrics_router_settings_permitted_target_regions" {
description = "If present then only these regions may be used to define a target."
Expand Down
9 changes: 7 additions & 2 deletions examples/ibm-metrics-router/versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
terraform {
required_version = ">= 0.12"
}
required_version = ">= 1.0"
required_providers {
ibm = {
source = "IBM-Cloud/ibm"
}
}
}
Loading