Skip to content

Commit

Permalink
feat(live): live domain resource support new field is_ipv6 (#6095)
Browse files Browse the repository at this point in the history
  • Loading branch information
deer-hang authored Dec 26, 2024
1 parent c5fb0d8 commit 4e33749
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 35 deletions.
3 changes: 3 additions & 0 deletions docs/resources/live_domain.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ The following arguments are supported:
* `ingest_domain_name` - (Optional, String) Specifies the ingest domain name, which associates with the streaming
domain name to push streams to nearby CDN nodes.

* `is_ipv6` - (Optional, Bool) Specifies whether enable IPv6 switch. Defaults to **false**.
This field can only be edited when `status` is **on**.

* `status` - (Optional, String) Specifies status of the domain name. The options are as follows:
+ **on**: enable the domain name.
+ **off**: disable the domain name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ func getDomainResourceFunc(conf *config.Config, state *terraform.ResourceState)
func TestAccDomain_basic(t *testing.T) {
var obj model.CreateDomainMappingResponse

pushDomainName := fmt.Sprintf("%s.huaweicloud.com", acceptance.RandomAccResourceNameWithDash())
pullDomainName := fmt.Sprintf("%s.huaweicloud.com", acceptance.RandomAccResourceNameWithDash())
pushResourceName := "huaweicloud_live_domain.ingestDomain"
pullResourceName := "huaweicloud_live_domain.streamingDomain"
ingestDomainName := fmt.Sprintf("%s.huaweicloud.com", acceptance.RandomAccResourceNameWithDash())
streamingDomainName := fmt.Sprintf("%s.huaweicloud.com", acceptance.RandomAccResourceNameWithDash())
ingestResourceName := "huaweicloud_live_domain.ingestDomain"
streamingResourceName := "huaweicloud_live_domain.streamingDomain"

rc := acceptance.InitResourceCheck(
pushResourceName,
ingestResourceName,
&obj,
getDomainResourceFunc,
)
Expand All @@ -45,42 +45,44 @@ func TestAccDomain_basic(t *testing.T) {
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testDomain_basic(pushDomainName, pullDomainName),
Config: testDomain_basic(ingestDomainName, streamingDomainName),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(pushResourceName, "name", pushDomainName),
resource.TestCheckResourceAttr(pushResourceName, "type", "push"),
resource.TestCheckResourceAttr(pushResourceName, "status", "on"),
resource.TestCheckResourceAttr(pushResourceName, "service_area", "mainland_china"),
resource.TestCheckResourceAttr(pushResourceName, "enterprise_project_id", acceptance.HW_ENTERPRISE_PROJECT_ID_TEST),

resource.TestCheckResourceAttr(pullResourceName, "name", pullDomainName),
resource.TestCheckResourceAttr(pullResourceName, "type", "pull"),
resource.TestCheckResourceAttr(pullResourceName, "status", "on"),
resource.TestCheckResourceAttr(pullResourceName, "ingest_domain_name", pushDomainName),
resource.TestCheckResourceAttr(pullResourceName, "service_area", "outside_mainland_china"),
resource.TestCheckResourceAttr(pullResourceName, "enterprise_project_id", acceptance.HW_ENTERPRISE_PROJECT_ID_TEST),
resource.TestCheckResourceAttr(ingestResourceName, "name", ingestDomainName),
resource.TestCheckResourceAttr(ingestResourceName, "type", "push"),
resource.TestCheckResourceAttr(ingestResourceName, "status", "on"),
resource.TestCheckResourceAttr(ingestResourceName, "service_area", "mainland_china"),
resource.TestCheckResourceAttr(ingestResourceName, "is_ipv6", "true"),
resource.TestCheckResourceAttr(ingestResourceName, "enterprise_project_id", acceptance.HW_ENTERPRISE_PROJECT_ID_TEST),

resource.TestCheckResourceAttr(streamingResourceName, "name", streamingDomainName),
resource.TestCheckResourceAttr(streamingResourceName, "type", "pull"),
resource.TestCheckResourceAttr(streamingResourceName, "status", "on"),
resource.TestCheckResourceAttr(streamingResourceName, "ingest_domain_name", ingestDomainName),
resource.TestCheckResourceAttr(streamingResourceName, "service_area", "outside_mainland_china"),
resource.TestCheckResourceAttr(streamingResourceName, "enterprise_project_id", acceptance.HW_ENTERPRISE_PROJECT_ID_TEST),
),
},
{
Config: testDomain_basic_update(pushDomainName, pullDomainName),
Config: testDomain_basic_update(ingestDomainName, streamingDomainName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(pushResourceName, "name", pushDomainName),
resource.TestCheckResourceAttr(pushResourceName, "type", "push"),
resource.TestCheckResourceAttr(pushResourceName, "status", "on"),
resource.TestCheckResourceAttr(pushResourceName, "service_area", "mainland_china"),
resource.TestCheckResourceAttr(pushResourceName, "enterprise_project_id", acceptance.HW_ENTERPRISE_PROJECT_ID_TEST),

resource.TestCheckResourceAttr(pullResourceName, "name", pullDomainName),
resource.TestCheckResourceAttr(pullResourceName, "type", "pull"),
resource.TestCheckResourceAttr(pullResourceName, "status", "off"),
resource.TestCheckResourceAttr(pullResourceName, "ingest_domain_name", ""),
resource.TestCheckResourceAttr(pullResourceName, "service_area", "outside_mainland_china"),
resource.TestCheckResourceAttr(pullResourceName, "enterprise_project_id", acceptance.HW_ENTERPRISE_PROJECT_ID_TEST),
resource.TestCheckResourceAttr(ingestResourceName, "name", ingestDomainName),
resource.TestCheckResourceAttr(ingestResourceName, "type", "push"),
resource.TestCheckResourceAttr(ingestResourceName, "status", "on"),
resource.TestCheckResourceAttr(ingestResourceName, "service_area", "mainland_china"),
resource.TestCheckResourceAttr(ingestResourceName, "is_ipv6", "false"),
resource.TestCheckResourceAttr(ingestResourceName, "enterprise_project_id", acceptance.HW_ENTERPRISE_PROJECT_ID_TEST),

resource.TestCheckResourceAttr(streamingResourceName, "name", streamingDomainName),
resource.TestCheckResourceAttr(streamingResourceName, "type", "pull"),
resource.TestCheckResourceAttr(streamingResourceName, "status", "off"),
resource.TestCheckResourceAttr(streamingResourceName, "ingest_domain_name", ""),
resource.TestCheckResourceAttr(streamingResourceName, "service_area", "outside_mainland_china"),
resource.TestCheckResourceAttr(streamingResourceName, "enterprise_project_id", acceptance.HW_ENTERPRISE_PROJECT_ID_TEST),
),
},
{
ResourceName: pullResourceName,
ResourceName: streamingResourceName,
ImportState: true,
ImportStateVerify: true,
},
Expand All @@ -94,6 +96,7 @@ resource "huaweicloud_live_domain" "ingestDomain" {
name = "%[1]s"
type = "push"
service_area = "mainland_china"
is_ipv6 = true
enterprise_project_id = "%[3]s"
}
Expand All @@ -113,6 +116,7 @@ resource "huaweicloud_live_domain" "ingestDomain" {
name = "%[1]s"
type = "push"
service_area = "mainland_china"
is_ipv6 = false
enterprise_project_id = "%[3]s"
}
Expand Down
34 changes: 31 additions & 3 deletions huaweicloud/services/live/resource_huaweicloud_live_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ func ResourceDomain() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"is_ipv6": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"status": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -127,6 +132,12 @@ func resourceDomainCreate(ctx context.Context, d *schema.ResourceData, meta inte
}
}

if d.Get("is_ipv6").(bool) {
if err := updateIPv6Switch(client, d); err != nil {
return diag.Errorf("error updating Live domain IPv6 switch in creation operation: %s", err)
}
}

return resourceDomainRead(ctx, d, meta)
}

Expand Down Expand Up @@ -162,6 +173,7 @@ func resourceDomainRead(_ context.Context, d *schema.ResourceData, meta interfac
d.Set("cname", detail.DomainCname),
d.Set("service_area", flattenServiceAreaAttribute(detail.ServiceArea)),
d.Set("enterprise_project_id", detail.EnterpriseProjectId),
d.Set("is_ipv6", detail.IsIpv6),
)

return diag.FromErr(mErr.ErrorOrNil())
Expand All @@ -183,14 +195,12 @@ func resourceDomainUpdate(ctx context.Context, d *schema.ResourceData, meta inte
return diag.Errorf("error creating Live v1 client: %s", err)
}

domainName := d.Get("name").(string)

// associate the streaming domain name with an ingest domain Or delete association
if d.HasChange("ingest_domain_name") {
ingetstDomainNameOld, ingetstDomainName := d.GetChange("ingest_domain_name")

if ingetstDomainName == "" {
err = deleteAssociation(client, domainName, ingetstDomainNameOld.(string))
err = deleteAssociation(client, d.Get("name").(string), ingetstDomainNameOld.(string))
} else {
err = associatingDomain(d, client)
}
Expand All @@ -207,6 +217,12 @@ func resourceDomainUpdate(ctx context.Context, d *schema.ResourceData, meta inte
}
}

if d.HasChange("is_ipv6") {
if err := updateIPv6Switch(client, d); err != nil {
return diag.Errorf("error updating Live domain IPv6 switch in update operation: %s", err)
}
}

return resourceDomainRead(ctx, d, meta)
}

Expand Down Expand Up @@ -371,3 +387,15 @@ func updateStatus(ctx context.Context, d *schema.ResourceData, client *livev1.Li

return waitingForDomainStatus(ctx, client, d.Id(), respStatus, d.Timeout(schema.TimeoutUpdate))
}

func updateIPv6Switch(client *livev1.LiveClient, d *schema.ResourceData) error {
switchRequest := model.UpdateDomainIp6SwitchRequest{
Body: &model.DomainIpv6SwitchReq{
Domain: d.Get("name").(string),
IsIpv6: utils.Bool(d.Get("is_ipv6").(bool)),
},
}

_, err := client.UpdateDomainIp6Switch(&switchRequest)
return err
}

0 comments on commit 4e33749

Please sign in to comment.