Skip to content

Commit f3953fe

Browse files
committed
update instance module
1 parent 88e8e80 commit f3953fe

File tree

4 files changed

+63
-76
lines changed

4 files changed

+63
-76
lines changed

README.md

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,30 @@ These types of resources are supported:
1515
```hcl
1616
# Create uhost instance attached with eip and cloud disk
1717
module "uhost_instance" {
18-
source = "terraform-ucloud-modules/uhost-instance/ucloud"
19-
version = "1.0.0"
20-
21-
# uhost instance
22-
instance_count = 2
23-
instance_name = "example-complete-instance"
24-
password = "ucloud_2019"
25-
image_name_regex = "^CentOS 7.[1-2] 64"
26-
image_type = "base"
27-
instance_type = "n-standard-2"
28-
boot_disk_type = "cloud_ssd"
29-
tag = "example-complete"
30-
31-
# eip
32-
eip_count_per_instance = 1
33-
eip_internet_type = "bgp"
34-
eip_charge_mode = "bandwidth"
35-
eip_name = "example-complete-eip"
36-
37-
# disk
38-
disk_count_per_instance = 1
39-
disk_size = 30
40-
disk_type = "ssd_data_disk"
41-
disk_name = "example-complete-disk"
18+
source = "terraform-ucloud-modules/uhost-instance/ucloud"
19+
version = "1.0.0"
20+
21+
# uhost instance
22+
instance_count = 2
23+
availability_zone = "cn-bj2-05"
24+
image_id = "uimage-ohveag"
25+
instance_type = "n-standard-2"
26+
password = "ucloud_2019"
27+
instance_name = "example-complete-instance"
28+
boot_disk_type = "cloud_ssd"
29+
tag = "example-complete"
30+
31+
# eip
32+
eip_count_per_instance = 1
33+
eip_internet_type = "bgp"
34+
eip_charge_mode = "bandwidth"
35+
eip_name = "example-complete-eip"
36+
37+
# disk
38+
disk_count_per_instance = 1
39+
disk_size = 30
40+
disk_type = "ssd_data_disk"
41+
disk_name = "example-complete-disk"
4242
}
4343
```
4444

@@ -52,21 +52,20 @@ module "uhost_instance" {
5252
| Name | Description | Type | Default | Required |
5353
|------|-------------|:----:|:-----:|:-----:|
5454
| password | The password of instance | string | - | yes |
55-
| availability\_zone | Available zone where instance and other resources are located. If not set, the first availability zone of current region will be used. | string | `""` | no |
55+
| availability\_zone | Available zone where instance and other resources are located. | string | - | yes |
56+
| image\_id | ID of image to use for instances. | string | - | yes |
57+
| instance\_type | The type of instance to launch. | string | - | yes |
5658
| count\_format | Number format to use for output. | string | `"%02d"` | no |
57-
| image\_name\_regex | The name regex of image to use for fetch specified image when image_id isn't set. | string | `"^CentOS 7.4 64"` | no |
58-
| image\_type | The type of image to filter image when image_id isn't set. Possible values: base, business, custom. | string | `"base"` | no |
59-
| image\_id | ID of image to use for instances. | string | `""` | no |
6059
| instance\_count | Number of instances to launch. | string | `"1"` | no |
61-
| instance\_type | The type of instance to launch. | string | `"n-basic-1"` | no |
6260
| instance\_name | Name to be used on instances as prefix. | string | `"TF-UHost-Instance"` | no |
6361
| charge\_type | The charge type of instance and other related resources. Possible values: year, month, dynamic. | string | `"month"` | no |
6462
| duration | The duration of purchase of the instance and other related resources | string | `"1"` | no |
6563
| boot\_disk\_type | The type of system disk. Possible values: local_normal, local_ssd, cloud_normal, cloud_ssd. | string | `"local_normal"` | no |
6664
| local\_disk\_size | The size of local data disk | string | `"0"` | no |
6765
| local\_disk\_type | The type of local data disk. Possible values: local_normal, local_ssd. | string | `"local_normal"` | no |
68-
| tag | The tag of instance and other related resources | string | `"Default"` | no |
66+
| tag | The tag of instance and other related resources | string | `""` | no |
6967
| security\_group | ID of security group to use for instances. If not set, the default security group will be used. | string | `""` | no |
68+
| isolation\_group | ID of isolation group to use for instances. | string | `""` | no |
7069
| vpc\_id | The VPC linked to the instance | string | `""` | no |
7170
| subnet\_id | The Subnet linked to the instance | string | `""` | no |
7271
| disk\_count\_per\_instance | Number of disks attach to per instance. | string | `"0"` | no |

examples/complete/main.tf

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,27 @@ data "ucloud_security_groups" "default" {
77
type = "recommend_web"
88
}
99

10+
data "ucloud_images" "default" {
11+
availability_zone = "cn-bj2-05"
12+
name_regex = "^CentOS 7.[1-2] 64"
13+
image_type = "base"
14+
}
15+
1016
# Create uhost instance attached with eip and cloud disk
1117
module "uhost_instance" {
1218
source = "../../"
1319

14-
# uhost instance
15-
instance_count = 2
16-
instance_name = "example-complete-instance"
17-
password = "ucloud_2019"
18-
image_name_regex = "^CentOS 7.[1-2] 64"
19-
image_type = "base"
20-
instance_type = "n-standard-2"
21-
boot_disk_type = "cloud_ssd"
22-
tag = "example-complete"
20+
# common config
21+
availability_zone = "cn-bj2-05"
22+
tag = "example-complete"
2323

24-
# the default Web Security Group that UCloud recommend to users
24+
# uhost instance
25+
instance_count = 2
26+
image_id = data.ucloud_images.default.images[0].id
27+
instance_type = "n-standard-2"
28+
password = "ucloud_2019"
29+
instance_name = "example-complete-instance"
30+
boot_disk_type = "cloud_ssd"
2531
security_group = data.ucloud_security_groups.default.security_groups[0].id
2632

2733
# eip

main.tf

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
1-
# Query availability zone
2-
data "ucloud_zones" "default" {
3-
}
4-
5-
# Query image
6-
data "ucloud_images" "default" {
7-
availability_zone = data.ucloud_zones.default.zones[0].id
8-
name_regex = var.image_name_regex
9-
image_type = var.image_type
10-
}
11-
121
# Create uhost instance
132
resource "ucloud_instance" "instances" {
14-
image_id = var.image_id == "" ? data.ucloud_images.default.images[0].id : var.image_id
15-
availability_zone = var.availability_zone == "" ? data.ucloud_zones.default.zones[0].id : var.availability_zone
3+
image_id = var.image_id
4+
availability_zone = var.availability_zone
165
instance_type = var.instance_type
176
root_password = var.password
187
name = var.instance_count < 2 ? var.instance_name : format(
198
"%s-%s",
209
var.instance_name,
2110
format(var.count_format, count.index + 1),
2211
)
23-
charge_type = var.charge_type
24-
duration = var.duration
25-
tag = var.tag
26-
security_group = var.security_group
27-
vpc_id = var.vpc_id
28-
subnet_id = var.subnet_id
12+
charge_type = var.charge_type
13+
duration = var.duration
14+
tag = var.tag
15+
security_group = var.security_group
16+
vpc_id = var.vpc_id
17+
subnet_id = var.subnet_id
18+
isolation_group = var.isolation_group
2919

3020
data_disk_size = var.local_disk_size
3121
data_disk_type = var.local_disk_type
@@ -61,7 +51,7 @@ resource "ucloud_eip_association" "default" {
6151

6252
# Create cloud disk
6353
resource "ucloud_disk" "disks" {
64-
availability_zone = var.availability_zone == "" ? data.ucloud_zones.default.zones[0].id : var.availability_zone
54+
availability_zone = var.availability_zone
6555
name = var.disk_count_per_instance < 2 ? var.disk_name : format(
6656
"%s-%s",
6757
var.disk_name,
@@ -77,7 +67,7 @@ resource "ucloud_disk" "disks" {
7767

7868
# Attach disk to instance
7969
resource "ucloud_disk_attachment" "default" {
80-
availability_zone = var.availability_zone == "" ? data.ucloud_zones.default.zones[0].id : var.availability_zone
70+
availability_zone = var.availability_zone
8171
instance_id = ucloud_instance.instances[count.index % var.instance_count].id
8272
disk_id = ucloud_disk.disks[count.index].id
8373
count = var.disk_count_per_instance > 0 && var.instance_count > 0 ? var.disk_count_per_instance * var.instance_count : 0

variables.tf

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
variable "availability_zone" {
2-
description = "Available zone where instance and other resources are located. If not set, the first availability zone of current region will be used."
3-
default = ""
2+
description = "Available zone where instance and other resources are located."
43
}
54

65
variable "count_format" {
@@ -9,19 +8,8 @@ variable "count_format" {
98
}
109

1110
# image
12-
variable "image_name_regex" {
13-
description = "The name regex of image to use for fetch specified image when image_id isn't set"
14-
default = "^CentOS 7.4 64"
15-
}
16-
17-
variable "image_type" {
18-
description = "The type of image to filter image when image_id isn't set."
19-
default = "base"
20-
}
21-
2211
variable "image_id" {
2312
description = "ID of image to use for instances."
24-
default = ""
2513
}
2614

2715
# uhost instance
@@ -32,7 +20,6 @@ variable "instance_count" {
3220

3321
variable "instance_type" {
3422
description = "The type of instance to launch."
35-
default = "n-basic-1"
3623
}
3724

3825
variable "password" {
@@ -71,14 +58,19 @@ variable "local_disk_type" {
7158

7259
variable "tag" {
7360
description = "The tag of instance and other related resources"
74-
default = "Default"
61+
default = ""
7562
}
7663

7764
variable "security_group" {
7865
description = "ID of security group to use for instances. If not set, the default security group will be used."
7966
default = ""
8067
}
8168

69+
variable "isolation_group" {
70+
description = "The ID of isolation group to use for instances."
71+
default = ""
72+
}
73+
8274
variable "vpc_id" {
8375
description = "The VPC linked to the instance"
8476
default = ""

0 commit comments

Comments
 (0)