Skip to content

Commit

Permalink
feat(NAT): Synchronized SFS resource, unit test and document.
Browse files Browse the repository at this point in the history
  • Loading branch information
liwanting0517 committed Jan 15, 2024
1 parent ba09928 commit b1531a3
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/resources/sfs_access_rule_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ resource "flexibleengine_sfs_access_rule_v2" "rule_1" {

The following arguments are supported:

* `region` - (Optional, String, ForceNew) Specifies the region in which to create the RDS instance resource.
If omitted, the provider-level region will be used. Changing this will create a new RDS instance resource.

* `sfs_id` - (Required, String, ForceNew) Specifies the UUID of the shared file system.
Changing this will create a new access rule.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package acceptance

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

"github.com/chnsz/golangsdk/openstack/sfs/v2/shares"

"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
)

func getSfsAccessRuleResourceFunc(cfg *config.Config, state *terraform.ResourceState) (interface{}, error) {
client, err := cfg.SfsV2Client(OS_REGION_NAME)
if err != nil {
return nil, fmt.Errorf("error creating SFS client: %s", err)
}

resourceID := state.Primary.ID
sfsID := state.Primary.Attributes["sfs_id"]
rules, err := shares.ListAccessRights(client, sfsID).ExtractAccessRights()
if err != nil {
return nil, err
}

for _, item := range rules {
if item.ID == resourceID {
return &item, nil
}
}

return nil, fmt.Errorf("the sfs access rule %s does not exist", resourceID)
}

func TestAccSFSAccessRuleV2_basic(t *testing.T) {
var rule shares.AccessRight
rName := acceptance.RandomAccResourceName()
resourceName := "flexibleengine_sfs_access_rule_v2.test"

rc := acceptance.InitResourceCheck(
resourceName,
&rule,
getSfsAccessRuleResourceFunc,
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
ProviderFactories: TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: configAccSFSAccessRuleV2_basic(rName),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceName, "access_level", "rw"),
resource.TestCheckResourceAttr(resourceName, "status", "active"),
),
},
{
Config: configAccSFSAccessRuleV2_ipAuth(rName),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceName, "status", "active"),
),
},
},
})
}

func configAccSFSAccessRuleV2_basic(rName string) string {
return fmt.Sprintf(`
data "flexibleengine_vpc_v1" "test" {
name = "tf-xxx"
}
resource "flexibleengine_sfs_file_system_v2" "test" {
share_proto = "NFS"
size = 10
name = "%s"
description = "sfs file system created by terraform testacc"
}
resource "flexibleengine_sfs_access_rule_v2" "test" {
sfs_id = flexibleengine_sfs_file_system_v2.test.id
access_to = data.flexibleengine_vpc_v1.test.id
}`, rName)
}

func configAccSFSAccessRuleV2_ipAuth(rName string) string {
return fmt.Sprintf(`
data "flexibleengine_vpc_v1" "test" {
name = "tf-xxx"
}
resource "flexibleengine_sfs_file_system_v2" "test" {
share_proto = "NFS"
size = 10
name = "%s"
description = "sfs file system created by terraform testacc"
}
resource "flexibleengine_sfs_access_rule_v2" "test" {
sfs_id = flexibleengine_sfs_file_system_v2.test.id
access_to = join("#", [data.flexibleengine_vpc_v1.test.id, "192.168.10.0/24", "0", "no_all_squash,no_root_squash"])
}`, rName)
}
5 changes: 3 additions & 2 deletions flexibleengine/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ func Provider() *schema.Provider {
"flexibleengine_vpc_peering_connection_accepter_v2": resourceVpcPeeringConnectionAccepterV2(),

"flexibleengine_sfs_file_system_v2": resourceSFSFileSystemV2(),
"flexibleengine_sfs_access_rule_v2": resourceSFSAccessRuleV2(),

"flexibleengine_rts_software_config_v1": resourceSoftwareConfigV1(),
"flexibleengine_rts_stack_v1": resourceRTSStackV1(),
Expand Down Expand Up @@ -688,7 +687,9 @@ func Provider() *schema.Provider {
"flexibleengine_lb_member_v3": elb.ResourceMemberV3(), // v1.35.0
"flexibleengine_smn_topic_v2": smn.ResourceTopic(), // v1.39.0
"flexibleengine_smn_subscription_v2": smn.ResourceSubscription(), // v1.39.0
"flexibleengine_sfs_turbo": sfs.ResourceSFSTurbo(),

"flexibleengine_sfs_access_rule_v2": sfs.ResourceSFSAccessRuleV2(),
"flexibleengine_sfs_turbo": sfs.ResourceSFSTurbo(),

// Deprecated resource
"flexibleengine_as_group_v1": resourceASGroup(),
Expand Down

0 comments on commit b1531a3

Please sign in to comment.