diff --git a/fptcloud/instance-group/resource_instance_group.go b/fptcloud/instance-group/resource_instance_group.go index 75a23cc..3e2e4ca 100644 --- a/fptcloud/instance-group/resource_instance_group.go +++ b/fptcloud/instance-group/resource_instance_group.go @@ -95,7 +95,12 @@ func resourceInstanceGroupCreate(ctx context.Context, d *schema.ResourceData, m createModel.PolicyId = policyId.(string) } if vmIds, ok := d.GetOk("vm_ids"); ok { - createModel.VmIds = vmIds.([]string) + vmIdsSet := vmIds.(*schema.Set) + vmIdsList := make([]string, 0, len(vmIdsSet.List())) + for _, v := range vmIdsSet.List() { + vmIdsList = append(vmIdsList, v.(string)) + } + createModel.VmIds = vmIdsList } isSuccess, err := service.CreateInstanceGroup(createModel) diff --git a/fptcloud/instance/resource_instance.go b/fptcloud/instance/resource_instance.go index 129e2fc..9cd789c 100644 --- a/fptcloud/instance/resource_instance.go +++ b/fptcloud/instance/resource_instance.go @@ -69,11 +69,12 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, m inter } if securityGroupIds, ok := d.GetOk("security_group_ids"); ok { - securityGroupIdsValue := securityGroupIds.([]interface{}) - createdModel.SecurityGroupIds = make([]string, len(securityGroupIdsValue)) - for i, v := range securityGroupIdsValue { - createdModel.SecurityGroupIds[i] = v.(string) + securityGroupIdsSet := securityGroupIds.(*schema.Set) + securityGroupIdsList := make([]string, 0, len(securityGroupIdsSet.List())) + for _, v := range securityGroupIdsSet.List() { + securityGroupIdsList = append(securityGroupIdsList, v.(string)) } + createdModel.SecurityGroupIds = securityGroupIdsList } if instanceGroupId, ok := d.GetOk("instance_group_id"); ok { diff --git a/fptcloud/instance/schema_instance.go b/fptcloud/instance/schema_instance.go index e199618..468c606 100644 --- a/fptcloud/instance/schema_instance.go +++ b/fptcloud/instance/schema_instance.go @@ -84,7 +84,7 @@ var dataSourceInstanceSchema = map[string]*schema.Schema{ Description: "The root storage policy of the instance", }, "security_group_ids": { - Type: schema.TypeSet, + Type: schema.TypeList, Computed: true, Optional: true, Elem: &schema.Schema{Type: schema.TypeString}, diff --git a/fptcloud/security-group-rule/resource_security_group_rule.go b/fptcloud/security-group-rule/resource_security_group_rule.go index 0a1aeda..6ca2906 100755 --- a/fptcloud/security-group-rule/resource_security_group_rule.go +++ b/fptcloud/security-group-rule/resource_security_group_rule.go @@ -127,11 +127,12 @@ func resourceSecurityGroupRuleCreate(ctx context.Context, d *schema.ResourceData } if sources, ok := d.GetOk("sources"); ok { - sourceList := sources.([]interface{}) - createdModel.Sources = make([]string, len(sourceList)) - for i, v := range sourceList { - createdModel.Sources[i] = v.(string) + sourceSet := sources.(*schema.Set) + sourceList := make([]string, 0, len(sourceSet.List())) + for _, v := range sourceSet.List() { + sourceList = append(sourceList, v.(string)) } + createdModel.Sources = sourceList } if description, ok := d.GetOk("description"); ok { diff --git a/fptcloud/security-group/resource_security_group.go b/fptcloud/security-group/resource_security_group.go index 99928bd..a17bf22 100755 --- a/fptcloud/security-group/resource_security_group.go +++ b/fptcloud/security-group/resource_security_group.go @@ -47,11 +47,12 @@ func resourceSecurityGroupCreate(ctx context.Context, d *schema.ResourceData, m } if applyTo, ok := d.GetOk("apply_to"); ok { - applyToList := applyTo.([]interface{}) - createdModel.ApplyTo = make([]string, len(applyToList)) - for i, v := range applyToList { - createdModel.ApplyTo[i] = v.(string) + applyToSet := applyTo.(*schema.Set) + applyToList := make([]string, 0, len(applyToSet.List())) + for _, v := range applyToSet.List() { + applyToList = append(applyToList, v.(string)) } + createdModel.ApplyTo = applyToList } if okVpcId { @@ -161,18 +162,20 @@ func resourceSecurityGroupUpdate(ctx context.Context, d *schema.ResourceData, m } if hasChangeApplyTo { - applyToValue, ok := d.Get("apply_to").([]interface{}) + applyToValue, ok := d.GetOk("apply_to") if !ok { - applyToValue = []interface{}{} + applyToValue = &schema.Set{} } - applyTo := make([]string, len(applyToValue)) - for i, v := range applyToValue { - applyTo[i] = v.(string) + + applyToSet := applyToValue.(*schema.Set) + applyTo := make([]string, 0, len(applyToSet.List())) + for _, v := range applyToSet.List() { + applyTo = append(applyTo, v.(string)) } _, err := securityGroupService.UpdateApplyTo(vpcId, d.Id(), applyTo) if err != nil { - return diag.Errorf("[ERR] An error occurred while change apply to from security group %s: %s", d.Id(), err) + return diag.Errorf("[ERR] An error occurred while changing apply to for security group %s: %s", d.Id(), err) } updateStateConf := &retry.StateChangeConf{