Skip to content

feat(er): supports new resource to update the attachment infos #6734

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
56 changes: 56 additions & 0 deletions docs/resources/er_attachment_update.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
subcategory: "Enterprise Router (ER)"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_er_attachment_update"
description: |-
Use this resource to update the basic attachment information within HuaweiCloud.
---

# huaweicloud_er_attachment_update

Use this resource to update the basic attachment information within HuaweiCloud.

-> This resource is only a one-time action resource for updating the attachment. Deleting this resource will not restore
the corresponding attachment configuration, but will only remove the resource information from the tfstate file.

## Example Usage

```hcl
variable "instance_id" {}
variable "attachment_id" {}
variable "new_attachment_name" {}

resource "huaweicloud_er_attachment_update" "test" {
instance_id = var.instance_id
attachment_id = var.attachment_id
name = var.new_attachment_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 creates a new resource.

* `instance_id` - (Required, String, NonUpdatable) Specifies the ID of the shared ER instance.

* `attachment_id` - (Required, String, NonUpdatable) Specifies the ID of the attachment to be accept or reject.

* `name` - (Optional, String) Specifies the new name of the attachment.
The valid length is limited from `1` to `64` characters, only English letters, Chinese characters, digits,
underscore (_), hyphens (-) and dots (.) allowed.

* `description` - (Optional, String) Specifies the new name of the attachment.
The valid length is limited from `1` to `255`, and the angle brackets (< and >) are not allowed.
The description do not restore with an empty value whether this parameter value is omitted or set empty.

-> At least one of parameter `name` and parameter `description` must be set.

## Attribute Reference

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

* `id` - The resource ID.
1 change: 1 addition & 0 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1913,6 +1913,7 @@ func Provider() *schema.Provider {

"huaweicloud_er_association": er.ResourceAssociation(),
"huaweicloud_er_attachment_accepter": er.ResourceAttachmentAccepter(),
"huaweicloud_er_attachment_update": er.ResourceAttachmentUpdate(),
"huaweicloud_er_instance": er.ResourceInstance(),
"huaweicloud_er_propagation": er.ResourcePropagation(),
"huaweicloud_er_route_table": er.ResourceRouteTable(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
package er

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/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/er"
)

func getAttachmentFunc(cfg *config.Config, state *terraform.ResourceState) (interface{}, error) {
client, err := cfg.NewServiceClient("er", acceptance.HW_REGION_NAME)
if err != nil {
return nil, fmt.Errorf("error creating Instance Client: %s", err)
}
return er.GetAttachmentById(client, state.Primary.Attributes["instance_id"],
state.Primary.Attributes["attachment_id"])
}

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

resourceName = "huaweicloud_er_attachment_update.test"
rc = acceptance.InitResourceCheck(resourceName, &obj, getAttachmentFunc)

name = acceptance.RandomAccResourceName()
updateName = acceptance.RandomAccResourceName()

baseConfig = testAccAttachmentUpdate_base()
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccAttachmentUpdate_basic_step1(baseConfig),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttrPair(resourceName, "instance_id",
"huaweicloud_er_instance.test", "id"),
resource.TestCheckResourceAttrPair(resourceName, "attachment_id",
"huaweicloud_er_vpc_attachment.test", "id"),
resource.TestCheckResourceAttrPair(resourceName, "name",
"huaweicloud_er_vpc_attachment.test", "name"),
resource.TestCheckResourceAttr(resourceName, "description", "Created by attachment update resource"),
),
},
{
Config: testAccAttachmentUpdate_basic_step2(baseConfig, name),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttrPair(resourceName, "instance_id",
"huaweicloud_er_instance.test", "id"),
resource.TestCheckResourceAttrPair(resourceName, "attachment_id",
"huaweicloud_er_vpc_attachment.test", "id"),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "description", "Created by attachment update resource"),
),
},
{
Config: testAccAttachmentUpdate_basic_step3(baseConfig, updateName),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttrPair(resourceName, "instance_id",
"huaweicloud_er_instance.test", "id"),
resource.TestCheckResourceAttrPair(resourceName, "attachment_id",
"huaweicloud_er_vpc_attachment.test", "id"),
resource.TestCheckResourceAttr(resourceName, "name", updateName),
resource.TestCheckResourceAttr(resourceName, "description", "Updated by attachment update resource"),
),
},
},
})
}

func testAccAttachmentUpdate_base() string {
var (
name = acceptance.RandomAccResourceName()
bgpAsNum = acctest.RandIntRange(64512, 65534)
)

return fmt.Sprintf(`
data "huaweicloud_availability_zones" "test" {}

resource "huaweicloud_er_instance" "test" {
availability_zones = try(slice(data.huaweicloud_availability_zones.test.names, 0, 1), []) # only one az has.
name = "%[1]s"
asn = %[2]d

lifecycle {
ignore_changes = [
availability_zones,
]
}
}

resource "huaweicloud_vpc" "test" {
name = "%[1]s"
cidr = "192.168.0.0/16"
}

resource "huaweicloud_vpc_subnet" "test" {
vpc_id = huaweicloud_vpc.test.id
name = "%[1]s"
cidr = cidrsubnet(huaweicloud_vpc.test.cidr, 4, 0)
gateway_ip = cidrhost(cidrsubnet(huaweicloud_vpc.test.cidr, 4, 0), 1)
}

resource "huaweicloud_er_vpc_attachment" "test" {
instance_id = huaweicloud_er_instance.test.id
vpc_id = huaweicloud_vpc.test.id # huaweicloud_vpc_subnet.test.vpc_id
subnet_id = huaweicloud_vpc_subnet.test.id
name = "%[1]s"

lifecycle {
ignore_changes = [
name,
description,
]
}
}
`, name, bgpAsNum)
}

func testAccAttachmentUpdate_basic_step1(baseConfig string) string {
return fmt.Sprintf(`
%[1]s

resource "huaweicloud_er_attachment_update" "test" {
instance_id = huaweicloud_er_instance.test.id
attachment_id = huaweicloud_er_vpc_attachment.test.id
description = "Created by attachment update resource"
}
`, baseConfig)
}

func testAccAttachmentUpdate_basic_step2(baseConfig, name string) string {
return fmt.Sprintf(`
%[1]s

resource "huaweicloud_er_attachment_update" "test" {
instance_id = huaweicloud_er_instance.test.id
attachment_id = huaweicloud_er_vpc_attachment.test.id
name = "%[2]s"
}
`, baseConfig, name)
}

func testAccAttachmentUpdate_basic_step3(baseConfig, name string) string {
return fmt.Sprintf(`
%[1]s

resource "huaweicloud_er_attachment_update" "test" {
instance_id = huaweicloud_er_instance.test.id
attachment_id = huaweicloud_er_vpc_attachment.test.id
name = "%[2]s"
description = "Updated by attachment update resource"
}
`, baseConfig, name)
}
Loading
Loading