Skip to content

Commit

Permalink
refactor(sfs-turbo): refer to huaweicloud and update the doc (#972)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason-Zhang9309 authored Sep 4, 2023
1 parent a7f23e5 commit c62c2b9
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 381 deletions.
88 changes: 48 additions & 40 deletions docs/resources/sfs_turbo.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,69 +11,69 @@ Provides an Shared File System (SFS) Turbo resource.
## Example Usage

```hcl
variable "vpc_id" {}
variable "subnet_id" {}
variable "secgroup_id" {}
variable "test_az" {}
resource "flexibleengine_vpc_v1" "example_vpc" {
name = "example-vpc"
cidr = "192.168.0.0/16"
}
resource "flexibleengine_vpc_subnet_v1" "example_subnet" {
name = "example-vpc-subnet"
cidr = "192.168.0.0/24"
gateway_ip = "192.168.0.1"
vpc_id = flexibleengine_vpc_v1.example_vpc.id
}
resource "flexibleengine_networking_secgroup_v2" "example_secgroup" {
name = "example-secgroup"
description = "My neutron security group"
}
resource "flexibleengine_sfs_turbo" "sfs-turbo-1" {
name = "sfs-turbo-1"
size = 500
share_proto = "NFS"
vpc_id = flexibleengine_vpc_v1.example_vpc.id
subnet_id = flexibleengine_vpc_subnet_v1.example_subnet.id
security_group_id = flexibleengine_networking_secgroup_v2.example_secgroup.id
resource "flexibleengine_sfs_turbo" "test" {
name = "sfs-turbo-1"
size = 500
share_proto = "NFS"
vpc_id = var.vpc_id
subnet_id = var.subnet_id
security_group_id = var.secgroup_id
availability_zone = var.test_az
tags = {
foo = "bar"
key = "value"
}
}
```

## Argument Reference

The following arguments are supported:

* `name` - (Required) Specifies the name of an SFS Turbo file system. The value contains 4 to 64
* `region` - (Optional, String, ForceNew) The region in which to create the SFS Turbo resource. If omitted, the
provider-level region will be used. Changing this creates a new SFS Turbo resource.

* `name` - (Required, String, ForceNew) Specifies the name of an SFS Turbo file system. The value contains 4 to 64
characters and must start with a letter. Changing this will create a new resource.

* `size` - (Required) Specifies the capacity of a common file system, in GB. The value ranges from 500 to 32768.
* `size` - (Required, Int) Specifies the capacity of a sharing file system, in GB. The value ranges from 500 to 32768.

* `share_proto` - (Optional) Specifies the protocol for sharing file systems. The valid value is NFS.
Changing this will create a new resource.
-> The file system capacity can only be expanded, not reduced.

* `share_type` - (Optional) Specifies the file system type. The valid values are STANDARD and PERFORMANCE.
* `share_proto` - (Optional, String, ForceNew) Specifies the protocol for sharing file systems. The valid value is NFS.
Changing this will create a new resource.

* `availability_zone` - (Required) Specifies the availability zone where the file system is located.
* `share_type` - (Optional, String, ForceNew) Specifies the file system type. Changing this will create a new resource.
Valid values are **STANDARD** and **PERFORMANCE**. Defaults to **STANDARD**.

* `availability_zone` - (Required, String, ForceNew) Specifies the availability zone where the file system is located.
Changing this will create a new resource.

* `vpc_id` - (Required) Specifies the VPC ID. Changing this will create a new resource.
* `vpc_id` - (Required, String, ForceNew) Specifies the VPC ID. Changing this will create a new resource.

* `subnet_id` - (Required) Specifies the ID of the VPC Subnet. Changing this will create a new resource.
* `subnet_id` - (Required, String, ForceNew) Specifies the network ID of the subnet. Changing this will create a new
resource.

* `security_group_id` - (Required) Specifies the security group ID. Changing this will create a new resource.
* `security_group_id` - (Required, String, ForceNew) Specifies the security group ID. Changing this will create a new
resource.

* `crypt_key_id` - (Optional) Specifies the ID of a KMS key to encrypt the file system.
Changing this will create a new resource.
* `crypt_key_id` - (Optional, String, ForceNew) Specifies the ID of a KMS key to encrypt the file system. Changing this
will create a new resource.

* `tags` - (Optional, Map) Specifies the key/value pairs to associate with the SFS Turbo.

-> **NOTE:**
SFS Turbo will create two private IP addresses and one virtual IP address under the subnet you specified.
To ensure normal use, SFS Turbo will enable the inbound rules for ports *111*, *445*, *2049*, *2051*, *2052*,
and *20048* in the security group you specified.
SFS Turbo will create two private IP addresses and one virtual IP address under the subnet you specified. To ensure
normal use, SFS Turbo will enable the inbound rules for ports *111*, *445*, *2049*, *2051*, *2052*, and *20048* in the
security group you specified.

## Attributes Reference
## Attribute Reference

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

Expand All @@ -89,10 +89,18 @@ In addition to all arguments above, the following attributes are exported:

* `available_capacity` - The available capacity of the SFS Turbo file system in the unit of GB.

## Timeouts

This resource provides the following timeouts configuration options:

* `create` - Default is 60 minutes.
* `update` - Default is 60 minutes.
* `delete` - Default is 10 minutes.

## Import

SFS Turbo can be imported using the `id`, e.g.

```shell
```bash
terraform import flexibleengine_sfs_turbo 1e3d5306-24c9-4316-9185-70e9787d71ab
```
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package flexibleengine
package acceptance

import (
"fmt"
"testing"

"github.com/chnsz/golangsdk/openstack/sfs_turbo/v1/shares"
"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/chnsz/golangsdk/openstack/sfs_turbo/v1/shares"

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

func TestAccSFSTurbo_basic(t *testing.T) {
Expand All @@ -17,9 +20,9 @@ func TestAccSFSTurbo_basic(t *testing.T) {
var turbo shares.Turbo

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckSFSTurboDestroy,
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: TestAccProviderFactories,
CheckDestroy: testAccCheckSFSTurboDestroy,
Steps: []resource.TestStep{
{
Config: testAccSFSTurbo_basic(randSuffix),
Expand All @@ -30,6 +33,8 @@ func TestAccSFSTurbo_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "share_type", "STANDARD"),
resource.TestCheckResourceAttr(resourceName, "size", "500"),
resource.TestCheckResourceAttr(resourceName, "status", "200"),
resource.TestCheckResourceAttr(resourceName, "tags.foo", "bar"),
resource.TestCheckResourceAttr(resourceName, "tags.key", "value"),
),
},
{
Expand All @@ -41,8 +46,10 @@ func TestAccSFSTurbo_basic(t *testing.T) {
Config: testAccSFSTurbo_update(randSuffix),
Check: resource.ComposeTestCheckFunc(
testAccCheckSFSTurboExists(resourceName, &turbo),
resource.TestCheckResourceAttr(resourceName, "size", "600"),
resource.TestCheckResourceAttr(resourceName, "status", "221"),
resource.TestCheckResourceAttr(resourceName, "size", "500"),
resource.TestCheckResourceAttr(resourceName, "status", "200"),
resource.TestCheckResourceAttr(resourceName, "tags.foo", "bar_update"),
resource.TestCheckResourceAttr(resourceName, "tags.key", "value_update"),
),
},
},
Expand All @@ -56,9 +63,9 @@ func TestAccSFSTurbo_crypt(t *testing.T) {
var turbo shares.Turbo

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckSFSTurboDestroy,
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: TestAccProviderFactories,
CheckDestroy: testAccCheckSFSTurboDestroy,
Steps: []resource.TestStep{
{
Config: testAccSFSTurbo_crypt(randSuffix),
Expand All @@ -77,10 +84,10 @@ func TestAccSFSTurbo_crypt(t *testing.T) {
}

func testAccCheckSFSTurboDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
config := testAccProvider.Meta().(*config.Config)
sfsClient, err := config.SfsV1Client(OS_REGION_NAME)
if err != nil {
return fmt.Errorf("Error creating FlexibleEngine sfs turbo client: %s", err)
return fmt.Errorf("Error creating flexibleengine sfs turbo client: %s", err)
}

for _, rs := range s.RootModule().Resources {
Expand Down Expand Up @@ -108,10 +115,10 @@ func testAccCheckSFSTurboExists(n string, share *shares.Turbo) resource.TestChec
return fmt.Errorf("No ID is set")
}

config := testAccProvider.Meta().(*Config)
config := testAccProvider.Meta().(*config.Config)
sfsClient, err := config.SfsV1Client(OS_REGION_NAME)
if err != nil {
return fmt.Errorf("Error creating FlexibleEngine sfs turbo client: %s", err)
return fmt.Errorf("Error creating flexibleengine sfs turbo client: %s", err)
}

found, err := shares.Get(sfsClient, rs.Primary.ID).Extract()
Expand Down Expand Up @@ -152,52 +159,66 @@ resource "flexibleengine_networking_secgroup_v2" "secgroup" {
func testAccSFSTurbo_basic(suffix string) string {
return fmt.Sprintf(`
%s
data "flexibleengine_availability_zones" "myaz" {}
resource "flexibleengine_sfs_turbo" "sfs-turbo1" {
name = "sfs-turbo-acc-%s"
size = 500
share_proto = "NFS"
vpc_id = flexibleengine_vpc_v1.test.id
subnet_id = flexibleengine_vpc_subnet_v1.test.id
name = "sfs-turbo-acc-%s"
size = 500
share_proto = "NFS"
vpc_id = flexibleengine_vpc_v1.test.id
subnet_id = flexibleengine_vpc_subnet_v1.test.id
security_group_id = flexibleengine_networking_secgroup_v2.secgroup.id
availability_zone = "%s"
availability_zone = data.flexibleengine_availability_zones.myaz.names[0]
tags = {
foo = "bar"
key = "value"
}
}
`, testAccNetworkPreConditions(suffix), suffix, OS_AVAILABILITY_ZONE)
`, testAccNetworkPreConditions(suffix), suffix)
}

func testAccSFSTurbo_update(suffix string) string {
return fmt.Sprintf(`
%s
data "flexibleengine_availability_zones" "myaz" {}
resource "flexibleengine_sfs_turbo" "sfs-turbo1" {
name = "sfs-turbo-acc-%s"
size = 600
share_proto = "NFS"
vpc_id = flexibleengine_vpc_v1.test.id
subnet_id = flexibleengine_vpc_subnet_v1.test.id
name = "sfs-turbo-acc-%s"
size = 500
share_proto = "NFS"
vpc_id = flexibleengine_vpc_v1.test.id
subnet_id = flexibleengine_vpc_subnet_v1.test.id
security_group_id = flexibleengine_networking_secgroup_v2.secgroup.id
availability_zone = "%s"
availability_zone = data.flexibleengine_availability_zones.myaz.names[0]
tags = {
foo = "bar_update"
key = "value_update"
}
}
`, testAccNetworkPreConditions(suffix), suffix, OS_AVAILABILITY_ZONE)
`, testAccNetworkPreConditions(suffix), suffix)
}

func testAccSFSTurbo_crypt(suffix string) string {
return fmt.Sprintf(`
%s
data "flexibleengine_availability_zones" "myaz" {}
resource "flexibleengine_kms_key_v1" "key_1" {
key_alias = "kms-acc-%s"
key_alias = "kms-acc-%s"
pending_days = "7"
}
resource "flexibleengine_sfs_turbo" "sfs-turbo1" {
name = "sfs-turbo-acc-%s"
size = 500
share_proto = "NFS"
crypt_key_id = flexibleengine_kms_key_v1.key_1.id
vpc_id = flexibleengine_vpc_v1.test.id
subnet_id = flexibleengine_vpc_subnet_v1.test.id
name = "sfs-turbo-acc-%s"
size = 500
share_proto = "NFS"
vpc_id = flexibleengine_vpc_v1.test.id
subnet_id = flexibleengine_vpc_subnet_v1.test.id
security_group_id = flexibleengine_networking_secgroup_v2.secgroup.id
availability_zone = "%s"
availability_zone = data.flexibleengine_availability_zones.myaz.names[0]
crypt_key_id = flexibleengine_kms_key_v1.key_1.id
}
`, testAccNetworkPreConditions(suffix), suffix, suffix, OS_AVAILABILITY_ZONE)
`, testAccNetworkPreConditions(suffix), suffix, suffix)
}
2 changes: 1 addition & 1 deletion flexibleengine/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,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_sfs_turbo": resourceSFSTurbo(),
"flexibleengine_rts_software_config_v1": resourceSoftwareConfigV1(),
"flexibleengine_rts_stack_v1": resourceRTSStackV1(),
"flexibleengine_compute_bms_server_v2": resourceComputeBMSInstanceV2(),
Expand Down Expand Up @@ -550,6 +549,7 @@ 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": huaweicloud.ResourceSFSTurbo(), // v1.41.0

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

0 comments on commit c62c2b9

Please sign in to comment.