Skip to content

Commit

Permalink
Configuration examples
Browse files Browse the repository at this point in the history
This is the examples originally submitted in hashicorp/terraform#11235.
  • Loading branch information
wangyuelucky authored and apparentlymart committed Jul 7, 2017
1 parent 7f05461 commit 6cd9982
Show file tree
Hide file tree
Showing 62 changed files with 1,507 additions and 0 deletions.
27 changes: 27 additions & 0 deletions examples/ecs-image/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
### ECS Example

The example gains image info and use it to launche ECS instance, disk, and attached the disk on ECS. the count parameter in variables.tf can let you gain specify image and use it to create specify number ECS instances.

### Get up and running

* Planning phase

terraform plan
var.availability_zones
Enter a value: {var.availability_zones} /*cn-beijing-b*/
var.datacenter
Enter a value: {datacenter}
....

* Apply phase

terraform apply
var.availability_zones
Enter a value: {var.availability_zones} /*cn-beijing-b*/
var.datacenter
Enter a value: {datacenter}
....

* Destroy

terraform destroy
55 changes: 55 additions & 0 deletions examples/ecs-image/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
data "alicloud_images" "ecs_image" {
most_recent = "${var.most_recent}"
owners = "${var.image_owners}"
name_regex = "${var.name_regex}"
}

resource "alicloud_security_group" "group" {
name = "${var.short_name}"
description = "New security group"
}


resource "alicloud_disk" "disk" {
availability_zone = "${var.availability_zones}"
category = "${var.disk_category}"
size = "${var.disk_size}"
count = "${var.count}"
}

resource "alicloud_instance" "instance" {
instance_name = "${var.short_name}-${var.role}-${format(var.count_format, count.index+1)}"
host_name = "${var.short_name}-${var.role}-${format(var.count_format, count.index+1)}"
image_id = "${data.alicloud_images.ecs_image.images.0.id}"
instance_type = "${var.ecs_type}"
count = "${var.count}"
availability_zone = "${var.availability_zones}"
security_groups = ["${alicloud_security_group.group.*.id}"]

internet_charge_type = "${var.internet_charge_type}"
internet_max_bandwidth_out = "${var.internet_max_bandwidth_out}"

io_optimized = "${var.io_optimized}"

password = "${var.ecs_password}"

allocate_public_ip = "${var.allocate_public_ip}"

instance_charge_type = "PostPaid"
system_disk_category = "cloud_efficiency"


tags {
role = "${var.role}"
dc = "${var.datacenter}"
}

}

resource "alicloud_disk_attachment" "instance-attachment" {
count = "${var.count}"
disk_id = "${element(alicloud_disk.disk.*.id, count.index)}"
instance_id = "${element(alicloud_instance.instance.*.id, count.index)}"
device_name = "${var.device_name}"
}

15 changes: 15 additions & 0 deletions examples/ecs-image/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
output "hostname_list" {
value = "${join(",", alicloud_instance.instance.*.instance_name)}"
}

output "ecs_ids" {
value = "${join(",", alicloud_instance.instance.*.id)}"
}

output "ecs_public_ip" {
value = "${join(",", alicloud_instance.instance.*.public_ip)}"
}

output "tags" {
value = "${jsonencode(alicloud_instance.instance.tags)}"
}
57 changes: 57 additions & 0 deletions examples/ecs-image/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
variable "count" {
default = "1"
}
variable "count_format" {
default = "%02d"
}
variable "most_recent" {
default = true
}

variable "image_owners" {
default = ""
}

variable "name_regex" {
default = "^centos_6\\w{1,5}[64].*"
}

variable "role" {
default = "work"
}
variable "datacenter" {
default = "beijing"
}
variable "short_name" {
default = "hi"
}
variable "ecs_type" {
default = "ecs.n1.small"
}
variable "ecs_password" {
default = "Test12345"
}
variable "availability_zones" {
default = "cn-beijing-b"
}
variable "allocate_public_ip" {
default = true
}
variable "internet_charge_type" {
default = "PayByTraffic"
}
variable "internet_max_bandwidth_out" {
default = 5
}
variable "io_optimized" {
default = "optimized"
}
variable "disk_category" {
default = "cloud_ssd"
}
variable "disk_size" {
default = "40"
}
variable "device_name" {
default = "/dev/xvdb"
}
18 changes: 18 additions & 0 deletions examples/ecs-slb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### ECS With SLB Example

The example launches ECS, disk, and attached the disk on ECS. It also creates an SLB, and addition the ECS to backendServer. The variables.tf can let you create specify parameter instances, such as image_id, ecs_type etc.

### Get up and running

* Planning phase

terraform plan

* Apply phase

terraform apply


* Destroy

terraform destroy
53 changes: 53 additions & 0 deletions examples/ecs-slb/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
resource "alicloud_security_group" "group" {
name = "${var.short_name}"
description = "New security group"
}

resource "alicloud_instance" "instance" {
instance_name = "${var.short_name}-${var.role}-${format(var.count_format, count.index+1)}"
host_name = "${var.short_name}-${var.role}-${format(var.count_format, count.index+1)}"
image_id = "${var.image_id}"
instance_type = "${var.ecs_type}"
count = "${var.count}"
availability_zone = "${var.availability_zones}"
security_groups = ["${alicloud_security_group.group.*.id}"]

internet_charge_type = "${var.internet_charge_type}"
internet_max_bandwidth_out = "${var.internet_max_bandwidth_out}"

io_optimized = "${var.io_optimized}"

password = "${var.ecs_password}"

allocate_public_ip = "${var.allocate_public_ip}"

instance_charge_type = "PostPaid"
system_disk_category = "cloud_efficiency"


tags {
role = "${var.role}"
dc = "${var.datacenter}"
}

}

resource "alicloud_slb" "instance" {
name = "${var.slb_name}"
internet_charge_type = "${var.slb_internet_charge_type}"
internet = "${var.internet}"

listener = [
{
"instance_port" = "2111"
"lb_port" = "21"
"lb_protocol" = "tcp"
"bandwidth" = "5"
}]
}


resource "alicloud_slb_attachment" "default" {
slb_id = "${alicloud_slb.instance.id}"
instances = ["${alicloud_instance.instance.*.id}"]
}
20 changes: 20 additions & 0 deletions examples/ecs-slb/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
output "slb_id" {
value = "${alicloud_slb.instance.id}"
}

output "slbname" {
value = "${alicloud_slb.instance.name}"
}

output "hostname_list" {
value = "${join(",", alicloud_instance.instance.*.instance_name)}"
}

output "ecs_ids" {
value = "${join(",", alicloud_instance.instance.*.id)}"
}

output "slb_backendserver" {
value = "${alicloud_slb_attachment.default.backend_servers}"
}

58 changes: 58 additions & 0 deletions examples/ecs-slb/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
variable "count" {
default = "1"
}
variable "count_format" {
default = "%02d"
}
variable "image_id" {
default = "ubuntu_140405_64_40G_cloudinit_20161115.vhd"
}

variable "role" {
default = "worder"
}
variable "datacenter" {
default = "beijing"
}
variable "short_name" {
default = "hi"
}
variable "ecs_type" {
default = "ecs.n1.small"
}
variable "ecs_password" {
default = "Test12345"
}
variable "availability_zones" {
default = "cn-beijing-b"
}
variable "ssh_username" {
default = "root"
}

variable "allocate_public_ip" {
default = true
}

variable "internet_charge_type" {
default = "PayByTraffic"
}

variable "slb_internet_charge_type" {
default = "paybytraffic"
}
variable "internet_max_bandwidth_out" {
default = 5
}

variable "io_optimized" {
default = "optimized"
}

variable "slb_name" {
default = "slb_worder"
}

variable "internet" {
default = true
}
20 changes: 20 additions & 0 deletions examples/ecs-special-sg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### ECS With special SLB and SecurityGroup Example

The example launches 6 ECS and create it on special SLB and securityGroup.
Also additional first and second instance to the SLB backend server.
The variables.tf can let you create specify parameter instances, such as image_id, ecs_type etc.

### Get up and running

* Planning phase

terraform plan

* Apply phase

terraform apply


* Destroy

terraform destroy
39 changes: 39 additions & 0 deletions examples/ecs-special-sg/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
provider "alicloud" {
alias = "bj"
region = "cn-beijing"
}

resource "alicloud_instance" "instance" {
provider = "alicloud.bj"
instance_name = "website-${format(var.count_format, count.index+1)}"
host_name = "website-${format(var.count_format, count.index+1)}"
image_id = "centos7u2_64_40G_cloudinit_20160728.raw"
instance_type = "ecs.s2.large"
count = "6"
availability_zone = "cn-beijing-b"
security_groups = "${var.security_groups}"

internet_charge_type = "PayByBandwidth"

io_optimized = "none"

password = "${var.ecs_password}"

allocate_public_ip = "false"

instance_charge_type = "PostPaid"
system_disk_category = "cloud"


tags {
env = "prod"
product = "website"
dc = "beijing"
}

}

resource "alicloud_slb_attachment" "foo" {
slb_id = "${var.slb_id}"
instances = ["${alicloud_instance.instance.0.id}", "${alicloud_instance.instance.1.id}"]
}
7 changes: 7 additions & 0 deletions examples/ecs-special-sg/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "hostname_list" {
value = "${join(",", alicloud_instance.instance.*.instance_name)}"
}

output "ecs_ids" {
value = "${join(",", alicloud_instance.instance.*.id)}"
}
Loading

0 comments on commit 6cd9982

Please sign in to comment.