Skip to content

Commit

Permalink
RMS: resource recorder (#2693)
Browse files Browse the repository at this point in the history
RMS: resource recorder

Summary of the Pull Request
Resource recorder implementation
PR Checklist

 Refers to: #2659
 Tests added/passed.
 Documentation updated.
 Schema updated.
 Release notes added.

Acceptance Steps Performed
=== RUN   TestAccRecorder_basic
=== PAUSE TestAccRecorder_basic
=== CONT  TestAccRecorder_basic
--- PASS: TestAccRecorder_basic (92.57s)
PASS

Process finished with the exit code 0

Reviewed-by: Aloento
Reviewed-by: Anton Sidelnikov
  • Loading branch information
artem-lifshits authored Oct 25, 2024
1 parent 8d2abfc commit 87250f1
Show file tree
Hide file tree
Showing 7 changed files with 585 additions and 0 deletions.
122 changes: 122 additions & 0 deletions docs/resources/rms_resource_recorder_v1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
---
subcategory: "Config"
layout: "opentelekomcloud"
page_title: "OpenTelekomCloud: opentelekomcloud_resource_recorder_v1"
sidebar_current: "docs-opentelekomcloud-resource-recorder-v1"
description: ""
---

Up-to-date reference of API arguments for RMS Resource Recorder you can get at
[documentation portal](https://docs.otc.t-systems.com/config/api-ref/apis/resource_recorder/index.html#rms-04-0200)

# opentelekomcloud_rms_resource_recorder_v1

Manages a RMS recorder resource within OpenTelekomCloud.

-> Only one resource recorder can be configured.

## Example Usage

### Recorder with All Supported Resources

```hcl
variable "topic_urn" {}
variable "bucket_name" {}
variable "delivery_region" {}
resource "opentelekomcloud_rms_resource_recorder_v1" "test" {
agency_name = "rms_tracker_agency"
selector {
all_supported = true
}
obs_channel {
bucket = var.bucket_name
region = var.delivery_region
}
smn_channel {
topic_urn = var.topic_urn
}
}
```

### Recorder with Specified Resources

```hcl
variable "bucket_name" {}
variable "delivery_region" {}
resource "opentelekomcloud_rms_resource_recorder_v1" "test" {
agency_name = "rms_tracker_agency"
selector {
all_supported = false
resource_types = ["vpc.vpcs", "rds.instances", "dms.kafkas", "dms.rabbitmqs", "dms.queues"]
}
obs_channel {
bucket = var.bucket_name
region = var.delivery_region
}
}
```

## Argument Reference

The following arguments are supported:

* `agency_name` - (Required, String) Specifies the IAM agency name which must include permissions
for sending notifications through SMN and for writing data into OBS.

* `selector` - (Required, List) Specifies configurations of resource selector.
The [object](#Recorder_SelectorConfigBody) structure is documented below.

* `obs_channel` - (Optional, List) Specifies configurations of the OBS bucket used for data dumping.
The [object](#Recorder_TrackerOBSChannelConfigBody) structure is documented below.

* `smn_channel` - (Optional, List) Specifies configurations of the SMN channel used to send notifications.
The [object](#Recorder_TrackerSMNChannelConfigBody) structure is documented below.

-> At least one `obs_channel` or `smn_channel` must be configured.

<a name="Recorder_SelectorConfigBody"></a>
The `selector` block supports:

* `all_supported` - (Required, Bool) Specifies whether to select all supported resources.

* `resource_types` - (Optional, List) Specifies the resource type list.

<a name="Recorder_TrackerOBSChannelConfigBody"></a>
The `obs_channel` block supports:

* `bucket` - (Required, String) Specifies the OBS bucket name used for data dumping.

* `region` - (Required, String) Specifies the region where this bucket is located.

* `bucket_prefix` - (Optional, String) Specifies the OBS bucket prefix.

<a name="Recorder_TrackerSMNChannelConfigBody"></a>
The `smn_channel` block supports:

* `topic_urn` - (Required, String) Specifies the SMN topic URN used to send notifications.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The resource ID.

* `retention_period` - The number of days for data storage.

* `region` - The region where this SMN topic is located.

* `project_id` - The project ID where this SMN topic is located.

## Import

The recorder can be imported by providing `domain_id` as resource ID, e.g.

```bash
$ terraform import opentelekomcloud_rms_resource_recorder_v1.test domain_id
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
package rms

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/rms/recorder"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/common"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/env"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/common/cfg"
)

func getRecorderResourceFunc(conf *cfg.Config, state *terraform.ResourceState) (interface{}, error) {
client, err := conf.RmsV1Client(env.OS_REGION_NAME)
if err != nil {
return nil, fmt.Errorf("error creating RMS V1 client: %s", err)
}

return recorder.GetRecorder(client, state.Primary.ID)
}

func TestAccRecorder_basic(t *testing.T) {
var obj interface{}

name := "rms-test-" + acctest.RandString(5)
rName := "opentelekomcloud_rms_resource_recorder_v1.test"

rc := common.InitResourceCheck(
rName,
&obj,
getRecorderResourceFunc,
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { common.TestAccPreCheck(t) },
ProviderFactories: common.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testRecorder_with_obs_partial(name),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(rName, "agency_name", "rms_tracker_agency"),
resource.TestCheckResourceAttr(rName, "selector.0.all_supported", "false"),
resource.TestCheckResourceAttr(rName, "selector.0.resource_types.#", "4"),
resource.TestCheckResourceAttrSet(rName, "obs_channel.0.region"),
resource.TestCheckResourceAttrPair(rName, "obs_channel.0.bucket",
"opentelekomcloud_obs_bucket.test", "bucket"),
),
},
{
Config: testRecorder_with_obs_all(name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(rName, "agency_name", "rms_tracker_agency"),
resource.TestCheckResourceAttr(rName, "selector.0.all_supported", "true"),
resource.TestCheckResourceAttr(rName, "selector.0.resource_types.#", "0"),
),
},
{
Config: testRecorder_with_smn(name),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(rName, "agency_name", "rms_tracker_agency"),
resource.TestCheckResourceAttr(rName, "selector.0.all_supported", "true"),
resource.TestCheckResourceAttrSet(rName, "smn_channel.0.region"),
resource.TestCheckResourceAttrSet(rName, "smn_channel.0.project_id"),
resource.TestCheckResourceAttrPair(rName, "smn_channel.0.topic_urn",
"opentelekomcloud_smn_topic_v2.test", "topic_urn"),
),
},
{
Config: testRecorder_with_all(name),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttrPair(rName, "smn_channel.0.topic_urn",
"opentelekomcloud_smn_topic_v2.test", "topic_urn"),
resource.TestCheckResourceAttrPair(rName, "obs_channel.0.bucket",
"opentelekomcloud_obs_bucket.test", "bucket"),
),
},
{
ResourceName: rName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testRecorder_base(name string) string {
return fmt.Sprintf(`
resource "opentelekomcloud_obs_bucket" "test" {
bucket = "%[1]s"
storage_class = "STANDARD"
acl = "private"
force_destroy = true
tags = {
env = "rms_recorder_channel"
key = "value"
}
}
resource "opentelekomcloud_smn_topic_v2" "test" {
name = "%[1]s"
tags = {
env = "rms_recorder_channel"
key = "value"
}
}
`, name)
}

func testRecorder_with_obs_partial(name string) string {
return fmt.Sprintf(`
%s
resource "opentelekomcloud_rms_resource_recorder_v1" "test" {
agency_name = "rms_tracker_agency"
selector {
all_supported = false
resource_types = ["vpc.vpcs", "rds.instances", "dms.kafkas", "dms.queues"]
}
obs_channel {
bucket = opentelekomcloud_obs_bucket.test.id
region = "%s"
}
}
`, testRecorder_base(name), env.OS_REGION_NAME)
}

func testRecorder_with_obs_all(name string) string {
return fmt.Sprintf(`
%s
resource "opentelekomcloud_rms_resource_recorder_v1" "test" {
agency_name = "rms_tracker_agency"
selector {
all_supported = true
}
obs_channel {
bucket = opentelekomcloud_obs_bucket.test.id
region = "%s"
}
}
`, testRecorder_base(name), env.OS_REGION_NAME)
}

func testRecorder_with_smn(name string) string {
return fmt.Sprintf(`
%s
resource "opentelekomcloud_rms_resource_recorder_v1" "test" {
agency_name = "rms_tracker_agency"
selector {
all_supported = true
}
smn_channel {
topic_urn = opentelekomcloud_smn_topic_v2.test.topic_urn
}
}
`, testRecorder_base(name))
}

func testRecorder_with_all(name string) string {
return fmt.Sprintf(`
%s
resource "opentelekomcloud_rms_resource_recorder_v1" "test" {
agency_name = "rms_tracker_agency"
selector {
all_supported = true
}
obs_channel {
bucket = opentelekomcloud_obs_bucket.test.id
region = "%s"
}
smn_channel {
topic_urn = opentelekomcloud_smn_topic_v2.test.topic_urn
}
}
`, testRecorder_base(name), env.OS_REGION_NAME)
}
7 changes: 7 additions & 0 deletions opentelekomcloud/common/cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,13 @@ func (c *Config) RdsV3Client(region string) (*golangsdk.ServiceClient, error) {
})
}

func (c *Config) RmsV1Client(region string) (*golangsdk.ServiceClient, error) {
return openstack.NewRmsServiceV1(c.HwClient, golangsdk.EndpointOpts{
Region: region,
Availability: c.getEndpointType(),
})
}

func (c *Config) SdrsV1Client(region string) (*golangsdk.ServiceClient, error) {
return openstack.NewSDRSV1(c.HwClient, golangsdk.EndpointOpts{
Region: region,
Expand Down
2 changes: 2 additions & 0 deletions opentelekomcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/services/nat"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/services/obs"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/services/rds"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/services/rms"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/services/rts"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/services/s3"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/services/sdrs"
Expand Down Expand Up @@ -524,6 +525,7 @@ func Provider() *schema.Provider {
"opentelekomcloud_rds_maintenance_v3": rds.ResourceRdsMaintenanceV3(),
"opentelekomcloud_rds_parametergroup_v3": rds.ResourceRdsConfigurationV3(),
"opentelekomcloud_rds_read_replica_v3": rds.ResourceRdsReadReplicaV3(),
"opentelekomcloud_rms_resource_recorder_v1": rms.ResourceRmsResourceRecorderV1(),
"opentelekomcloud_rts_software_deployment_v1": rts.ResourceRtsSoftwareDeploymentV1(),
"opentelekomcloud_rts_software_config_v1": rts.ResourceSoftwareConfigV1(),
"opentelekomcloud_rts_stack_v1": rts.ResourceRTSStackV1(),
Expand Down
6 changes: 6 additions & 0 deletions opentelekomcloud/services/rms/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package rms

const (
errCreationRMSV1Client = "error creating OpenTelekomCloud RMS v1 client: %w"
rmsClientV1 = "rms-v1-client"
)
Loading

0 comments on commit 87250f1

Please sign in to comment.