|
| 1 | +Alicloud ECS Instance Terraform Module In VPC |
| 2 | +terraform-alicloud-ecs-instance |
| 3 | +===================================================================== |
| 4 | + |
| 5 | +A terraform module to provide ECS instances in Alicloud VPC. |
| 6 | + |
| 7 | +- It assumes you have one VPC and VSwitch and you want to put the new instances to the VPC. If not, you can launch a new one by module [terraform-alicloud-vpc](https://github.com/alibaba/terraform-alicloud-vpc) |
| 8 | +- It assumes you have several security groups in the VPC and you want to join the new instances into them. If not, you can launch one or more groups by module [terraform-alicloud-security-group](https://github.com/alibaba/terraform-alicloud-security-group) |
| 9 | +- If you have no idea some parametes, such as instance type, availability zone and image id, |
| 10 | + the module will provide default values according to some input parameters, such as `image_name_regex`, `cpu_core_count`, `memory_size` and so on. |
| 11 | + |
| 12 | + |
| 13 | +Module Input Variables |
| 14 | +---------------------- |
| 15 | + |
| 16 | +The module aim to create one or more instances and disks in the VPC. Its input variables contains VSwitch, Security Group, ECS Disks and ECS Instances. |
| 17 | + |
| 18 | +#### Common Input vairables |
| 19 | + |
| 20 | +- `alicloud_access_key` - The Alicloud Access Key ID to launch resources |
| 21 | +- `alicloud_secret_key` - The Alicloud Access Secret Key to launch resources |
| 22 | +- `region` - The region to launch resources |
| 23 | +- `availability_zone` - The availability zone ID to launch ECS Instances and ECS Disks - default to a zone ID retrieved by zones' data source |
| 24 | +- `number_format` - The number format used to mark multiple resources - default to "%02d" |
| 25 | + |
| 26 | +`Note`: If you specify the `vswitch_id`, the `availability_zone` would be ignore when launching ECS instances. |
| 27 | +#### Instance Types Data Source Input Variables |
| 28 | + |
| 29 | +- `image_name_regex` - The ECS image's name regex used to fetch latest specified system images - default to "^ubuntu_14.*_64" and it would return a latest 64bit Ubuntu Image |
| 30 | + |
| 31 | +### Instance typs Variables |
| 32 | + |
| 33 | +- `cpu_core_count` - CPU core count used to fetch instance types - default to 1 |
| 34 | +- `memory_size` - Memory size used to fetch instance types - default to 2 |
| 35 | + |
| 36 | +#### VSwitch Input Variables |
| 37 | + |
| 38 | +- `vswitch_id` - VSwitch ID to launch new ECS instances |
| 39 | + |
| 40 | +#### Security Groups Input Variables |
| 41 | + |
| 42 | +- `group_ids` - List of Security Group IDs to launch new ECS instances |
| 43 | + |
| 44 | +#### ECS Disk Input Variables |
| 45 | + |
| 46 | +- `number_of_disks` - The number disks you want to launch - default to 0 |
| 47 | +- `disk_name` - ECS disk name to mark data disk(s) - default to "TF_ECS_Disk" |
| 48 | +- `disk_category` - ECS disk category to launch data disk(s) - choices to ["cloud_ssd", "cloud_efficiency"] - default to "cloud_efficiency" |
| 49 | +- `disk_size` - ECS disk size to launch data disk(s) - default to 40 |
| 50 | +- `disk_tags` - A map for setting ECS disk tags - default to |
| 51 | + |
| 52 | + disk_tags = { |
| 53 | + created_by = "Terraform" |
| 54 | + created_from = "module-tf-alicloud-ecs-instance" |
| 55 | + } |
| 56 | + |
| 57 | +#### ECS Instance Input Variables |
| 58 | + |
| 59 | +- `number_of_instances` - The number of instances you want to launch - default to 1 |
| 60 | +- `image_id` - The image id to use - default to an Ubuntu-64bit image ID retrieved by images' data source |
| 61 | +- `instance_type` - The ECS instance type, e.g. ecs.n4.small, - default to a 1Core 2GB instance type retrieved by instance_types' data source |
| 62 | +- `instance_name` - ECS instance name to mark instance(s) - default to "TF_ECS_Instance" |
| 63 | +- `host_name` - ECS instance host name to configure instance(s) - default to "TF_ECS_Host_Name" |
| 64 | +- `system_category` - ECS disk category to launch system disk - choices to ["cloud_ssd", "cloud_efficiency"] - default to "cloud_efficiency" |
| 65 | +- `system_size` - ECS disk size to launch system disk - default to 40 |
| 66 | +- `allocate_public_ip` - Whether to allocate public for instance(s) - default to true |
| 67 | +- `internet_charge_type` - The internet charge type for setting instance network - choices["PayByTraffic", "PayByBandwidth"] - default to "PayByTraffic" |
| 68 | +- `internet_max_bandwidth_out` - The max out bandwidth for setting instance network - default to 10 |
| 69 | +- `instance_charge_type` - The instance charge type - choices to ["PrePaid", "PostPaid"] - default to "PostPaid" |
| 70 | +- `period` - The instance charge period when instance charge type is 'PrePaid' - default to 1 |
| 71 | +- `key_name` - The instance key pair name for SSH keys |
| 72 | +- `password` - The instance password |
| 73 | +- `instance_tags` - A map for setting ECS Instance tags - default to |
| 74 | + |
| 75 | + instance_tags = { |
| 76 | + created_by = "Terraform" |
| 77 | + created_from = "module-tf-alicloud-ecs-instance" |
| 78 | + } |
| 79 | + |
| 80 | + |
| 81 | +Usage |
| 82 | +----- |
| 83 | +You can use this in your terraform template with the following steps. |
| 84 | + |
| 85 | +1. Adding a module resource to your template, e.g. main.tf |
| 86 | + |
| 87 | + module "tf-instances" { |
| 88 | + source = "github.com/terraform-community-modules/terraform-alicloud-ecs-instance" |
| 89 | + |
| 90 | + alicloud_access_key = "${var.alicloud_access_key}" |
| 91 | + alicloud_secret_key = "${var.alicloud_secret_key}" |
| 92 | + region = "${var.region}" |
| 93 | + |
| 94 | + vswitch_id = "${var.vswitch_id}" |
| 95 | + group_ids = "${var.group_ids}" |
| 96 | + |
| 97 | + disk_category = "cloud_ssd" |
| 98 | + disk_name = "my_module_disk" |
| 99 | + disk_size = "50" |
| 100 | + number_of_disks = 2 |
| 101 | + |
| 102 | + instance_name = "my_module_instances" |
| 103 | + host_name = "my_host" |
| 104 | + internet_charge_type = "PayByTraffic" |
| 105 | + number_of_instances = "2" |
| 106 | + |
| 107 | + key_name = "${var.key_name}" |
| 108 | + |
| 109 | + } |
| 110 | + |
| 111 | +2. Setting values for the following variables, either through terraform.tfvars or environment variables or -var arguments on the CLI |
| 112 | + |
| 113 | +- alicloud_access_key |
| 114 | +- alicloud_secret_key |
| 115 | +- region |
| 116 | +- key_name |
| 117 | +- vswitch_id |
| 118 | +- group_ids |
| 119 | + |
| 120 | +Module Output Variables |
| 121 | +----------------------- |
| 122 | + |
| 123 | +- instance_ids - List of new instance ids |
| 124 | +- disk_ids - List of new data disk ids |
| 125 | + |
| 126 | +Authors |
| 127 | +------- |
| 128 | +Created and maintained by He Guimin( @xiaozhu36, [email protected]) |
0 commit comments