-
Notifications
You must be signed in to change notification settings - Fork 162
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
root
committed
Sep 27, 2018
1 parent
0fd3d6c
commit e65d22f
Showing
33 changed files
with
2,579 additions
and
1 deletion.
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,83 @@ | ||
package huaweicloud | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/huaweicloud/golangsdk/openstack/dms/v1/availablezones" | ||
) | ||
|
||
func dataSourceDmsAZV1() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceDmsAZV1Read, | ||
|
||
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 dataSourceDmsAZV1Read(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
dmsV1Client, err := config.dmsV1Client(GetRegion(d, config)) | ||
if err != nil { | ||
return fmt.Errorf("Error creating HuaweiCloud kms key client: %s", err) | ||
} | ||
|
||
v, err := availablezones.Get(dmsV1Client).Extract() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Printf("[DEBUG] Dms 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] Dms az : %+v", az) | ||
|
||
d.SetId(az.ID) | ||
d.Set("code", az.Code) | ||
d.Set("name", az.Name) | ||
d.Set("port", az.Port) | ||
d.Set("resource_availability", az.ResourceAvailability) | ||
|
||
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,53 @@ | ||
package huaweicloud | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccDmsAZV1DataSource_basic(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccDmsAZV1DataSource_basic, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckDmsAZV1DataSourceID("data.huaweicloud_dms_az_v1.az1"), | ||
resource.TestCheckResourceAttr( | ||
"data.huaweicloud_dms_az_v1.az1", "name", "可用区1"), | ||
resource.TestCheckResourceAttr( | ||
"data.huaweicloud_dms_az_v1.az1", "port", "8002"), | ||
resource.TestCheckResourceAttr( | ||
"data.huaweicloud_dms_az_v1.az1", "code", "cn-north-1a"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckDmsAZV1DataSourceID(n string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
if !ok { | ||
return fmt.Errorf("Can't find Dms az data source: %s", n) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("Dms az data source ID not set") | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
var testAccDmsAZV1DataSource_basic = fmt.Sprintf(` | ||
data "huaweicloud_dms_az_v1" "az1" { | ||
name = "可用区1" | ||
port = "8002" | ||
code = "cn-north-1a" | ||
} | ||
`) |
87 changes: 87 additions & 0 deletions
87
huaweicloud/data_source_huaweicloud_dms_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/dms/v1/maintainwindows" | ||
) | ||
|
||
func dataSourceDmsMaintainWindowV1() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceDmsMaintainWindowV1Read, | ||
|
||
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 dataSourceDmsMaintainWindowV1Read(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
dmsV1Client, err := config.dmsV1Client(GetRegion(d, config)) | ||
if err != nil { | ||
return fmt.Errorf("Error creating HuaweiCloud kms key client: %s", err) | ||
} | ||
|
||
v, err := maintainwindows.Get(dmsV1Client).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] Dms MaintainWindow : %+v", mw) | ||
|
||
return nil | ||
} |
49 changes: 49 additions & 0 deletions
49
huaweicloud/data_source_huaweicloud_dms_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 TestAccDmsMaintainWindowV1DataSource_basic(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccDmsMaintainWindowV1DataSource_basic, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckDmsMaintainWindowV1DataSourceID("data.huaweicloud_dms_maintainwindow_v1.maintainwindow1"), | ||
resource.TestCheckResourceAttr( | ||
"data.huaweicloud_dms_maintainwindow_v1.maintainwindow1", "seq", "1"), | ||
resource.TestCheckResourceAttr( | ||
"data.huaweicloud_dms_maintainwindow_v1.maintainwindow1", "begin", "22"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckDmsMaintainWindowV1DataSourceID(n string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
if !ok { | ||
return fmt.Errorf("Can't find Dms maintainwindow data source: %s", n) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("Dms maintainwindow data source ID not set") | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
var testAccDmsMaintainWindowV1DataSource_basic = fmt.Sprintf(` | ||
data "huaweicloud_dms_maintainwindow_v1" "maintainwindow1" { | ||
seq = 1 | ||
} | ||
`) |
Oops, something went wrong.