Skip to content

Commit

Permalink
added need_slb attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
arafato committed Oct 12, 2018
1 parent 0eddbcd commit f96df16
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 2 deletions.
24 changes: 23 additions & 1 deletion alicloud/import_alicloud_cs_swarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,29 @@ func TestAccAlicloudCSSwarm_importBasic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"name_prefix", "cidr_block", "image_id", "password", "release_eip"},
ImportStateVerifyIgnore: []string{"name_prefix", "cidr_block", "image_id", "password", "release_eip", "need_slb"},
},
},
})
}

func TestAccAlicloudCSSwarm_importBasicNoSlb(t *testing.T) {
resourceName := "alicloud_cs_swarm.cs_vpc"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckSwarmClusterDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCSSwarm_basic_noslb,
},

resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"name_prefix", "cidr_block", "image_id", "password", "release_eip", "need_slb"},
},
},
})
Expand Down
8 changes: 7 additions & 1 deletion alicloud/resource_alicloud_cs_swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ func resourceAlicloudCSSwarm() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
},

"need_slb": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: true,
ForceNew: true,
},
"nodes": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -181,6 +186,7 @@ func resourceAlicloudCSSwarmCreate(d *schema.ResourceData, meta interface{}) err
VSwitchID: d.Get("vswitch_id").(string),
SubnetCIDR: d.Get("cidr_block").(string),
ReleaseEipFlag: d.Get("release_eip").(bool),
NeedSLB: d.Get("need_slb").(bool),
}

vsw, err := client.DescribeVswitch(args.VSwitchID)
Expand Down
74 changes: 74 additions & 0 deletions alicloud/resource_alicloud_cs_swarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,35 @@ func TestAccAlicloudCSSwarm_vpc(t *testing.T) {
})
}

func TestAccAlicloudCSSwarm_vpc_noslb(t *testing.T) {
var container cs.ClusterType

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},

IDRefreshName: "alicloud_cs_swarm.cs_vpc",

Providers: testAccProviders,
CheckDestroy: testAccCheckSwarmClusterDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCSSwarm_basic_noslb,
Check: resource.ComposeTestCheckFunc(
testAccCheckContainerClusterExists("alicloud_cs_swarm.cs_vpc", &container),
resource.TestCheckResourceAttr("alicloud_cs_swarm.cs_vpc", "node_number", "2"),
resource.TestCheckResourceAttr("alicloud_cs_swarm.cs_vpc", "nodes.#", "2"),
resource.TestCheckResourceAttr("alicloud_cs_swarm.cs_vpc", "disk_category", "cloud_efficiency"),
resource.TestCheckResourceAttr("alicloud_cs_swarm.cs_vpc", "disk_size", "20"),
resource.TestCheckResourceAttr("alicloud_cs_swarm.cs_vpc", "nodes.0.eip", ""),
resource.TestCheckResourceAttr("alicloud_cs_swarm.cs_vpc", "slb_id", ""),
),
},
},
})
}

func TestAccAlicloudCSSwarm_update(t *testing.T) {
var container cs.ClusterType

Expand Down Expand Up @@ -230,6 +259,51 @@ resource "alicloud_cs_swarm" "cs_vpc" {
}
`

const testAccCSSwarm_basic_noslb = `
variable "name" {
default = "testAccCSSwarm-basic"
}
data "alicloud_images" main {
most_recent = true
name_regex = "^centos_6\\w{1,5}[64].*"
}
data "alicloud_zones" main {
available_resource_creation = "VSwitch"
}
data "alicloud_instance_types" "default" {
availability_zone = "${data.alicloud_zones.main.zones.0.id}"
cpu_core_count = 1
memory_size = 2
}
resource "alicloud_vpc" "foo" {
name = "${var.name}"
cidr_block = "10.1.0.0/21"
}
resource "alicloud_vswitch" "foo" {
name = "${var.name}"
vpc_id = "${alicloud_vpc.foo.id}"
cidr_block = "10.1.1.0/24"
availability_zone = "${data.alicloud_zones.main.zones.0.id}"
}
resource "alicloud_cs_swarm" "cs_vpc" {
password = "Just$test"
instance_type = "${data.alicloud_instance_types.default.instance_types.0.id}"
name_prefix = "${var.name}"
node_number = 2
disk_category = "cloud_efficiency"
disk_size = 20
cidr_block = "172.20.0.0/24"
image_id = "${data.alicloud_images.main.images.0.id}"
vswitch_id = "${alicloud_vswitch.foo.id}"
release_eip = "true"
need_slb = "false"
}
`

const testAccCSSwarm_update = `
variable "name" {
default = "tf-testAccCSSwarm-update"
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/cs_swarm.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ The following arguments are supported:
* `disk_size` - (Force new resource) The data disk size of ECS instance node. Its valid value is 20~32768 GB. Default to 20.
* `vswitch_id` - (Required, Force new resource) The password of ECS instance node. If it is not specified, the container cluster's network mode will be `Classic`.
* `release_eip` - Whether to release EIP after creating swarm cluster successfully. Default to false.
* `need_slb`- Whether to create the default simple routing Server Load Balancer instance for the cluster. The default value is true.


## Attributes Reference
Expand Down

0 comments on commit f96df16

Please sign in to comment.