-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29e1be9
commit cf0d47b
Showing
29 changed files
with
1,849 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package huaweicloud | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/huaweicloud/golangsdk/openstack/dcs/v1/availablezones" | ||
) | ||
|
||
func dataSourceDcsAZV1() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceDcsAZV1Read, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"code": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"port": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceDcsAZV1Read(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
dcsV1Client, err := config.dcsV1Client(GetRegion(d, config)) | ||
if err != nil { | ||
return fmt.Errorf("Error creating dcs key client: %s", err) | ||
} | ||
|
||
v, err := availablezones.Get(dcsV1Client).Extract() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Printf("[DEBUG] Dcs az : %+v", v) | ||
var filteredAZs []availablezones.AvailableZone | ||
if v.RegionID == GetRegion(d, config) { | ||
AZs := v.AvailableZones | ||
for _, newAZ := range AZs { | ||
if newAZ.ResourceAvailability != "true" { | ||
continue | ||
} | ||
|
||
name := d.Get("name").(string) | ||
if name != "" && newAZ.Name != name { | ||
continue | ||
} | ||
|
||
port := d.Get("port").(string) | ||
if port != "" && newAZ.Port != port { | ||
continue | ||
} | ||
filteredAZs = append(filteredAZs, newAZ) | ||
} | ||
} | ||
|
||
if len(filteredAZs) < 1 { | ||
return fmt.Errorf("Not found any available zones") | ||
} | ||
|
||
az := filteredAZs[0] | ||
log.Printf("[DEBUG] Dcs az : %+v", az) | ||
|
||
d.SetId(az.ID) | ||
d.Set("code", az.Code) | ||
d.Set("name", az.Name) | ||
d.Set("port", az.Port) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package huaweicloud | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccDcsAZV1DataSource_basic(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccDcsAZV1DataSource_basic, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckDcsAZV1DataSourceID("data.huaweicloud_dcs_az_v1.az1"), | ||
resource.TestCheckResourceAttr( | ||
"data.huaweicloud_dcs_az_v1.az1", "port", "8002"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckDcsAZV1DataSourceID(n string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
if !ok { | ||
return fmt.Errorf("Can't find Dcs az data source: %s", n) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("Dcs az data source ID not set") | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
var testAccDcsAZV1DataSource_basic = fmt.Sprintf(` | ||
data "huaweicloud_dcs_az_v1" "az1" { | ||
code = "%s" | ||
port = "8002" | ||
} | ||
`, OS_AVAILABILITY_ZONE) |
87 changes: 87 additions & 0 deletions
87
huaweicloud/data_source_huaweicloud_dcs_maintainwindow_v1.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package huaweicloud | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"strconv" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/huaweicloud/golangsdk/openstack/dcs/v1/maintainwindows" | ||
) | ||
|
||
func dataSourceDcsMaintainWindowV1() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceDcsMaintainWindowV1Read, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"seq": &schema.Schema{ | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"begin": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"end": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"default": &schema.Schema{ | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceDcsMaintainWindowV1Read(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
dcsV1Client, err := config.dcsV1Client(GetRegion(d, config)) | ||
if err != nil { | ||
return fmt.Errorf("Error creating dcs key client: %s", err) | ||
} | ||
|
||
v, err := maintainwindows.Get(dcsV1Client).Extract() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
maintainWindows := v.MaintainWindows | ||
var filteredMVs []maintainwindows.MaintainWindow | ||
for _, mv := range maintainWindows { | ||
seq := d.Get("seq").(int) | ||
if seq != 0 && mv.ID != seq { | ||
continue | ||
} | ||
|
||
begin := d.Get("begin").(string) | ||
if begin != "" && mv.Begin != begin { | ||
continue | ||
} | ||
end := d.Get("end").(string) | ||
if end != "" && mv.End != end { | ||
continue | ||
} | ||
|
||
df := d.Get("default").(bool) | ||
if mv.Default != df { | ||
continue | ||
} | ||
filteredMVs = append(filteredMVs, mv) | ||
} | ||
if len(filteredMVs) < 1 { | ||
return fmt.Errorf("Your query returned no results. Please change your filters and try again.") | ||
} | ||
mw := filteredMVs[0] | ||
d.SetId(strconv.Itoa(mw.ID)) | ||
d.Set("begin", mw.Begin) | ||
d.Set("end", mw.End) | ||
d.Set("default", mw.Default) | ||
log.Printf("[DEBUG] Dcs MaintainWindow : %+v", mw) | ||
|
||
return nil | ||
} |
49 changes: 49 additions & 0 deletions
49
huaweicloud/data_source_huaweicloud_dcs_maintainwindow_v1_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package huaweicloud | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccDcsMaintainWindowV1DataSource_basic(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccDcsMaintainWindowV1DataSource_basic, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckDcsMaintainWindowV1DataSourceID("data.huaweicloud_dcs_maintainwindow_v1.maintainwindow1"), | ||
resource.TestCheckResourceAttr( | ||
"data.huaweicloud_dcs_maintainwindow_v1.maintainwindow1", "seq", "1"), | ||
resource.TestCheckResourceAttr( | ||
"data.huaweicloud_dcs_maintainwindow_v1.maintainwindow1", "begin", "22"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckDcsMaintainWindowV1DataSourceID(n string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
if !ok { | ||
return fmt.Errorf("Can't find Dcs maintainwindow data source: %s", n) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("Dcs maintainwindow data source ID not set") | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
var testAccDcsMaintainWindowV1DataSource_basic = fmt.Sprintf(` | ||
data "huaweicloud_dcs_maintainwindow_v1" "maintainwindow1" { | ||
seq = 1 | ||
} | ||
`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package huaweicloud | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/huaweicloud/golangsdk/openstack/dcs/v1/products" | ||
) | ||
|
||
func dataSourceDcsProductV1() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceDcsProductV1Read, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"spec_code": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceDcsProductV1Read(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
dcsV1Client, err := config.dcsV1Client(GetRegion(d, config)) | ||
if err != nil { | ||
return fmt.Errorf("Error get dcs product client: %s", err) | ||
} | ||
|
||
v, err := products.Get(dcsV1Client).Extract() | ||
if err != nil { | ||
return err | ||
} | ||
log.Printf("[DEBUG] Dcs get products : %+v", v) | ||
var FilteredPd []products.Product | ||
for _, pd := range v.Products { | ||
spec_code := d.Get("spec_code").(string) | ||
if spec_code != "" && pd.SpecCode != spec_code { | ||
continue | ||
} | ||
FilteredPd = append(FilteredPd, pd) | ||
} | ||
|
||
if len(FilteredPd) < 1 { | ||
return fmt.Errorf("Your query returned no results. Please change your filters and try again.") | ||
} | ||
|
||
pd := FilteredPd[0] | ||
d.SetId(pd.ProductID) | ||
d.Set("spec_code", pd.SpecCode) | ||
log.Printf("[DEBUG] Dcs product : %+v", pd) | ||
|
||
return nil | ||
} |
47 changes: 47 additions & 0 deletions
47
huaweicloud/data_source_huaweicloud_dcs_product_v1_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package huaweicloud | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccDcsProductV1DataSource_basic(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccDcsProductV1DataSource_basic, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckDcsProductV1DataSourceID("data.huaweicloud_dcs_product_v1.product1"), | ||
resource.TestCheckResourceAttr( | ||
"data.huaweicloud_dcs_product_v1.product1", "spec_code", "dcs.single_node"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckDcsProductV1DataSourceID(n string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
if !ok { | ||
return fmt.Errorf("Can't find Dcs product data source: %s", n) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("Dcs product data source ID not set") | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
var testAccDcsProductV1DataSource_basic = fmt.Sprintf(` | ||
data "huaweicloud_dcs_product_v1" "product1" { | ||
spec_code = "dcs.single_node" | ||
} | ||
`) |
Oops, something went wrong.