Skip to content

Commit

Permalink
Merge pull request #103 from alibaba/dev
Browse files Browse the repository at this point in the history
some bugfix
  • Loading branch information
shuwei-yin authored Mar 17, 2017
2 parents 8f2bd5b + ec033a4 commit 92fb4a4
Show file tree
Hide file tree
Showing 29 changed files with 670 additions and 432 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
## 1.0.4 (unreleased)

BUG FIXES:

* resource/alicloud_db_instance: fix rds update failed bug ([#102](https://github.com/alibaba/terraform-provider/pull/102))
* resource/alicloud_instance: fix ecs instance system disk size not work bug ([#100](https://github.com/alibaba/terraform-provider/pull/100))

IMPROVEMENTS:

* alicloud/config: add businessinfo to sdk client ([#96](https://github.com/alibaba/terraform-provider/pull/96))

## 1.0.3 (March 4, 2017)

FEATURES:
Expand Down
36 changes: 11 additions & 25 deletions alicloud/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,7 @@ func (c *Config) Client() (*AliyunClient, error) {
}, nil
}

// return new ecs Client
// when you need new client not global client, use this method
func (c *Config) NewEcsConn() (*ecs.Client, error) {
client := ecs.NewClient(c.AccessKey, c.SecretKey)
client.SetBusinessInfo("Terraform")
_, err := client.DescribeRegions()

if err != nil {
return nil, err
}

return client, nil
}
const BusinessInfoKey = "Terraform"

func (c *Config) loadAndValidate() error {
err := c.validateRegion()
Expand All @@ -105,7 +93,9 @@ func (c *Config) validateRegion() error {
}

func (c *Config) ecsConn() (*ecs.Client, error) {
client := ecs.NewClient(c.AccessKey, c.SecretKey)
client := ecs.NewECSClient(c.AccessKey, c.SecretKey, c.Region)
client.SetBusinessInfo(BusinessInfoKey)

_, err := client.DescribeRegions()

if err != nil {
Expand All @@ -116,24 +106,20 @@ func (c *Config) ecsConn() (*ecs.Client, error) {
}

func (c *Config) rdsConn() (*rds.Client, error) {
client := rds.NewClient(c.AccessKey, c.SecretKey)
client := rds.NewRDSClient(c.AccessKey, c.SecretKey, c.Region)
client.SetBusinessInfo(BusinessInfoKey)
return client, nil
}

func (c *Config) slbConn() (*slb.Client, error) {
client := slb.NewClient(c.AccessKey, c.SecretKey)

client := slb.NewSLBClient(c.AccessKey, c.SecretKey, c.Region)
client.SetBusinessInfo(BusinessInfoKey)
return client, nil
}

func (c *Config) vpcConn() (*ecs.Client, error) {
_, err := c.ecsConn()

if err != nil {
return nil, err
}

client := &ecs.Client{}
client.Init("https://vpc.aliyuncs.com/", "2016-04-28", c.AccessKey, c.SecretKey)
client := ecs.NewVPCClient(c.AccessKey, c.SecretKey, c.Region)
client.SetBusinessInfo(BusinessInfoKey)
return client, nil

}
98 changes: 64 additions & 34 deletions alicloud/data_source_alicloud_zones_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,6 @@ func TestAccAlicloudZonesDataSource_basic(t *testing.T) {
}

func TestAccAlicloudZonesDataSource_filter(t *testing.T) {
// the zone length changed occasionally
// check by range to avoid test case failure
testCheckZoneLength := func(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
ms := s.RootModule()
rs, ok := ms.Resources[name]
if !ok {
return fmt.Errorf("Not found: %s", name)
}

is := rs.Primary
if is == nil {
return fmt.Errorf("No primary instance: %s", name)
}

i, err := strconv.Atoi(is.Attributes["zones.#"])

if err != nil {
return fmt.Errorf("convert zone length err: %#v", err)
}

if i <= 0 {
return fmt.Errorf("zone length expected greater than 0 got err: %d", i)
}

return nil
}
}

resource.Test(t, resource.TestCase{
PreCheck: func() {
Expand All @@ -80,23 +52,81 @@ func TestAccAlicloudZonesDataSource_filter(t *testing.T) {
})
}

func TestAccAlicloudZonesDataSource_unitRegion(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckAlicloudZonesDataSource_unitRegion,
Check: resource.ComposeTestCheckFunc(
testAccCheckAlicloudDataSourceID("data.alicloud_zones.foo"),
),
},
},
})
}

// the zone length changed occasionally
// check by range to avoid test case failure
func testCheckZoneLength(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
ms := s.RootModule()
rs, ok := ms.Resources[name]
if !ok {
return fmt.Errorf("Not found: %s", name)
}

is := rs.Primary
if is == nil {
return fmt.Errorf("No primary instance: %s", name)
}

i, err := strconv.Atoi(is.Attributes["zones.#"])

if err != nil {
return fmt.Errorf("convert zone length err: %#v", err)
}

if i <= 0 {
return fmt.Errorf("zone length expected greater than 0 got err: %d", i)
}

return nil
}
}

const testAccCheckAlicloudZonesDataSourceBasicConfig = `
data "alicloud_zones" "foo" {
}
`

const testAccCheckAlicloudZonesDataSourceFilter = `
data "alicloud_zones" "foo" {
"available_instance_type"= "ecs.c2.xlarge"
"available_resource_creation"= "VSwitch"
"available_disk_category"= "cloud_efficiency"
available_instance_type= "ecs.c2.xlarge"
available_resource_creation= "VSwitch"
available_disk_category= "cloud_efficiency"
}
`

const testAccCheckAlicloudZonesDataSourceFilterIoOptimized = `
data "alicloud_zones" "foo" {
"available_instance_type"= "ecs.c2.xlarge"
"available_resource_creation"= "IoOptimized"
"available_disk_category"= "cloud"
available_instance_type= "ecs.c2.xlarge"
available_resource_creation= "IoOptimized"
available_disk_category= "cloud"
}
`

const testAccCheckAlicloudZonesDataSource_unitRegion = `
provider "alicloud" {
alias = "northeast"
region = "ap-northeast-1"
}
data "alicloud_zones" "foo" {
provider = "alicloud.northeast"
available_resource_creation= "VSwitch"
}
`
1 change: 1 addition & 0 deletions alicloud/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const (
DiskIncorrectStatus = "IncorrectDiskStatus"
DiskCreatingSnapshot = "DiskCreatingSnapshot"
InstanceLockedForSecurity = "InstanceLockedForSecurity"
SystemDiskNotFound = "SystemDiskNotFound"
// eip
EipIncorrectStatus = "IncorrectEipStatus"
InstanceIncorrectStatus = "IncorrectInstanceStatus"
Expand Down
Loading

0 comments on commit 92fb4a4

Please sign in to comment.