Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(live): Optimize resource code to recording resource #6033

Merged
merged 1 commit into from
Dec 18, 2024
Merged
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
46 changes: 25 additions & 21 deletions docs/resources/live_recording.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
subcategory: "Live"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_live_recording"
description: ""
description: |-
Manages a recording template within HuaweiCloud Live.
---

# huaweicloud_live_recording
Expand Down Expand Up @@ -56,21 +57,21 @@ If omitted, the provider-level region will be used. Changing this parameter will
* `type` - (Optional, String, ForceNew) Specifies the types of recording notifications. The options are as follows:
+ **CONTINUOUS_RECORD**: continuous recording. Recording is triggered once streams are pushed to the recording system.
+ **COMMAND_RECORD**: command-based recording. Tenants need to run commands to start and stop recording after streams
are pushed to the recording system.
are pushed to the recording system.

Defaults to `CONTINUOUS_RECORD`. Changing this parameter will create a new resource.

* `obs` - (Required, List) Specifies the obs for storing recordings.
The [obs](#recording_obs) structure is documented below.
The [obs](#recording_obs) structure is documented below.

* `hls` - (Optional, List) Specifies the HLS configuration rule for storing recording as HLS.
The [hls](#recording_HLS) structure is documented below.
The [hls](#recording_HLS) structure is documented below.

* `flv` - (Optional, List) Specifies the FLV configuration rule for storing recording as FLV.
The [flv](#recording_FLV_MP4) structure is documented below.
The [flv](#recording_FLV_MP4) structure is documented below.

* `mp4` - (Optional, List) Specifies the MP4 configuration rule for storing recording as MP4.
The [mp4](#recording_FLV_MP4) structure is documented below.
The [mp4](#recording_FLV_MP4) structure is documented below.

-> At least one of `hls`, `flv`, `mp4` must be specified.

Expand All @@ -87,35 +88,38 @@ The `obs` block supports:
The `hls` block supports:

* `recording_length` - (Required, Int) Specifies the recording length. Value range: `15` ~ `720`, unit: `minute`.
A stream exceeding the recording length will generate a new recording.
A stream exceeding the recording length will generate a new recording.

* `file_naming` - (Optional, String) Specifies the path and file name prefix of an M3U8 file. The default value is
`Record/{publish_domain}/{app}/{record_type}/{record_format}/{stream}_{file_start_time}/{stream}_{file_start_time}`.
`Record/{publish_domain}/{app}/{record_type}/{record_format}/{stream}_{file_start_time}/{stream}_{file_start_time}`.

* `ts_file_naming` - (Optional, String) Specifies TS file name prefix.
The default value is `{file_start_time_unix}_{file_end_time_unix}_{ts_sequence_number}`.
The default value is `{file_start_time_unix}_{file_end_time_unix}_{ts_sequence_number}`.

* `record_slice_duration` - (Optional, Int) Specifies the TS slice duration for HLS recording.
Value range: `2` ~ `60`, unit: `second`. Defaults to `10`.

* `max_stream_pause_length` - (Optional, Int) Specifies the interval threshold for combining HLS chunks. If the stream
pause length exceeds the value of this parameter, a new recording is generated.
Value range: `-1` ~ `300`, unit: `second`.
If the value is set to `0`, a new file will be generated once the stream is interrupted.
If the value is set to `-1`, the HLS chunks will be combined to the previous file generated within 30 days after
the same stream is recovered.
Defaults to `0`.
pause length exceeds the value of this parameter, a new recording is generated.
Value range: `-1` ~ `300`, unit: `second`. Defaults to `0`.

-> 1. If the value is set to `0`, a new file will be generated once the stream is interrupted.
<br/>2. If the value is set to `-1`, the HLS chunks will be combined to the previous file generated within `30` days
after the same stream is recovered.

<a name="recording_FLV_MP4"></a>
The `flv` and `mp4` block support:

* `recording_length` - (Required, Int) Specifies the recording length. Value range: `15` ~ `180`, unit: `minute`.
A stream exceeding the recording length will generate a new recording.
A stream exceeding the recording length will generate a new recording.

* `file_naming` - (Optional, String) Specifies the path and file name prefix of a recording file. The default value is
`Record/{publish_domain}/{app}/{record_type}/{record_format}/{stream}_{file_start_time}/{file_start_time}`.
`Record/{publish_domain}/{app}/{record_type}/{record_format}/{stream}_{file_start_time}/{file_start_time}`.

* `max_stream_pause_length` - (Optional, Int) Specifies the interval threshold for combining recording chunks. If the
stream pause length exceeds the value of this parameter, a new recording is generated.
Value range: `0` ~ `300`, unit: `second`.
If the value is set to `0`, a new file will be generated once the stream is interrupted. Defaults to `0`.
stream pause length exceeds the value of this parameter, a new recording is generated.
Value range: `0` ~ `300`, unit: `second`. Defaults to `0`.
If the value is set to `0`, a new file will be generated once the stream is interrupted.

## Attribute Reference

Expand All @@ -128,5 +132,5 @@ In addition to all arguments above, the following attributes are exported:
Recording templates can be imported using the `id`, e.g.

```bash
$ terraform import huaweicloud_live_recording.test 55534eaa-533a-419d-9b40-ec427ea7195a
$ terraform import huaweicloud_live_recording.test <id>
```
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ func getRecordingResourceFunc(conf *config.Config, state *terraform.ResourceStat
func TestAccRecording_basic(t *testing.T) {
var obj model.ShowRecordRuleRequest

name := acceptance.RandomAccResourceNameWithDash()
pushDomainName := fmt.Sprintf("%s.huaweicloud.com", name)
rName := "huaweicloud_live_recording.test"

rc := acceptance.InitResourceCheck(
Expand All @@ -35,15 +33,18 @@ func TestAccRecording_basic(t *testing.T) {
)

resource.Test(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckLiveIngestDomainName(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testRecording_basic(pushDomainName, name),
Config: testRecording_basic(),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(rName, "domain_name", pushDomainName),
resource.TestCheckResourceAttr(rName, "domain_name", acceptance.HW_LIVE_INGEST_DOMAIN_NAME),
resource.TestCheckResourceAttr(rName, "app_name", "live"),
resource.TestCheckResourceAttr(rName, "stream_name", "streamname"),
resource.TestCheckResourceAttr(rName, "type", "CONTINUOUS_RECORD"),
Expand All @@ -53,14 +54,16 @@ func TestAccRecording_basic(t *testing.T) {
),
},
{
Config: testRecording_basic_update(pushDomainName, name),
Config: testRecording_basic_update(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(rName, "domain_name", pushDomainName),
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(rName, "domain_name", acceptance.HW_LIVE_INGEST_DOMAIN_NAME),
resource.TestCheckResourceAttr(rName, "app_name", "live"),
resource.TestCheckResourceAttr(rName, "stream_name", "streamname"),
resource.TestCheckResourceAttr(rName, "type", "CONTINUOUS_RECORD"),
resource.TestCheckResourceAttr(rName, "obs.0.region", acceptance.HW_REGION_NAME),
resource.TestCheckResourceAttr(rName, "hls.0.recording_length", "120"),
resource.TestCheckResourceAttr(rName, "hls.0.record_slice_duration", "5"),
resource.TestCheckResourceAttrSet(rName, "hls.0.file_naming"),
),
},
Expand All @@ -73,10 +76,10 @@ func TestAccRecording_basic(t *testing.T) {
})
}

func testAccLiveObs(obsName string) string {
func testRecording_base() string {
return fmt.Sprintf(`
resource "huaweicloud_obs_bucket" "bucket" {
bucket = "%s"
bucket = "%[1]s"
acl = "private"
force_destroy = true
Expand All @@ -86,21 +89,23 @@ resource "huaweicloud_obs_bucket" "bucket" {
]
}
}
`, obsName)
}
func testRecording_basic(pushDomainName, obsName string) string {
obsConfig := testAccLiveObs(obsName)
return fmt.Sprintf(`
%s
resource "huaweicloud_live_bucket_authorization" "test" {
depends_on = [huaweicloud_obs_bucket.bucket]
resource "huaweicloud_live_domain" "ingestDomain" {
name = "%s"
type = "push"
bucket = "%[1]s"
}
`, acceptance.RandomAccResourceNameWithDash())
}

func testRecording_basic() string {
return fmt.Sprintf(`
%[1]s
resource "huaweicloud_live_recording" "test" {
domain_name = huaweicloud_live_domain.ingestDomain.name
depends_on = [huaweicloud_live_bucket_authorization.test]
domain_name = "%[2]s"
app_name = "live"
stream_name = "streamname"
type = "CONTINUOUS_RECORD"
Expand All @@ -114,21 +119,17 @@ resource "huaweicloud_live_recording" "test" {
recording_length = 120
}
}
`, obsConfig, pushDomainName)
`, testRecording_base(), acceptance.HW_LIVE_INGEST_DOMAIN_NAME)
}

func testRecording_basic_update(pushDomainName, obsName string) string {
obsConfig := testAccLiveObs(obsName)
func testRecording_basic_update() string {
return fmt.Sprintf(`
%s
resource "huaweicloud_live_domain" "ingestDomain" {
name = "%s"
type = "push"
}
%[1]s
resource "huaweicloud_live_recording" "test" {
domain_name = huaweicloud_live_domain.ingestDomain.name
depends_on = [huaweicloud_live_bucket_authorization.test]
domain_name = "%[2]s"
app_name = "live"
stream_name = "streamname"
type = "CONTINUOUS_RECORD"
Expand All @@ -139,8 +140,9 @@ resource "huaweicloud_live_recording" "test" {
}
hls {
recording_length = 120
recording_length = 120
record_slice_duration = 5
}
}
`, obsConfig, pushDomainName)
`, testRecording_base(), acceptance.HW_LIVE_INGEST_DOMAIN_NAME)
}
Loading
Loading