This example will show you how to launch an Alibaba Cloud (阿里云) ECS Instance using Ubuntu and packed with Docker and Docker Compose. Very simple but can be used as good start for other project.
For this, you just need to create a folder with this 2 files in it:
main.tf
provider "alicloud" {}
data "template_file" "user_data" {
template = "${file("user-data.sh")}"
}
data "alicloud_images" "default" {
name_regex = "^ubuntu_16.*_64"
}
data "alicloud_instance_types" "default" {
instance_type_family = "ecs.xn4"
cpu_core_count = 1
memory_size = 1
}
data "alicloud_vpcs" "default" {
is_default = true
}
data "alicloud_vswitches" "default" {
is_default = true
}
data "alicloud_security_groups" "default" {
vpc_id = "${data.alicloud_vpcs.default.id}"
}
resource "alicloud_instance" "ecs" {
instance_name = "ubuntu-docker"
image_id = "${data.alicloud_images.default.images.0.image_id}"
instance_type = "${data.alicloud_instance_types.default.instance_types.0.id}"
vswitch_id = "${data.alicloud_vswitches.default.vswitches.0.id}"
security_groups = [
"${data.alicloud_security_groups.default.groups.0.id}"
]
internet_max_bandwidth_out = 100
password = "Test1234!"
user_data = "${data.template_file.user_data.template}"
}
user-data.sh
#!/usr/bin/env bash
apt-get update && apt-get install -y apt-transport-https ca-certificates curl git-core software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get update && apt-get install -y docker-ce docker-compose
curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-`uname -s`-`uname -m` -o /usr/bin/docker-compose
ENJOY!