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

feat(SFS): Synchronized SFS resource, unit test and document. #1101

Closed
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
feat(SFS): Synchronized SFS resource, unit test and document.
liwanting0517 committed Jan 17, 2024
commit f609b3e61c2c611615e3df1c4b9500bc24cde729
3 changes: 3 additions & 0 deletions docs/resources/sfs_access_rule_v2.md
Original file line number Diff line number Diff line change
@@ -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 resource.
If omitted, the provider-level region will be used. Changing this parameter will create a new resource.

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

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
@@ -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(),
@@ -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(),