-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(live): add a new resource to manage disable a push stream
- Loading branch information
1 parent
23f5ecb
commit 156bcd2
Showing
4 changed files
with
472 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,64 @@ | ||
--- | ||
subcategory: "Live" | ||
layout: "huaweicloud" | ||
page_title: "HuaweiCloud: huaweicloud_live_disable_push_stream" | ||
description: |- | ||
Manages a disable push stream resource within HuaweiCloud. | ||
--- | ||
|
||
# huaweicloud_live_disable_push_stream | ||
|
||
Manages a disable push stream resource within HuaweiCloud. | ||
|
||
-> Creating the resource indicates disable a push stream, deleting the resource indicates resume a push stream. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
variable "domain_name" {} | ||
variable "app_name" {} | ||
variable "stream_name" {} | ||
resource "huaweicloud_live_disable_push_stream" "test" { | ||
domain_name = var.domain_name | ||
app_name = var.app_name | ||
stream_name = var.stream_name | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource. | ||
If omitted, the provider-level region will be used. | ||
Changing this parameter will create a new resource. | ||
|
||
* `domain_name` - (Required, String, ForceNew) Specifies the ingest domain name of the disabling push stream. | ||
Changing this parameter will create a new resource. | ||
|
||
* `app_name` - (Required, String, ForceNew) Specifies the application name of the disabling push stream. | ||
Changing this parameter will create a new resource. | ||
|
||
* `stream_name` - (Required, String, ForceNew) Specifies the stream name of the disabling push stream. | ||
The stream name is not allowed to be `*`. | ||
Changing this parameter will create a new resource. | ||
|
||
* `resume_time` - (Optional, String) Specifies the time of resuming push stream. | ||
The time is in UTC, the format is **yyyy-mm-ddThh:mm:ssZ**. e.g. **2024-06-01T15:03:01Z** | ||
If this parameter is not specified, the default value is `7` days. The maximum value is `90` days. | ||
The `resume_time` cannot be earlier than the current time. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The resource ID, UUID format. | ||
|
||
## Import | ||
|
||
The resource can be imported using `domain_name`, `app_name` and `stream_name`, separated by slashes (/), e.g. | ||
|
||
```bash | ||
$ terraform import huaweicloud_live_disable_push_stream.test <domain_name>/<app_name>/<stream_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
130 changes: 130 additions & 0 deletions
130
huaweicloud/services/acceptance/live/resource_huaweicloud_live_disable_push_stream_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,130 @@ | ||
package live | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
|
||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" | ||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" | ||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/live" | ||
) | ||
|
||
func getDisablePushStreamFunc(cfg *config.Config, state *terraform.ResourceState) (interface{}, error) { | ||
region := acceptance.HW_REGION_NAME | ||
client, err := cfg.NewServiceClient("live", region) | ||
if err != nil { | ||
return nil, fmt.Errorf("error creating Live client: %s", err) | ||
} | ||
|
||
getRespBody, err := live.GetDisablePushStream(client, state.Primary.Attributes["domain_name"], | ||
state.Primary.Attributes["app_name"], state.Primary.Attributes["stream_name"]) | ||
if err != nil { | ||
return nil, fmt.Errorf("error retrieving disabled push stream: %s", err) | ||
} | ||
|
||
return getRespBody, nil | ||
} | ||
|
||
func TestAccDisablePushStream_basic(t *testing.T) { | ||
var ( | ||
disablePushStreamObj interface{} | ||
rName = "huaweicloud_live_disable_push_stream.test" | ||
domainName = fmt.Sprintf("%s.huaweicloud.com", acceptance.RandomAccResourceNameWithDash()) | ||
createTime = time.Now().UTC().Add(24 * time.Hour).Format("2006-01-02T15:04:05Z") | ||
updateTime = time.Now().UTC().Add(48 * time.Hour).Format("2006-01-02T15:04:05Z") | ||
) | ||
|
||
rc := acceptance.InitResourceCheck( | ||
rName, | ||
&disablePushStreamObj, | ||
getDisablePushStreamFunc, | ||
) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
acceptance.TestAccPreCheck(t) | ||
}, | ||
ProviderFactories: acceptance.TestAccProviderFactories, | ||
CheckDestroy: rc.CheckResourceDestroy(), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDisablePushStream_basic(domainName, createTime), | ||
Check: resource.ComposeTestCheckFunc( | ||
rc.CheckResourceExists(), | ||
resource.TestCheckResourceAttrPair(rName, "domain_name", "huaweicloud_live_domain.test", "name"), | ||
resource.TestCheckResourceAttr(rName, "app_name", "live"), | ||
resource.TestCheckResourceAttr(rName, "stream_name", "tf-test"), | ||
resource.TestCheckResourceAttr(rName, "resume_time", createTime), | ||
), | ||
}, | ||
{ | ||
Config: testAccDisablePushStream_update(domainName, updateTime), | ||
Check: resource.ComposeTestCheckFunc( | ||
rc.CheckResourceExists(), | ||
resource.TestCheckResourceAttr(rName, "resume_time", updateTime), | ||
), | ||
}, | ||
{ | ||
ResourceName: rName, | ||
ImportState: true, | ||
ImportStateVerify: false, | ||
ImportStateIdFunc: testAccDisablePushStreamImportState(rName), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDisablePushStream_basic(name, nowTime string) string { | ||
return fmt.Sprintf(` | ||
resource "huaweicloud_live_domain" "test" { | ||
name = "%[1]s" | ||
type = "push" | ||
} | ||
resource "huaweicloud_live_disable_push_stream" "test" { | ||
domain_name = huaweicloud_live_domain.test.name | ||
app_name = "live" | ||
stream_name = "tf-test" | ||
resume_time = "%[2]s" | ||
} | ||
`, name, nowTime) | ||
} | ||
|
||
func testAccDisablePushStream_update(name, updateTime string) string { | ||
return fmt.Sprintf(` | ||
resource "huaweicloud_live_domain" "test" { | ||
name = "%[1]s" | ||
type = "push" | ||
} | ||
resource "huaweicloud_live_disable_push_stream" "test" { | ||
domain_name = huaweicloud_live_domain.test.name | ||
app_name = "live" | ||
stream_name = "tf-test" | ||
resume_time = "%[2]s" | ||
} | ||
`, name, updateTime) | ||
} | ||
|
||
func testAccDisablePushStreamImportState(rName string) resource.ImportStateIdFunc { | ||
return func(s *terraform.State) (string, error) { | ||
var domainName, appName, streamName string | ||
rs, ok := s.RootModule().Resources[rName] | ||
if !ok { | ||
return "", fmt.Errorf("resource (%s) not found", rName) | ||
} | ||
|
||
domainName = rs.Primary.Attributes["domain_name"] | ||
appName = rs.Primary.Attributes["app_name"] | ||
streamName = rs.Primary.Attributes["stream_name"] | ||
if domainName == "" || appName == "" || streamName == "" { | ||
return "", fmt.Errorf("invalid format specified for import ID, "+ | ||
"want '<domain_name>/<app_name>/<stream_name>',but got '%s/%s/%s'", domainName, appName, streamName) | ||
} | ||
return fmt.Sprintf("%s/%s/%s", domainName, appName, streamName), nil | ||
} | ||
} |
Oops, something went wrong.