Skip to content

Commit

Permalink
Only returns available flavors for specified az (#621)
Browse files Browse the repository at this point in the history
This updates flavors data source to filter abandon and sellout
flavors for specified az.
  • Loading branch information
niuzhenguo authored Oct 31, 2020
1 parent 3cab310 commit 2c04b01
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/hashicorp/errwrap v1.0.0
github.com/hashicorp/go-cleanhttp v0.5.1
github.com/hashicorp/terraform-plugin-sdk v1.13.0
github.com/huaweicloud/golangsdk v0.0.0-20201027014306-5ff7dac952b3
github.com/huaweicloud/golangsdk v0.0.0-20201030072716-cb31520416ba
github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a
github.com/mitchellh/go-homedir v1.1.0
github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ 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-20201027014306-5ff7dac952b3 h1:OM0O1p/gea9E3fQGca1gBrM/f10IZQ38w4MGhupar8c=
github.com/huaweicloud/golangsdk v0.0.0-20201027014306-5ff7dac952b3/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/huaweicloud/golangsdk v0.0.0-20201030072716-cb31520416ba h1:HYHfyOIFOG8Y3y1XZoiyFhsTUxkg56IxPn+D9ME60pE=
github.com/huaweicloud/golangsdk v0.0.0-20201030072716-cb31520416ba/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a h1:FyS/ubzBR5xJlnJGRTwe7GUHpJOR4ukYK3y+LFNffuA=
github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a/go.mod h1:uoIMjNxUfXi48Ci40IXkPRbghZ1vbti6v9LCbNqRgHY=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
Expand Down
18 changes: 18 additions & 0 deletions huaweicloud/data_source_huaweicloud_compute_flavors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package huaweicloud
import (
"fmt"
"strconv"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/huaweicloud/golangsdk/openstack/ecs/v1/flavors"
Expand Down Expand Up @@ -72,6 +73,7 @@ func dataSourceEcsFlavorsRead(d *schema.ResourceData, meta interface{}) error {
mem := int64(d.Get("memory_size").(int))
pType := d.Get("performance_type").(string)
gen := d.Get("generation").(string)
az := d.Get("availability_zone").(string)

var ids []string
for _, flavor := range allFlavors {
Expand All @@ -92,6 +94,22 @@ func dataSourceEcsFlavorsRead(d *schema.ResourceData, meta interface{}) error {
continue
}

if az != "" {
status := flavor.OsExtraSpecs.OperationStatus
azStatusRaw := flavor.OsExtraSpecs.OperationAz
azStatusList := strings.Split(azStatusRaw, ",")
if strings.Contains(azStatusRaw, az) {
for i := 0; i < len(azStatusList); i++ {
azStatus := azStatusList[i]
if azStatus == (az+"(abandon)") || azStatus == (az+"(sellout)") || azStatus == (az+"obt_sellout") {
continue
}
}
} else if status == "abandon" || strings.Contains(status, "sellout") {
continue
}
}

ids = append(ids, flavor.ID)
}

Expand Down

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

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ github.com/hashicorp/terraform-svchost/auth
github.com/hashicorp/terraform-svchost/disco
# github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d
github.com/hashicorp/yamux
# github.com/huaweicloud/golangsdk v0.0.0-20201027014306-5ff7dac952b3
# github.com/huaweicloud/golangsdk v0.0.0-20201030072716-cb31520416ba
## explicit
github.com/huaweicloud/golangsdk
github.com/huaweicloud/golangsdk/internal
Expand Down

0 comments on commit 2c04b01

Please sign in to comment.