Skip to content

Commit

Permalink
feat(sfsTurbo): support edit security_group_id field (huaweicloud#3782)
Browse files Browse the repository at this point in the history
  • Loading branch information
wanglong3710 authored Dec 4, 2023
1 parent 689a174 commit a5dc5fc
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 8 deletions.
3 changes: 1 addition & 2 deletions docs/resources/sfs_turbo.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ The following arguments are supported:
* `subnet_id` - (Required, String, ForceNew) Specifies the network ID of the subnet. 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.
* `security_group_id` - (Required, String) Specifies the security group ID.

* `enhanced` - (Optional, Bool, ForceNew) Specifies whether the file system is enhanced or not. Changing this will
create a new resource.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func TestAccSFSTurbo_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "status", "200"),
resource.TestCheckResourceAttr(resourceName, "tags.foo", "bar"),
resource.TestCheckResourceAttr(resourceName, "tags.key", "value"),
resource.TestCheckResourceAttrPair(resourceName, "security_group_id",
"huaweicloud_networking_secgroup.test", "id"),
),
},
{
Expand All @@ -75,11 +77,13 @@ func TestAccSFSTurbo_basic(t *testing.T) {
Config: testAccSFSTurbo_update(rName),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("%s-update", rName)),
resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("%s_update", rName)),
resource.TestCheckResourceAttr(resourceName, "size", "600"),
resource.TestCheckResourceAttr(resourceName, "status", "221"),
resource.TestCheckResourceAttr(resourceName, "tags.foo", "bar_update"),
resource.TestCheckResourceAttr(resourceName, "tags.key", "value_update"),
resource.TestCheckResourceAttrPair(resourceName, "security_group_id",
"huaweicloud_networking_secgroup.test_update", "id"),
resource.TestCheckResourceAttr(resourceName, "status", "232"),
),
},
},
Expand Down Expand Up @@ -394,17 +398,22 @@ resource "huaweicloud_sfs_turbo" "test" {

func testAccSFSTurbo_update(rName string) string {
return fmt.Sprintf(`
%s
%[1]s
resource "huaweicloud_networking_secgroup" "test_update" {
name = "%[2]s_update"
delete_default_rules = true
}
data "huaweicloud_availability_zones" "test" {}
resource "huaweicloud_sfs_turbo" "test" {
name = "%s-update"
name = "%[2]s_update"
size = 600
share_proto = "NFS"
vpc_id = huaweicloud_vpc.test.id
subnet_id = huaweicloud_vpc_subnet.test.id
security_group_id = huaweicloud_networking_secgroup.test.id
security_group_id = huaweicloud_networking_secgroup.test_update.id
availability_zone = data.huaweicloud_availability_zones.test.names[0]
tags = {
Expand Down
22 changes: 21 additions & 1 deletion huaweicloud/services/sfs/resource_huaweicloud_sfs_turbo.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ func ResourceSFSTurbo() *schema.Resource {
"security_group_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"crypt_key_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -530,6 +529,27 @@ func resourceSFSTurboUpdate(ctx context.Context, d *schema.ResourceData, meta in
}
}

if d.HasChange("security_group_id") {
updateSecurityGroupIdOpts := shares.UpdateSecurityGroupIdOpts{
SecurityGroupId: d.Get("security_group_id").(string),
}
err = shares.UpdateSecurityGroupId(sfsClient, d.Id(), updateSecurityGroupIdOpts).Err
if err != nil {
return diag.Errorf("error updating security group ID of SFS Turbo: %s", err)
}
stateConf := &resource.StateChangeConf{
Pending: []string{"132"},
Target: []string{"232", "200"},
Refresh: waitForSFSTurboSubStatus(sfsClient, resourceId),
Timeout: d.Timeout(schema.TimeoutUpdate),
PollInterval: 5 * time.Second,
}
_, err = stateConf.WaitForStateContext(ctx)
if err != nil {
return diag.Errorf("error updating SFS Turbo: %s", err)
}
}

return resourceSFSTurboRead(ctx, d, meta)
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a5dc5fc

Please sign in to comment.