Skip to content

Commit

Permalink
support enterprise_project_id in sfs turbo (#1030)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason-Zhang9309 committed Apr 2, 2021
1 parent 814ef9f commit efd2059
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/data-sources/enterprise_project.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ EVS | huaweicloud_evs_volume |
CCE | huaweicloud_cce_cluster | huaweicloud_cce_node<br>huaweicloud_cce_node_pool<br>huaweicloud_cce_addon
RDS | huaweicloud_rds_instance<br>huaweicloud_rds_read_replica_instance |
OBS | huaweicloud_obs_bucket | huaweicloud_obs_bucket_object<br>huaweicloud_obs_bucket_policy
SFS | huaweicloud_sfs_file_system | huaweicloud_sfs_access_rule
SFS | huaweicloud_sfs_file_system<br>huaweicloud_sfs_turbo | huaweicloud_sfs_access_rule
KMS | huaweicloud_kms_key |
DCS | huaweicloud_dcs_instance |
NAT | huaweicloud_nat_gateway | huaweicloud_nat_snat_rule<br>huaweicloud_nat_dnat_rule
Expand Down
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
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)
}

0 comments on commit efd2059

Please sign in to comment.