Launch an Alibaba Cloud ECS with Docker using Terraform

Posted on 31 August 2018 by Alberto Roura.
alibaba cloudaliyundevopsecsterraform

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!



Republished from: Launch an Alibaba Cloud ECS with Docker using Terraform.

πŸš€ Ready to Transform Your Business?

Get expert guidance tailored to your China market ambitions. Our team of cloud and DevOps specialists has helped 100+ companies navigate the complexities of Chinese cloud infrastructure.

From AWS China foundations to ICP compliance, we handle the technical details so you can focus on growing your business.

πŸ“… Schedule Your Free Strategy Session

We'll assess your current setup and show you exactly how to optimize for the China market.

βœ“ No sales pitch β€’ βœ“ Actionable insights β€’ βœ“ Custom recommendations
100+
Companies Served
10+
Years Experience
99%
Client Satisfaction

Not ready for a call? Send us an email instead.