-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
8d2abfc
commit 87250f1
Showing
7 changed files
with
585 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
195 changes: 195 additions & 0 deletions
195
opentelekomcloud/acceptance/rms/resource_opentelekomcloud_rms_resource_recorder_v1_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) |
Oops, something went wrong.