Skip to content

Commit

Permalink
change type of fixed_ips to list in iec vip resource (#862)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiChangkuo authored Jan 26, 2021
1 parent 690417f commit ca32433
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 34 deletions.
12 changes: 3 additions & 9 deletions docs/resources/iec_vip.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ resource "huaweicloud_iec_vip" "vip_test" {
The following arguments are supported:

* `subnet_id` - (Required, String, ForceNew) Specifies the subnet network id
of vip binding in which to allocate IP address for this vip. Changing this
parameter creates a new vip resource.
of vip binding in which to allocate IP address for this vip.
Changing this parameter creates a new vip resource.

## Attributes Reference

Expand All @@ -32,13 +32,7 @@ In addition to all arguments above, the following attributes are exported:

* `mac_address` - The MAC address of the vip.

* `fixed_ips` - An subnet Array of the vip binding. The fixed_ips object
structure is documented below.

The `fixed_ips` block supports:

* `subnet_id` - The subnet id of the vip binding.
* `ip_address` - The ip address of the subnet network.
* `fixed_ips` - An array of IP addresses binding to the vip.

## Timeouts

Expand Down
26 changes: 6 additions & 20 deletions huaweicloud/resource_huaweicloud_iec_vip.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,9 @@ func resourceIecVipV1() *schema.Resource {
Computed: true,
},
"fixed_ips": {
Type: schema.TypeSet,
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"subnet_id": {
Type: schema.TypeString,
Computed: true,
},
"ip_address": {
Type: schema.TypeString,
Computed: true,
},
},
},
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}
Expand Down Expand Up @@ -107,14 +96,11 @@ func resourceIecVIPV1Read(d *schema.ResourceData, meta interface{}) error {
d.Set("subnet_id", n.NetworkID)
d.Set("mac_address", n.MacAddress)

ipsSet := make([]map[string]interface{}, len(n.FixedIPs))
for index, ipObj := range n.FixedIPs {
ipsSet[index] = map[string]interface{}{
"subnet_id": ipObj.SubnetId,
"ip_address": ipObj.IpAddress,
}
allIPs := make([]string, len(n.FixedIPs))
for i, ipObj := range n.FixedIPs {
allIPs[i] = ipObj.IpAddress
}
d.Set("fixed_ips", ipsSet)
d.Set("fixed_ips", allIPs)

return nil
}
Expand Down
12 changes: 7 additions & 5 deletions huaweicloud/resource_huaweicloud_iec_vip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"

Expand All @@ -14,6 +15,7 @@ import (

func TestAccIecVipResource_basic(t *testing.T) {
var iecPort iec_common.Port
rName := fmt.Sprintf("iec-%s", acctest.RandString(5))
resourceName := "huaweicloud_iec_vip.vip_test"

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -22,7 +24,7 @@ func TestAccIecVipResource_basic(t *testing.T) {
CheckDestroy: testAccCheckIecVipDestroy,
Steps: []resource.TestStep{
{
Config: testAccIecVip_basic(),
Config: testAccIecVip_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckIecVipExists(resourceName, &iecPort),
resource.TestMatchResourceAttr(resourceName, "mac_address", regexp.MustCompile("^[0-9A-Fa-f]{2}\\:[0-9A-Fa-f]{2}\\:[0-9A-Fa-f]{2}\\:[0-9A-Fa-f]{2}\\:[0-9A-Fa-f]{2}\\:[0-9A-Fa-f]{2}$")),
Expand Down Expand Up @@ -91,18 +93,18 @@ func testAccCheckIecVipExists(n string, resource *iec_common.Port) resource.Test
}
}

func testAccIecVip_basic() string {
func testAccIecVip_basic(rName string) string {
return fmt.Sprintf(`
data "huaweicloud_iec_sites" "sites_test" {}
resource "huaweicloud_iec_vpc" "vpc_test" {
name = "iec-vpc-demo"
name = "vpc-%s"
cidr = "192.168.0.0/16"
mode = "CUSTOMER"
}
resource "huaweicloud_iec_vpc_subnet" "subnet_test" {
name = "iec-subnet-demo"
name = "subnet-%s"
cidr = "192.168.0.0/16"
gateway_ip = "192.168.0.1"
vpc_id = huaweicloud_iec_vpc.vpc_test.id
Expand All @@ -112,5 +114,5 @@ resource "huaweicloud_iec_vpc_subnet" "subnet_test" {
resource "huaweicloud_iec_vip" "vip_test" {
subnet_id = huaweicloud_iec_vpc_subnet.subnet_test.id
}
`)
`, rName, rName)
}

0 comments on commit ca32433

Please sign in to comment.