Skip to content

Commit c692b78

Browse files
authored
Merge pull request #88 from xiaozhu36/master
Avoid container cluster cidr block conflicts with vswitch
2 parents 424f584 + 3dc15e4 commit c692b78

11 files changed

+101
-34
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
IMPROVEMENTS:
44

5+
- Support to set instnace name for RDS ([#89](https://github.com/terraform-providers/terraform-provider-alicloud/pull/89))
6+
- Avoid container cluster cidr block conflicts with vswitch's ([#88](https://github.com/terraform-providers/terraform-provider-alicloud/pull/88))
57
- Output resource import information ([#87](https://github.com/terraform-providers/terraform-provider-alicloud/pull/87))
68

79
BUG FIXES:

alicloud/diff_suppress_funcs.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,6 @@ func ecsChargeTypeSuppressFunc(k, old, new string, d *schema.ResourceData) bool
143143
func zoneIdDiffSuppressFunc(k, old, new string, d *schema.ResourceData) bool {
144144
if vsw, ok := d.GetOk("vswitch_id"); ok && vsw.(string) != "" {
145145
return true
146-
} else if vsw, ok := d.GetOk("subnet_id"); ok && vsw.(string) != "" {
147-
return true
148146
} else if multi, ok := d.GetOk("multi_az"); ok && multi.(bool) {
149147
return true
150148
}

alicloud/errors.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const (
7171
ScalingActivityInProgress = "ScalingActivityInProgress"
7272

7373
// rds
74+
InvalidDBInstanceIdNotFound = "InvalidDBInstanceId.NotFound"
7475
InvalidDBNameNotFound = "InvalidDBName.NotFound"
7576
InvalidDBInstanceNameNotFound = "InvalidDBInstanceName.NotFound"
7677
InvalidCurrentConnectionStringNotFound = "InvalidCurrentConnectionString.NotFound"
@@ -80,6 +81,9 @@ const (
8081
OperationDeniedDBInstanceStatus = "OperationDenied.DBInstanceStatus"
8182
InvalidConnectionStringDuplicate = "InvalidConnectionString.Duplicate"
8283
AtLeastOneNetTypeExists = "AtLeastOneNetTypeExists"
84+
ConnectionOperationDenied = "OperationDenied"
85+
ConnectionConflictMessage = "The requested resource is sold out in the specified zone; try other types of resources or other regions and zones"
86+
DBInternalError = "InternalError"
8387
// oss
8488
OssBucketNotFound = "NoSuchBucket"
8589
OssBodyNotFound = "404 Not Found"

alicloud/resource_alicloud_container_cluster.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ func resourceAlicloudContainerClusterCreate(d *schema.ResourceData, meta interfa
126126
}
127127
args.NetworkMode = cs.VPCNetwork
128128
args.VSwitchID = v.(string)
129-
args.SubnetCIDR = cidr.(string)
130129

131130
vswInfo, _, err := client.vpcconn.DescribeVSwitches(&ecs.DescribeVSwitchesArgs{
132131
RegionId: getRegion(d, meta),
@@ -138,6 +137,11 @@ func resourceAlicloudContainerClusterCreate(d *schema.ResourceData, meta interfa
138137
if len(vswInfo) < 1 {
139138
return fmt.Errorf("There is not found specified vswitch: %s, please check and try again.", v.(string))
140139
}
140+
if vswInfo[0].CidrBlock == cidr.(string) {
141+
return fmt.Errorf("Container cluster's cidr_block only accepts 192.168.X.0/24 or 172.18.X.0/24 ~ 172.31.X.0/24. " +
142+
"And it cannot be equal to vswitch's cidr_block and sub cidr block.")
143+
}
144+
args.SubnetCIDR = cidr.(string)
141145
args.VPCID = vswInfo[0].VpcId
142146
} else {
143147
args.NetworkMode = cs.ClassicNetwork

alicloud/resource_alicloud_db_instance.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ func resourceAlicloudDBInstance() *schema.Resource {
9494
ForceNew: true,
9595
Optional: true,
9696
},
97+
"instance_name": &schema.Schema{
98+
Type: schema.TypeString,
99+
Optional: true,
100+
ValidateFunc: validateDBInstanceName,
101+
},
97102

98103
"connection_string": &schema.Schema{
99104
Type: schema.TypeString,
@@ -286,13 +291,26 @@ func resourceAlicloudDBInstanceUpdate(d *schema.ResourceData, meta interface{})
286291
}
287292

288293
if update {
294+
// wait instance status is running before modifying
295+
if err := conn.WaitForInstanceAsyn(d.Id(), rds.Running, 500); err != nil {
296+
return fmt.Errorf("WaitForInstance %s got error: %#v", rds.Running, err)
297+
}
289298
if _, err := conn.ModifyDBInstanceSpec(&args); err != nil {
290299
return err
291300
}
292-
//// wait instance status change from Creating to running
293-
//if err := conn.WaitForInstanceAsyn(d.Id(), rds.Running, defaultLongTimeout); err != nil {
294-
// return fmt.Errorf("WaitForInstance %s got error: %#v", rds.Running, err)
295-
//}
301+
// wait instance status is running after modifying
302+
if err := conn.WaitForInstanceAsyn(d.Id(), rds.Running, 500); err != nil {
303+
return fmt.Errorf("WaitForInstance %s got error: %#v", rds.Running, err)
304+
}
305+
}
306+
307+
if d.HasChange("instance_name") {
308+
if err := conn.ModifyDBInstanceDescription(&rds.ModifyDBInstanceDescriptionArgs{
309+
DBInstanceId: d.Id(),
310+
DBInstanceDescription: d.Get("instance_name").(string),
311+
}); err != nil {
312+
return fmt.Errorf("ModifyDBInstanceDescription got an error: %#v", err)
313+
}
296314
}
297315

298316
d.Partial(false)
@@ -304,7 +322,7 @@ func resourceAlicloudDBInstanceRead(d *schema.ResourceData, meta interface{}) er
304322

305323
instance, err := client.DescribeDBInstanceById(d.Id())
306324
if err != nil {
307-
if NotFoundError(err) || IsExceptedError(err, InvalidDBInstanceNameNotFound) {
325+
if NotFoundError(err) || IsExceptedError(err, InvalidDBInstanceIdNotFound) || IsExceptedError(err, InvalidDBInstanceNameNotFound) {
308326
d.SetId("")
309327
return nil
310328
}
@@ -327,6 +345,7 @@ func resourceAlicloudDBInstanceRead(d *schema.ResourceData, meta interface{}) er
327345
d.Set("period", d.Get("period"))
328346
d.Set("vswitch_id", instance.VSwitchId)
329347
d.Set("connection_string", instance.ConnectionString)
348+
d.Set("instance_name", instance.DBInstanceDescription)
330349

331350
return nil
332351
}
@@ -348,7 +367,7 @@ func resourceAlicloudDBInstanceDelete(d *schema.ResourceData, meta interface{})
348367
err := client.rdsconn.DeleteInstance(d.Id())
349368

350369
if err != nil {
351-
if NotFoundError(err) || IsExceptedError(err, InvalidDBInstanceNameNotFound) {
370+
if NotFoundError(err) || IsExceptedError(err, InvalidDBInstanceIdNotFound) || IsExceptedError(err, InvalidDBInstanceNameNotFound) {
352371
return nil
353372
}
354373
return resource.RetryableError(fmt.Errorf("Delete DB instance timeout and got an error: %#v.", err))

alicloud/resource_alicloud_db_instance_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ func TestAccAlicloudDBInstance_basic(t *testing.T) {
4242
"alicloud_db_instance.foo",
4343
"engine",
4444
"MySQL"),
45+
resource.TestCheckResourceAttr(
46+
"alicloud_db_instance.foo",
47+
"instance_name",
48+
"test-instance"),
4549
),
4650
},
4751
},
@@ -284,7 +288,7 @@ func testAccCheckDBInstanceDestroy(s *terraform.State) error {
284288

285289
// Verify the error is what we want
286290
if err != nil {
287-
if NotFoundError(err) || IsExceptedError(err, InvalidDBInstanceNameNotFound) {
291+
if NotFoundError(err) || IsExceptedError(err, InvalidDBInstanceIdNotFound) || IsExceptedError(err, InvalidDBInstanceNameNotFound) {
288292
continue
289293
}
290294
return err
@@ -301,6 +305,7 @@ resource "alicloud_db_instance" "foo" {
301305
instance_type = "rds.mysql.t1.small"
302306
instance_storage = "10"
303307
instance_charge_type = "Postpaid"
308+
instance_name = "test-instance"
304309
}
305310
`
306311

alicloud/validators.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,3 +1079,21 @@ func validateInstanceSpotStrategy(v interface{}, k string) (ws []string, errors
10791079
}
10801080
return
10811081
}
1082+
1083+
func validateDBConnectionPrefix(v interface{}, k string) (ws []string, errors []error) {
1084+
if value := v.(string); value != "" {
1085+
if len(value) < 1 || len(value) > 31 {
1086+
errors = append(errors, fmt.Errorf("%q cannot be less than 1 and larger than 30.", k))
1087+
}
1088+
}
1089+
return
1090+
}
1091+
1092+
func validateDBInstanceName(v interface{}, k string) (ws []string, errors []error) {
1093+
if value := v.(string); value != "" {
1094+
if len(value) < 2 || len(value) > 256 {
1095+
errors = append(errors, fmt.Errorf("%q cannot be less than 1 and larger than 30.", k))
1096+
}
1097+
}
1098+
return
1099+
}

vendor/github.com/denverdino/aliyungo/rds/instances.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/vendor.json

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -235,68 +235,68 @@
235235
{
236236
"checksumSHA1": "9bZS3sdYQuY8j2Fxi9sEoQl2ibQ=",
237237
"path": "github.com/denverdino/aliyungo/cdn",
238-
"revision": "f6ec6f26ec42e39b07c75c738eb30c869d305ce5",
239-
"revisionTime": "2018-01-18T01:34:02Z"
238+
"revision": "c0d28eeada35fc1c63b16865b438ee277ca179fb",
239+
"revisionTime": "2018-01-19T08:28:08Z"
240240
},
241241
{
242242
"checksumSHA1": "6jhMTB/kEVfbbszOdOyYODYFk5Q=",
243243
"path": "github.com/denverdino/aliyungo/common",
244-
"revision": "f6ec6f26ec42e39b07c75c738eb30c869d305ce5",
245-
"revisionTime": "2018-01-18T01:34:02Z"
244+
"revision": "c0d28eeada35fc1c63b16865b438ee277ca179fb",
245+
"revisionTime": "2018-01-19T08:28:08Z"
246246
},
247247
{
248248
"checksumSHA1": "JgK7hgdP+yfsRin1lbz0LjBVtic=",
249249
"path": "github.com/denverdino/aliyungo/cs",
250-
"revision": "f6ec6f26ec42e39b07c75c738eb30c869d305ce5",
251-
"revisionTime": "2018-01-18T01:34:02Z"
250+
"revision": "c0d28eeada35fc1c63b16865b438ee277ca179fb",
251+
"revisionTime": "2018-01-19T08:28:08Z"
252252
},
253253
{
254254
"checksumSHA1": "0y6d3UiB8JckT3YTeXjMbLkSibg=",
255255
"path": "github.com/denverdino/aliyungo/dns",
256-
"revision": "f6ec6f26ec42e39b07c75c738eb30c869d305ce5",
257-
"revisionTime": "2018-01-18T01:34:02Z"
256+
"revision": "c0d28eeada35fc1c63b16865b438ee277ca179fb",
257+
"revisionTime": "2018-01-19T08:28:08Z"
258258
},
259259
{
260260
"checksumSHA1": "p0MBe0iRbSkAhLFYX7n/+wsfJJY=",
261261
"path": "github.com/denverdino/aliyungo/ecs",
262-
"revision": "f6ec6f26ec42e39b07c75c738eb30c869d305ce5",
263-
"revisionTime": "2018-01-18T01:34:02Z"
262+
"revision": "c0d28eeada35fc1c63b16865b438ee277ca179fb",
263+
"revisionTime": "2018-01-19T08:28:08Z"
264264
},
265265
{
266266
"checksumSHA1": "ppmAWGfRcffPvGcqpUbxdWwkUbg=",
267267
"path": "github.com/denverdino/aliyungo/ess",
268-
"revision": "f6ec6f26ec42e39b07c75c738eb30c869d305ce5",
269-
"revisionTime": "2018-01-18T01:34:02Z"
268+
"revision": "c0d28eeada35fc1c63b16865b438ee277ca179fb",
269+
"revisionTime": "2018-01-19T08:28:08Z"
270270
},
271271
{
272272
"checksumSHA1": "CPuR3s7LzQkT57Z20zMHXQM2MYQ=",
273273
"path": "github.com/denverdino/aliyungo/location",
274-
"revision": "f6ec6f26ec42e39b07c75c738eb30c869d305ce5",
275-
"revisionTime": "2018-01-18T01:34:02Z"
274+
"revision": "c0d28eeada35fc1c63b16865b438ee277ca179fb",
275+
"revisionTime": "2018-01-19T08:28:08Z"
276276
},
277277
{
278278
"checksumSHA1": "mkaQUrh01nWescV/Ek7Yv/WwX9Q=",
279279
"path": "github.com/denverdino/aliyungo/ram",
280-
"revision": "f6ec6f26ec42e39b07c75c738eb30c869d305ce5",
281-
"revisionTime": "2018-01-18T01:34:02Z"
280+
"revision": "c0d28eeada35fc1c63b16865b438ee277ca179fb",
281+
"revisionTime": "2018-01-19T08:28:08Z"
282282
},
283283
{
284-
"checksumSHA1": "EVzLqNTiuKKF5Ay5Cy5+TETjpvk=",
284+
"checksumSHA1": "D4ugog0rIZolvzyH2Wf/p+eUJOE=",
285285
"path": "github.com/denverdino/aliyungo/rds",
286-
"revision": "f6ec6f26ec42e39b07c75c738eb30c869d305ce5",
287-
"revisionTime": "2018-01-18T01:34:02Z"
286+
"revision": "c0d28eeada35fc1c63b16865b438ee277ca179fb",
287+
"revisionTime": "2018-01-19T08:28:08Z"
288288
},
289289
{
290290
"checksumSHA1": "vsHDSvuHR3Fce800xGIsMWcEMHc=",
291291
"path": "github.com/denverdino/aliyungo/slb",
292-
"revision": "f6ec6f26ec42e39b07c75c738eb30c869d305ce5",
293-
"revisionTime": "2018-01-18T01:34:02Z"
292+
"revision": "c0d28eeada35fc1c63b16865b438ee277ca179fb",
293+
"revisionTime": "2018-01-19T08:28:08Z"
294294
},
295295
{
296296
"checksumSHA1": "ZSpVJldK4F8joh8pOryB5SaSn8s=",
297297
"path": "github.com/denverdino/aliyungo/util",
298-
"revision": "f6ec6f26ec42e39b07c75c738eb30c869d305ce5",
299-
"revisionTime": "2018-01-18T01:34:02Z"
298+
"revision": "c0d28eeada35fc1c63b16865b438ee277ca179fb",
299+
"revisionTime": "2018-01-19T08:28:08Z"
300300
},
301301
{
302302
"checksumSHA1": "BCv50o5pDkoSG3vYKOSai1Z8p3w=",

website/docs/r/container_cluster.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The following arguments are supported:
3434
* `name` - (Force new resource) The container cluster's name. It is the only in one Alicloud account.
3535
* `name_prefix` - (Force new resource) The container cluster name's prefix. It is conflict with `name`. If it is specified, terraform will using it to build the only cluster name.
3636
* `size` - The ECS node number of the container cluster. Its value choices are 1~20, and default to 1.
37-
* `cidr_block` - (Required, Force new resource) The CIDR block for the Container. Its valid value are `192.168.X.0/24` or `172.16.X.0/24` ~ `172.31.X.0/24`, and it can't be conflict with VSwitch's.
37+
* `cidr_block` - (Required, Force new resource) The CIDR block for the Container. Its valid value are `192.168.X.0/24` or `172.18.X.0/24` ~ `172.31.X.0/24`. And it cannot be equal to vswitch's cidr_block and sub cidr block.
3838
* `image_id` - (Force new resource) The image ID of ECS instance node used. Default to System automate allocated.
3939
* `instance_type` - (Required, Force new resource) The type of ECS instance node.
4040
* `password` - (Required, Force new resource) The password of ECS instance node.

0 commit comments

Comments
 (0)