Skip to content

Commit

Permalink
Revert "provider/alicloud: change create ecs postpaid instance API" (#…
Browse files Browse the repository at this point in the history
…12724)

* Revert "datadog: Fix incorrect schema of monitor for 'silenced' (#12720)"

This reverts commit 8730bf1.

* Revert "schema: Allow *Resource as Elem of TypeMap in validation (#12722)"

This reverts commit 1df1c21.

* Revert "provider/alicloud: change create ecs postpaid instance API (#12226)"

This reverts commit ffc5a06.
  • Loading branch information
stack72 committed Mar 15, 2017
1 parent 449c4f7 commit 481abb1
Show file tree
Hide file tree
Showing 36 changed files with 176 additions and 910 deletions.
8 changes: 0 additions & 8 deletions builtin/providers/alicloud/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package alicloud

import (
"github.com/denverdino/aliyungo/common"
"github.com/denverdino/aliyungo/ecs"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down Expand Up @@ -51,10 +50,3 @@ func isProtocalValid(value string) bool {
}
return res
}

var DefaultBusinessInfo = ecs.BusinessInfo{
Pack: "terraform",
}

// default region for all resource
const DEFAULT_REGION = "cn-beijing"
34 changes: 6 additions & 28 deletions builtin/providers/alicloud/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ type Config struct {
type AliyunClient struct {
Region common.Region
ecsconn *ecs.Client
// use new version
ecsNewconn *ecs.Client
vpcconn *ecs.Client
slbconn *slb.Client
vpcconn *ecs.Client
slbconn *slb.Client
}

// Client for AliyunClient
Expand All @@ -37,12 +35,6 @@ func (c *Config) Client() (*AliyunClient, error) {
return nil, err
}

ecsNewconn, err := c.ecsConn()
if err != nil {
return nil, err
}
ecsNewconn.SetVersion(EcsApiVersion20160314)

slbconn, err := c.slbConn()
if err != nil {
return nil, err
Expand All @@ -54,27 +46,13 @@ func (c *Config) Client() (*AliyunClient, error) {
}

return &AliyunClient{
Region: c.Region,
ecsconn: ecsconn,
ecsNewconn: ecsNewconn,
vpcconn: vpcconn,
slbconn: slbconn,
Region: c.Region,
ecsconn: ecsconn,
vpcconn: vpcconn,
slbconn: slbconn,
}, 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)
_, err := client.DescribeRegions()

if err != nil {
return nil, err
}

return client, nil
}

func (c *Config) loadAndValidate() error {
err := c.validateRegion()
if err != nil {
Expand Down
25 changes: 6 additions & 19 deletions builtin/providers/alicloud/data_source_alicloud_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"log"
"regexp"
"sort"
"time"

"github.com/denverdino/aliyungo/ecs"
"github.com/hashicorp/terraform/helper/schema"
"time"
)

func dataSourceAlicloudImages() *schema.Resource {
Expand Down Expand Up @@ -175,28 +175,15 @@ func dataSourceAlicloudImagesRead(d *schema.ResourceData, meta interface{}) erro
params.ImageOwnerAlias = ecs.ImageOwnerAlias(owners.(string))
}

var allImages []ecs.ImageType

for {
images, paginationResult, err := conn.DescribeImages(params)
if err != nil {
break
}

allImages = append(allImages, images...)

pagination := paginationResult.NextPage()
if pagination == nil {
break
}

params.Pagination = *pagination
resp, _, err := conn.DescribeImages(params)
if err != nil {
return err
}

var filteredImages []ecs.ImageType
if nameRegexOk {
r := regexp.MustCompile(nameRegex.(string))
for _, image := range allImages {
for _, image := range resp {
// Check for a very rare case where the response would include no
// image name. No name means nothing to attempt a match against,
// therefore we are skipping such image.
Expand All @@ -211,7 +198,7 @@ func dataSourceAlicloudImagesRead(d *schema.ResourceData, meta interface{}) erro
}
}
} else {
filteredImages = allImages[:]
filteredImages = resp[:]
}

var images []ecs.ImageType
Expand Down
25 changes: 0 additions & 25 deletions builtin/providers/alicloud/data_source_alicloud_images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,6 @@ func TestAccAlicloudImagesDataSource_nameRegexFilter(t *testing.T) {
})
}

func TestAccAlicloudImagesDataSource_imageNotInFirstPage(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckAlicloudImagesDataSourceImageNotInFirstPageConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAlicloudDataSourceID("data.alicloud_images.name_regex_filtered_image"),
resource.TestMatchResourceAttr("data.alicloud_images.name_regex_filtered_image", "images.0.image_id", regexp.MustCompile("^ubuntu_1404")),
),
},
},
})
}

// Instance store test - using centos images
const testAccCheckAlicloudImagesDataSourceImagesConfig = `
data "alicloud_images" "multi_image" {
Expand Down Expand Up @@ -144,12 +128,3 @@ data "alicloud_images" "name_regex_filtered_image" {
name_regex = "^centos_6\\w{1,5}[64]{1}.*"
}
`

// Testing image not in first page response
const testAccCheckAlicloudImagesDataSourceImageNotInFirstPageConfig = `
data "alicloud_images" "name_regex_filtered_image" {
most_recent = true
owners = "system"
name_regex = "^ubuntu_1404\\d{2}_64"
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ func TestAccAlicloudInstanceTypesDataSource_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckAlicloudDataSourceID("data.alicloud_instance_types.4c8g"),

resource.TestCheckResourceAttr("data.alicloud_instance_types.4c8g", "instance_types.#", "4"),

resource.TestCheckResourceAttr("data.alicloud_instance_types.4c8g", "instance_types.0.cpu_core_count", "4"),
resource.TestCheckResourceAttr("data.alicloud_instance_types.4c8g", "instance_types.0.memory_size", "8"),
resource.TestCheckResourceAttr("data.alicloud_instance_types.4c8g", "instance_types.0.id", "ecs.s3.large"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func TestAccAlicloudRegionsDataSource_empty(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckAlicloudDataSourceID("data.alicloud_regions.empty_params_region"),

resource.TestCheckResourceAttr("data.alicloud_regions.empty_params_region", "name", ""),
resource.TestCheckResourceAttr("data.alicloud_regions.empty_params_region", "current", ""),

resource.TestCheckResourceAttr("data.alicloud_regions.empty_params_region", "regions.#", "13"),

resource.TestCheckResourceAttr("data.alicloud_regions.empty_params_region", "regions.0.id", "cn-shenzhen"),
Expand Down
36 changes: 2 additions & 34 deletions builtin/providers/alicloud/data_source_alicloud_zones_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package alicloud

import (
"fmt"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"strconv"
"testing"
)

Expand All @@ -26,35 +23,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() {
testAccPreCheck(t)
Expand All @@ -65,15 +33,15 @@ func TestAccAlicloudZonesDataSource_filter(t *testing.T) {
Config: testAccCheckAlicloudZonesDataSourceFilter,
Check: resource.ComposeTestCheckFunc(
testAccCheckAlicloudDataSourceID("data.alicloud_zones.foo"),
testCheckZoneLength("data.alicloud_zones.foo"),
resource.TestCheckResourceAttr("data.alicloud_zones.foo", "zones.#", "2"),
),
},

resource.TestStep{
Config: testAccCheckAlicloudZonesDataSourceFilterIoOptimized,
Check: resource.ComposeTestCheckFunc(
testAccCheckAlicloudDataSourceID("data.alicloud_zones.foo"),
testCheckZoneLength("data.alicloud_zones.foo"),
resource.TestCheckResourceAttr("data.alicloud_zones.foo", "zones.#", "1"),
),
},
},
Expand Down
5 changes: 0 additions & 5 deletions builtin/providers/alicloud/extension_ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,3 @@ const (
GroupRulePolicyAccept = GroupRulePolicy("accept")
GroupRulePolicyDrop = GroupRulePolicy("drop")
)

const (
EcsApiVersion20160314 = "2016-03-14"
EcsApiVersion20140526 = "2014-05-26"
)
2 changes: 1 addition & 1 deletion builtin/providers/alicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func Provider() terraform.ResourceProvider {
"region": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("ALICLOUD_REGION", DEFAULT_REGION),
DefaultFunc: schema.EnvDefaultFunc("ALICLOUD_REGION", "cn-beijing"),
Description: descriptions["region"],
},
},
Expand Down
15 changes: 3 additions & 12 deletions builtin/providers/alicloud/resource_alicloud_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,29 +136,20 @@ func testAccCheckDiskDestroy(s *terraform.State) error {
}

const testAccDiskConfig = `
data "alicloud_zones" "default" {
"available_disk_category"= "cloud_efficiency"
}
resource "alicloud_disk" "foo" {
# cn-beijing
availability_zone = "${data.alicloud_zones.default.zones.0.id}"
availability_zone = "cn-beijing-b"
name = "New-disk"
description = "Hello ecs disk."
category = "cloud_efficiency"
size = "30"
}
`
const testAccDiskConfigWithTags = `
data "alicloud_zones" "default" {
"available_disk_category"= "cloud_efficiency"
}
resource "alicloud_disk" "bar" {
# cn-beijing
availability_zone = "${data.alicloud_zones.default.zones.0.id}"
category = "cloud_efficiency"
size = "20"
availability_zone = "cn-beijing-b"
size = "10"
tags {
Name = "TerraformTest"
}
Expand Down
Loading

0 comments on commit 481abb1

Please sign in to comment.