Skip to content

Commit

Permalink
support enterprise_project_id in sfs turbo
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason-Zhang9309 committed Apr 2, 2021
1 parent 25380ce commit ea892f1
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 457 deletions.
3 changes: 3 additions & 0 deletions docs/resources/sfs_turbo.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ The following arguments are supported:
* `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.

* `enterprise_project_id` - (Optional, String, ForceNew) The enterprise project id of the file system.
Changing this will create a new resource.

-> **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*,
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,6 @@ github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/huaweicloud/golangsdk v0.0.0-20210323020602-6d5ee0030244 h1:Jzq3828aWxaRquRxPqv8aG1A6B+LatrIHiD3SMlHpFM=
github.com/huaweicloud/golangsdk v0.0.0-20210323020602-6d5ee0030244/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/huaweicloud/golangsdk v0.0.0-20210329082007-ee3a1fd6c542 h1:rA1o0dd7F2cR/zBe9Fyk7DjjgSv85MM6PdToMabNXq4=
github.com/huaweicloud/golangsdk v0.0.0-20210329082007-ee3a1fd6c542/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/huaweicloud/golangsdk v0.0.0-20210401071036-b8be64ba4002 h1:RxtuAdoAiJI9bScWcXf09sVDAEjP0w4X8zIe5e4pljU=
github.com/huaweicloud/golangsdk v0.0.0-20210401071036-b8be64ba4002/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down
25 changes: 16 additions & 9 deletions huaweicloud/resource_huaweicloud_sfs_turbo.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ func ResourceSFSTurbo() *schema.Resource {
Computed: true,
ForceNew: true,
},

"enterprise_project_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -118,14 +123,15 @@ func resourceSFSTurboCreate(d *schema.ResourceData, meta interface{}) error {
}

createOpts := shares.CreateOpts{
Name: d.Get("name").(string),
Size: d.Get("size").(int),
ShareProto: d.Get("share_proto").(string),
ShareType: d.Get("share_type").(string),
VpcID: d.Get("vpc_id").(string),
SubnetID: d.Get("subnet_id").(string),
SecurityGroupID: d.Get("security_group_id").(string),
AvailabilityZone: d.Get("availability_zone").(string),
Name: d.Get("name").(string),
Size: d.Get("size").(int),
ShareProto: d.Get("share_proto").(string),
ShareType: d.Get("share_type").(string),
VpcID: d.Get("vpc_id").(string),
SubnetID: d.Get("subnet_id").(string),
SecurityGroupID: d.Get("security_group_id").(string),
AvailabilityZone: d.Get("availability_zone").(string),
EnterpriseProjectId: GetEnterpriseProjectID(d, config),
}

metaOpts := shares.Metadata{}
Expand Down Expand Up @@ -184,6 +190,7 @@ func resourceSFSTurboRead(d *schema.ResourceData, meta interface{}) error {
d.Set("available_capacity", n.AvailCapacity)
d.Set("export_location", n.ExportLocation)
d.Set("crypt_key_id", n.CryptKeyID)
d.Set("enterprise_project_id", n.EnterpriseProjectId)

// n.Size is a string of float64, should convert it to int
if fsize, err := strconv.ParseFloat(n.Size, 64); err == nil {
Expand Down
41 changes: 41 additions & 0 deletions huaweicloud/resource_huaweicloud_sfs_turbo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,29 @@ func TestAccSFSTurbo_crypt(t *testing.T) {
})
}

func TestAccSFSTurbo_withEpsId(t *testing.T) {
randSuffix := acctest.RandString(5)
turboName := fmt.Sprintf("sfs-turbo-acc-%s", randSuffix)
resourceName := "huaweicloud_sfs_turbo.sfs-turbo1"
var turbo shares.Turbo

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheckEpsID(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckSFSTurboDestroy,
Steps: []resource.TestStep{
{
Config: testAccSFSTurbo_withEpsId(randSuffix),
Check: resource.ComposeTestCheckFunc(
testAccCheckSFSTurboExists(resourceName, &turbo),
resource.TestCheckResourceAttr(resourceName, "name", turboName),
resource.TestCheckResourceAttr(resourceName, "enterprise_project_id", HW_ENTERPRISE_PROJECT_ID_TEST),
),
},
},
})
}

func testAccCheckSFSTurboDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
sfsClient, err := config.SfsV1Client(HW_REGION_NAME)
Expand Down Expand Up @@ -207,3 +230,21 @@ resource "huaweicloud_sfs_turbo" "sfs-turbo1" {
}
`, testAccNetworkPreConditions(suffix), suffix, suffix)
}

func testAccSFSTurbo_withEpsId(suffix string) string {
return fmt.Sprintf(`
%s
data "huaweicloud_availability_zones" "myaz" {}
resource "huaweicloud_sfs_turbo" "sfs-turbo1" {
name = "sfs-turbo-acc-%s"
size = 500
share_proto = "NFS"
vpc_id = huaweicloud_vpc_v1.test.id
subnet_id = huaweicloud_vpc_subnet_v1.test.id
security_group_id = huaweicloud_networking_secgroup_v2.secgroup.id
availability_zone = data.huaweicloud_availability_zones.myaz.names[0]
enterprise_project_id = "%s"
}
`, testAccNetworkPreConditions(suffix), suffix, HW_ENTERPRISE_PROJECT_ID_TEST)
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit ea892f1

Please sign in to comment.