examples: Remove AliCloud and AWS examples
The examples for these providers have moved into the providers' own repositories, so this is just cleaning up the old copies in the main repo to avoid any confusion caused by the duplication. The examples readme has links to these provider-specific examples so that people looking for them in the old location can still find them.
This commit is contained in:
parent
0bca383b6b
commit
9be103b62d
|
@ -8,9 +8,17 @@ To run any example, just run `terraform apply` within that directory
|
|||
if you have Terraform checked out. Or, you can run it directly from git:
|
||||
|
||||
```
|
||||
$ terraform init github.com/hashicorp/terraform/examples/aws-two-tier
|
||||
$ terraform init github.com/hashicorp/terraform/examples/cross-provider
|
||||
...
|
||||
|
||||
$ terraform apply
|
||||
...
|
||||
```
|
||||
|
||||
## Provider-specific Examples
|
||||
|
||||
Terraform providers each live in their own repository. Some of these
|
||||
repositories contain documentation specific to their provider:
|
||||
|
||||
* [AliCloud Examples](https://github.com/terraform-providers/terraform-provider-alicloud/tree/master/examples)
|
||||
* [Amazon Web Services Examples](https://github.com/terraform-providers/terraform-provider-aws/tree/master/examples)
|
||||
|
|
|
@ -1,119 +0,0 @@
|
|||
|
||||
provider "alicloud" {
|
||||
region = "${var.region}"
|
||||
}
|
||||
|
||||
data "alicloud_instance_types" "1c2g" {
|
||||
cpu_core_count = 2
|
||||
memory_size = 4
|
||||
instance_type_family = "ecs.n1"
|
||||
}
|
||||
|
||||
data "alicloud_images" "centos" {
|
||||
most_recent = true
|
||||
name_regex = "^centos_7\\w.*"
|
||||
}
|
||||
|
||||
data "alicloud_zones" "default" {
|
||||
"available_instance_type"= "${data.alicloud_instance_types.1c2g.instance_types.0.id}"
|
||||
"available_disk_category"= "${var.disk_category}"
|
||||
}
|
||||
|
||||
resource "alicloud_vpc" "default" {
|
||||
cidr_block = "${var.vpc_cidr}"
|
||||
}
|
||||
|
||||
resource "alicloud_vswitch" "vsw" {
|
||||
vpc_id = "${alicloud_vpc.default.id}"
|
||||
cidr_block = "${var.vswitch_cidr}"
|
||||
availability_zone = "${data.alicloud_zones.default.zones.0.id}"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group" "sg" {
|
||||
name = "sg"
|
||||
vpc_id = "${alicloud_vpc.default.id}"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group_rule" "in-all" {
|
||||
type = "ingress"
|
||||
ip_protocol = "all"
|
||||
nic_type = "intranet"
|
||||
policy = "accept"
|
||||
port_range = "-1/-1"
|
||||
priority = 1
|
||||
security_group_id = "${alicloud_security_group.sg.id}"
|
||||
cidr_ip = "0.0.0.0/0"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group_rule" "en-all" {
|
||||
type = "egress"
|
||||
ip_protocol = "all"
|
||||
nic_type = "intranet"
|
||||
policy = "accept"
|
||||
port_range = "-1/-1"
|
||||
priority = 1
|
||||
security_group_id = "${alicloud_security_group.sg.id}"
|
||||
cidr_ip = "0.0.0.0/0"
|
||||
}
|
||||
|
||||
resource "alicloud_instance" "webserver" {
|
||||
security_groups = ["${alicloud_security_group.sg.id}"]
|
||||
vswitch_id = "${alicloud_vswitch.vsw.id}"
|
||||
|
||||
# series II
|
||||
instance_charge_type = "PostPaid"
|
||||
instance_type = "${data.alicloud_instance_types.1c2g.instance_types.0.id}"
|
||||
internet_max_bandwidth_out = 0
|
||||
io_optimized = "${var.io_optimized}"
|
||||
|
||||
system_disk_category = "${var.disk_category}"
|
||||
image_id = "${data.alicloud_images.centos.images.0.id}"
|
||||
|
||||
instance_name = "tf_lnmp"
|
||||
password= "${var.ecs_password}"
|
||||
|
||||
user_data = "${data.template_file.shell.rendered}"
|
||||
}
|
||||
|
||||
data "template_file" "shell" {
|
||||
template = "${file("userdata.sh")}"
|
||||
|
||||
vars {
|
||||
db_name = "${var.db_name}"
|
||||
db_user = "${var.db_user}"
|
||||
db_pwd = "${var.db_password}"
|
||||
db_root_pwd = "${var.db_root_password}"
|
||||
}
|
||||
}
|
||||
|
||||
resource "alicloud_nat_gateway" "default" {
|
||||
vpc_id = "${alicloud_vpc.default.id}"
|
||||
spec = "Small"
|
||||
bandwidth_packages = [{
|
||||
ip_count = 2
|
||||
bandwidth = 10
|
||||
zone = "${data.alicloud_zones.default.zones.0.id}"
|
||||
}]
|
||||
depends_on = [
|
||||
"alicloud_vswitch.vsw"]
|
||||
}
|
||||
|
||||
resource "alicloud_forward_entry" "dnat"{
|
||||
forward_table_id = "${alicloud_nat_gateway.default.forward_table_ids}"
|
||||
external_ip = "${element(split(",", alicloud_nat_gateway.default.bandwidth_packages.0.public_ip_addresses),1)}"
|
||||
external_port = "any"
|
||||
ip_protocol = "any"
|
||||
internal_ip = "${alicloud_instance.webserver.private_ip}"
|
||||
internal_port = "any"
|
||||
}
|
||||
|
||||
resource "alicloud_snat_entry" "snat"{
|
||||
snat_table_id = "${alicloud_nat_gateway.default.snat_table_ids}"
|
||||
source_vswitch_id = "${alicloud_vswitch.vsw.id}"
|
||||
snat_ip = "${element(split(",", alicloud_nat_gateway.default.bandwidth_packages.0.public_ip_addresses),0)}"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
output "nginx_url" {
|
||||
value = "${element(split(",", alicloud_nat_gateway.default.bandwidth_packages.0.public_ip_addresses),1)}:80/test.php"
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
#!/bin/bash
|
||||
NginxUrl=http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
|
||||
dbname=${db_name}
|
||||
dbuser=${db_user}
|
||||
dbpassword=${db_pwd}
|
||||
dbrootpassword=${db_root_pwd}
|
||||
export HOME=/root
|
||||
export HOSTNAME=`hostname`
|
||||
systemctl stop firewalld.service
|
||||
systemctl disable firewalld.service
|
||||
sed -i 's/^SELINUX=/# SELINUX=/' /etc/selinux/config
|
||||
sed -i '/# SELINUX=/a SELINUX=disabled' /etc/selinux/config
|
||||
setenforce 0
|
||||
yum install yum-priorities -y
|
||||
yum -y install aria2
|
||||
aria2c $NginxUrl
|
||||
rpm -ivh nginx-*.rpm
|
||||
yum -y install nginx
|
||||
systemctl start nginx.service
|
||||
systemctl enable nginx.service
|
||||
yum -y install php-fpm
|
||||
systemctl start php-fpm.service
|
||||
systemctl enable php-fpm.service
|
||||
sed -i '/FastCGI/,/htaccess/s/ #/ /' /etc/nginx/conf.d/default.conf
|
||||
sed -i '/FastCGI/s/^ / #/' /etc/nginx/conf.d/default.conf
|
||||
sed -i '/htaccess/s/^ / #/' /etc/nginx/conf.d/default.conf
|
||||
sed -i '/SCRIPT_FILENAME/s/\/scripts/\/usr\/share\/nginx\/html\//' /etc/nginx/conf.d/default.conf
|
||||
yum -y install mariadb mariadb-server
|
||||
systemctl start mariadb.service
|
||||
systemctl enable mariadb.service
|
||||
yum -y install php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash php-mcrypt
|
||||
MDSRING=`find / -name mbstring.so`
|
||||
echo extension=$MDSRING >> /etc/php.ini
|
||||
systemctl restart mariadb.service
|
||||
mysqladmin -u root password "$dbrootpassword"
|
||||
$(mysql $dbname -u root --password="$dbrootpassword" >/dev/null 2>&1 </dev/null); (( $? != 0 ))
|
||||
echo CREATE DATABASE $dbname \; > /tmp/setup.mysql
|
||||
echo GRANT ALL ON $dbname.* TO "$dbuser"@"localhost" IDENTIFIED BY "'$dbpassword'" \; >> /tmp/setup.mysql
|
||||
mysql -u root --password="$dbrootpassword" < /tmp/setup.mysql
|
||||
$(mysql $dbname -u root --password="$dbrootpassword" >/dev/null 2>&1 </dev/null); (( $? != 0 ))
|
||||
cd /root
|
||||
systemctl restart php-fpm.service
|
||||
systemctl restart nginx.service
|
||||
echo \<?php > /usr/share/nginx/html/test.php
|
||||
echo \$conn=mysql_connect\("'127.0.0.1'", "'$dbuser'", "'$dbpassword'"\)\; >> /usr/share/nginx/html/test.php
|
||||
echo if \(\$conn\){ >> /usr/share/nginx/html/test.php
|
||||
echo echo \"LNMP platform connect to mysql is successful\!\"\; >> /usr/share/nginx/html/test.php
|
||||
echo }else{ >> /usr/share/nginx/html/test.php
|
||||
echo echo \"LNMP platform connect to mysql is failed\!\"\; >> /usr/share/nginx/html/test.php
|
||||
echo } >> /usr/share/nginx/html/test.php
|
||||
echo phpinfo\(\)\; >> /usr/share/nginx/html/test.php
|
||||
echo \?\> >> /usr/share/nginx/html/test.php
|
|
@ -1,30 +0,0 @@
|
|||
variable "region" {
|
||||
default = "cn-beijing"
|
||||
}
|
||||
variable "vpc_cidr" {
|
||||
default = "10.1.0.0/21"
|
||||
}
|
||||
variable "vswitch_cidr" {
|
||||
default = "10.1.1.0/24"
|
||||
}
|
||||
variable "io_optimized" {
|
||||
default = "optimized"
|
||||
}
|
||||
variable "ecs_password" {
|
||||
default = "Test1234567*"
|
||||
}
|
||||
variable "disk_category" {
|
||||
default = "cloud_efficiency"
|
||||
}
|
||||
variable "db_name" {
|
||||
default = "lnmp"
|
||||
}
|
||||
variable "db_user" {
|
||||
default = "alier"
|
||||
}
|
||||
variable "db_password" {
|
||||
default = "123456"
|
||||
}
|
||||
variable "db_root_password" {
|
||||
default = "123456"
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
### 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
|
|
@ -1,88 +0,0 @@
|
|||
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_security_group_rule" "http-in" {
|
||||
type = "ingress"
|
||||
ip_protocol = "tcp"
|
||||
nic_type = "internet"
|
||||
policy = "accept"
|
||||
port_range = "80/80"
|
||||
priority = 1
|
||||
security_group_id = "${alicloud_security_group.group.id}"
|
||||
cidr_ip = "0.0.0.0/0"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group_rule" "https-in" {
|
||||
type = "ingress"
|
||||
ip_protocol = "tcp"
|
||||
nic_type = "internet"
|
||||
policy = "accept"
|
||||
port_range = "443/443"
|
||||
priority = 1
|
||||
security_group_id = "${alicloud_security_group.group.id}"
|
||||
cidr_ip = "0.0.0.0/0"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group_rule" "ssh-in" {
|
||||
type = "ingress"
|
||||
ip_protocol = "tcp"
|
||||
nic_type = "internet"
|
||||
policy = "accept"
|
||||
port_range = "22/22"
|
||||
priority = 1
|
||||
security_group_id = "${alicloud_security_group.group.id}"
|
||||
cidr_ip = "0.0.0.0/0"
|
||||
}
|
||||
|
||||
|
||||
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}"
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
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)}"
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
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"
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
### Configure NAT instance Example
|
||||
|
||||
In the Virtual Private Cloud(VPC) environment, to enable multiple back-end intranet hosts to provide services externally with a limited number of EIPs, map the ports on the EIP-bound host to the back-end intranet hosts.
|
||||
|
||||
### Get up and running
|
||||
|
||||
* Planning phase
|
||||
|
||||
terraform plan
|
||||
|
||||
* Apply phase
|
||||
|
||||
terraform apply
|
||||
|
||||
Get the outputs:
|
||||
+ nat_instance_eip_address = 123.56.19.238
|
||||
+ nat_instance_private_ip = 10.1.1.57
|
||||
+ worker_instance_private_ip = 10.1.1.56
|
||||
|
||||
* Apply phase
|
||||
|
||||
+ login the vm: ssh root@123.56.19.238|Test123456
|
||||
+ Run the "iptables -t nat -nvL" command to check the result
|
||||
|
||||
| prot | in | source | destination | |
|
||||
| ---- | -- | ----------- | -------------- | ------------------------ |
|
||||
| tcp | * | 0.0.0.0/0 | 10.1.1.57 | tcp dpt:80 to:10.1.1.56
|
||||
| all | * | 10.1.1.0/24 | 0.0.0.0/0 | to:10.1.1.57
|
||||
|
||||
|
||||
* Destroy
|
||||
|
||||
terraform destroy
|
|
@ -1,98 +0,0 @@
|
|||
resource "alicloud_vpc" "main" {
|
||||
cidr_block = "${var.vpc_cidr}"
|
||||
}
|
||||
|
||||
resource "alicloud_vswitch" "main" {
|
||||
vpc_id = "${alicloud_vpc.main.id}"
|
||||
cidr_block = "${var.vswitch_cidr}"
|
||||
availability_zone = "${var.zone}"
|
||||
depends_on = ["alicloud_vpc.main"]
|
||||
}
|
||||
|
||||
resource "alicloud_route_entry" "entry" {
|
||||
router_id = "${alicloud_vpc.main.router_id}"
|
||||
route_table_id = "${alicloud_vpc.main.router_table_id}"
|
||||
destination_cidrblock = "0.0.0.0/0"
|
||||
nexthop_type = "Instance"
|
||||
nexthop_id = "${alicloud_instance.nat.id}"
|
||||
}
|
||||
|
||||
resource "alicloud_instance" "nat" {
|
||||
image_id = "${var.image}"
|
||||
instance_type = "${var.instance_nat_type}"
|
||||
availability_zone = "${var.zone}"
|
||||
security_groups = ["${alicloud_security_group.group.id}"]
|
||||
vswitch_id = "${alicloud_vswitch.main.id}"
|
||||
instance_name = "nat"
|
||||
io_optimized = "optimized"
|
||||
system_disk_category = "cloud_efficiency"
|
||||
password= "${var.instance_pwd}"
|
||||
|
||||
depends_on = ["alicloud_instance.worker"]
|
||||
user_data = "${data.template_file.shell.rendered}"
|
||||
|
||||
tags {
|
||||
Name = "ecs-nat"
|
||||
}
|
||||
}
|
||||
|
||||
data "template_file" "shell" {
|
||||
template = "${file("userdata.sh")}"
|
||||
|
||||
vars {
|
||||
worker_private_ip = "${alicloud_instance.worker.private_ip}"
|
||||
vswitch_cidr = "${var.vswitch_cidr}"
|
||||
}
|
||||
}
|
||||
|
||||
resource "alicloud_instance" "worker" {
|
||||
image_id = "${var.image}"
|
||||
instance_type = "${var.instance_worker_type}"
|
||||
availability_zone = "${var.zone}"
|
||||
security_groups = ["${alicloud_security_group.group.id}"]
|
||||
vswitch_id = "${alicloud_vswitch.main.id}"
|
||||
instance_name = "worker"
|
||||
io_optimized = "optimized"
|
||||
system_disk_category = "cloud_efficiency"
|
||||
password= "${var.instance_pwd}"
|
||||
|
||||
tags {
|
||||
Name = "ecs-worker"
|
||||
}
|
||||
}
|
||||
|
||||
resource "alicloud_eip" "eip" {
|
||||
}
|
||||
|
||||
resource "alicloud_eip_association" "attach" {
|
||||
allocation_id = "${alicloud_eip.eip.id}"
|
||||
instance_id = "${alicloud_instance.nat.id}"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group" "group" {
|
||||
name = "terraform-test-group"
|
||||
description = "New security group"
|
||||
vpc_id = "${alicloud_vpc.main.id}"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group_rule" "allow_in" {
|
||||
security_group_id = "${alicloud_security_group.group.id}"
|
||||
type = "ingress"
|
||||
cidr_ip= "0.0.0.0/0"
|
||||
policy = "accept"
|
||||
ip_protocol= "all"
|
||||
nic_type= "intranet"
|
||||
port_range= "-1/-1"
|
||||
priority= 1
|
||||
}
|
||||
|
||||
resource "alicloud_security_group_rule" "allow_out" {
|
||||
security_group_id = "${alicloud_security_group.group.id}"
|
||||
type = "egress"
|
||||
cidr_ip= "0.0.0.0/0"
|
||||
policy = "accept"
|
||||
ip_protocol= "all"
|
||||
nic_type= "intranet"
|
||||
port_range= "-1/-1"
|
||||
priority= 1
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
output "nat_instance_id" {
|
||||
value = "${alicloud_instance.nat.id}"
|
||||
}
|
||||
|
||||
output "nat_instance_private_ip" {
|
||||
value = "${alicloud_instance.nat.private_ip}"
|
||||
}
|
||||
|
||||
output "nat_instance_eip_address" {
|
||||
value = "${alicloud_eip.eip.ip_address}"
|
||||
}
|
||||
|
||||
output "worker_instance_id" {
|
||||
value = "${alicloud_instance.worker.id}"
|
||||
}
|
||||
|
||||
output "worker_instance_private_ip" {
|
||||
value = "${alicloud_instance.worker.private_ip}"
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
PostRouting=${vswitch_cidr}
|
||||
SourceRouting=`ifconfig eth0|grep inet|awk '{print $2}'|tr -d 'addr:'`
|
||||
echo ${worker_private_ip}>> /etc/sysctl.conf
|
||||
echo 'net.ipv4.ip_forward=1'>> /etc/sysctl.conf
|
||||
sysctl -p
|
||||
iptables -t nat -I POSTROUTING -s $PostRouting -j SNAT --to-source $SourceRouting
|
||||
iptables -t nat -I PREROUTING -d $SourceRouting -p tcp --dport 80 -j DNAT --to ${worker_private_ip}
|
|
@ -1,27 +0,0 @@
|
|||
variable "vpc_cidr" {
|
||||
default = "10.1.0.0/21"
|
||||
}
|
||||
|
||||
variable "vswitch_cidr" {
|
||||
default = "10.1.1.0/24"
|
||||
}
|
||||
|
||||
variable "zone" {
|
||||
default = "cn-beijing-c"
|
||||
}
|
||||
|
||||
variable "image" {
|
||||
default = "ubuntu_140405_64_40G_cloudinit_20161115.vhd"
|
||||
}
|
||||
|
||||
variable "instance_nat_type" {
|
||||
default = "ecs.n1.small"
|
||||
}
|
||||
|
||||
variable "instance_worker_type" {
|
||||
default = "ecs.s2.large"
|
||||
}
|
||||
|
||||
variable "instance_pwd" {
|
||||
default = "Test123456"
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
### 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
|
|
@ -1,79 +0,0 @@
|
|||
resource "alicloud_security_group" "group" {
|
||||
name = "${var.short_name}"
|
||||
description = "New security group"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group_rule" "http-in" {
|
||||
type = "ingress"
|
||||
ip_protocol = "tcp"
|
||||
nic_type = "internet"
|
||||
policy = "accept"
|
||||
port_range = "80/80"
|
||||
priority = 1
|
||||
security_group_id = "${alicloud_security_group.group.id}"
|
||||
cidr_ip = "0.0.0.0/0"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group_rule" "https-in" {
|
||||
type = "ingress"
|
||||
ip_protocol = "tcp"
|
||||
nic_type = "internet"
|
||||
policy = "accept"
|
||||
port_range = "443/443"
|
||||
priority = 1
|
||||
security_group_id = "${alicloud_security_group.group.id}"
|
||||
cidr_ip = "0.0.0.0/0"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group_rule" "ssh-in" {
|
||||
type = "ingress"
|
||||
ip_protocol = "tcp"
|
||||
nic_type = "internet"
|
||||
policy = "accept"
|
||||
port_range = "22/22"
|
||||
priority = 1
|
||||
security_group_id = "${alicloud_security_group.group.id}"
|
||||
cidr_ip = "0.0.0.0/0"
|
||||
}
|
||||
|
||||
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}"
|
||||
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}"
|
||||
availability_zone = ""
|
||||
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}"]
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
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}"
|
||||
}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
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
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
### 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
|
|
@ -1,39 +0,0 @@
|
|||
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}"]
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
output "hostname_list" {
|
||||
value = "${join(",", alicloud_instance.instance.*.instance_name)}"
|
||||
}
|
||||
|
||||
output "ecs_ids" {
|
||||
value = "${join(",", alicloud_instance.instance.*.id)}"
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
variable "count" {
|
||||
default = "6"
|
||||
}
|
||||
variable "count_format" {
|
||||
default = "%02d"
|
||||
}
|
||||
|
||||
variable "security_groups" {
|
||||
type = "list"
|
||||
default = ["sg-2zecd09tw30jo1c7ekdi"]
|
||||
}
|
||||
variable "ecs_password" {
|
||||
default = "Test12345"
|
||||
}
|
||||
variable "slb_id"{
|
||||
default = "lb-2zel5fjqk1qgmwud7t3xb"
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
### ECS with UserData Example
|
||||
|
||||
Pass shell scripts to Ecs Instance by user_data parameter.
|
||||
|
||||
### Get up and running
|
||||
|
||||
* Planning phase
|
||||
|
||||
terraform plan
|
||||
|
||||
* Apply phase
|
||||
|
||||
terraform apply
|
||||
|
||||
* Destroy
|
||||
|
||||
terraform destroy
|
|
@ -1,48 +0,0 @@
|
|||
|
||||
resource "alicloud_vpc" "default" {
|
||||
name = "tf-vpc"
|
||||
cidr_block = "${var.vpc_cidr}"
|
||||
}
|
||||
|
||||
resource "alicloud_vswitch" "vsw" {
|
||||
vpc_id = "${alicloud_vpc.default.id}"
|
||||
cidr_block = "${var.vswitch_cidr}"
|
||||
availability_zone = "${var.zone}"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group" "sg" {
|
||||
name = "tf-sg"
|
||||
description = "sg"
|
||||
vpc_id = "${alicloud_vpc.default.id}"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group_rule" "allow_ssh" {
|
||||
security_group_id = "${alicloud_security_group.sg.id}"
|
||||
type = "ingress"
|
||||
cidr_ip= "0.0.0.0/0"
|
||||
policy = "accept"
|
||||
ip_protocol= "tcp"
|
||||
port_range= "22/22"
|
||||
priority= 1
|
||||
}
|
||||
|
||||
resource "alicloud_instance" "website" {
|
||||
# cn-beijing
|
||||
availability_zone = "${var.zone}"
|
||||
vswitch_id = "${alicloud_vswitch.vsw.id}"
|
||||
image_id = "${var.image}"
|
||||
|
||||
# series II
|
||||
instance_type = "${var.ecs_type}"
|
||||
io_optimized = "optimized"
|
||||
system_disk_category = "cloud_efficiency"
|
||||
|
||||
internet_charge_type = "PayByTraffic"
|
||||
internet_max_bandwidth_out = 5
|
||||
allocate_public_ip = true
|
||||
security_groups = ["${alicloud_security_group.sg.id}"]
|
||||
instance_name = "tf_website"
|
||||
password= "${var.password}"
|
||||
|
||||
user_data = "${file("userdata.sh")}"
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
|
||||
output "ecs_id" {
|
||||
value = "${alicloud_instance.website.id}"
|
||||
}
|
||||
|
||||
output "ecs_public_ip" {
|
||||
value = "${alicloud_instance.website.public_ip}"
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
#!/bin/bash -v
|
||||
apt-get update -y
|
||||
apt-get install -y nginx > /tmp/nginx.log
|
||||
|
||||
cd /
|
||||
mkdir -p alicloud/go
|
|
@ -1,23 +0,0 @@
|
|||
variable "vpc_cidr" {
|
||||
default = "172.16.0.0/12"
|
||||
}
|
||||
|
||||
variable "vswitch_cidr" {
|
||||
default = "172.16.0.0/21"
|
||||
}
|
||||
|
||||
variable "zone" {
|
||||
default = "cn-beijing-b"
|
||||
}
|
||||
|
||||
variable "password" {
|
||||
default = "Test123456"
|
||||
}
|
||||
|
||||
variable "image" {
|
||||
default = "ubuntu_140405_32_40G_cloudinit_20161115.vhd"
|
||||
}
|
||||
|
||||
variable "ecs_type" {
|
||||
default = "ecs.n1.medium"
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
### VPC Cluster Example
|
||||
|
||||
The example launches VPC cluster, include VPC, VSwitch, Nategateway, ECS, SecurityGroups. the example used the "module" to create instances. The variables.tf can let you create specify parameter instances, such as image_id, ecs_type, count etc.
|
||||
|
||||
### Get up and running
|
||||
|
||||
* Planning phase
|
||||
|
||||
terraform plan
|
||||
|
||||
|
||||
* Apply phase
|
||||
|
||||
terraform apply
|
||||
|
||||
|
||||
* Destroy
|
||||
|
||||
terraform destroy
|
|
@ -1,53 +0,0 @@
|
|||
|
||||
module "vpc" {
|
||||
availability_zones = "${var.availability_zones}"
|
||||
source = "../alicloud-vpc"
|
||||
short_name = "${var.short_name}"
|
||||
region = "${var.region}"
|
||||
}
|
||||
|
||||
module "security-groups" {
|
||||
source = "../alicloud-vpc-cluster-sg"
|
||||
short_name = "${var.short_name}"
|
||||
vpc_id = "${module.vpc.vpc_id}"
|
||||
}
|
||||
|
||||
module "control-nodes" {
|
||||
source = "../alicloud-ecs-vpc"
|
||||
count = "${var.control_count}"
|
||||
role = "control"
|
||||
datacenter = "${var.datacenter}"
|
||||
ecs_type = "${var.control_ecs_type}"
|
||||
disk_size = "${var.control_disk_size}"
|
||||
ssh_username = "${var.ssh_username}"
|
||||
short_name = "${var.short_name}"
|
||||
availability_zones = "${module.vpc.availability_zones}"
|
||||
security_groups = ["${module.security-groups.control_security_group}"]
|
||||
vswitch_id = "${module.vpc.vswitch_ids}"
|
||||
}
|
||||
|
||||
module "edge-nodes" {
|
||||
source = "../alicloud-ecs-vpc"
|
||||
count = "${var.edge_count}"
|
||||
role = "edge"
|
||||
datacenter = "${var.datacenter}"
|
||||
ecs_type = "${var.edge_ecs_type}"
|
||||
ssh_username = "${var.ssh_username}"
|
||||
short_name = "${var.short_name}"
|
||||
availability_zones = "${module.vpc.availability_zones}"
|
||||
security_groups = ["${module.security-groups.worker_security_group}"]
|
||||
vswitch_id = "${module.vpc.vswitch_ids}"
|
||||
}
|
||||
|
||||
module "worker-nodes" {
|
||||
source = "../alicloud-ecs-vpc"
|
||||
count = "${var.worker_count}"
|
||||
role = "worker"
|
||||
datacenter = "${var.datacenter}"
|
||||
ecs_type = "${var.worker_ecs_type}"
|
||||
ssh_username = "${var.ssh_username}"
|
||||
short_name = "${var.short_name}"
|
||||
availability_zones = "${module.vpc.availability_zones}"
|
||||
security_groups = ["${module.security-groups.worker_security_group}"]
|
||||
vswitch_id = "${module.vpc.vswitch_ids}"
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
variable "ecs_password" {
|
||||
default = "Test12345"
|
||||
}
|
||||
|
||||
variable "control_count" {
|
||||
default = "3"
|
||||
}
|
||||
variable "control_count_format" {
|
||||
default = "%02d"
|
||||
}
|
||||
variable "control_ecs_type" {
|
||||
default = "ecs.n1.medium"
|
||||
}
|
||||
variable "control_disk_size" {
|
||||
default = "100"
|
||||
}
|
||||
|
||||
variable "edge_count" {
|
||||
default = "2"
|
||||
}
|
||||
variable "edge_count_format" {
|
||||
default = "%02d"
|
||||
}
|
||||
variable "edge_ecs_type" {
|
||||
default = "ecs.n1.small"
|
||||
}
|
||||
|
||||
variable "worker_count" {
|
||||
default = "1"
|
||||
}
|
||||
variable "worker_count_format" {
|
||||
default = "%03d"
|
||||
}
|
||||
variable "worker_ecs_type" {
|
||||
default = "ecs.n1.small"
|
||||
}
|
||||
|
||||
variable "short_name" {
|
||||
default = "ali"
|
||||
}
|
||||
variable "ssh_username" {
|
||||
default = "root"
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
default = "cn-beijing"
|
||||
}
|
||||
|
||||
variable "availability_zones" {
|
||||
default = "cn-beijing-c"
|
||||
}
|
||||
|
||||
variable "datacenter" {
|
||||
default = "beijing"
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
### ECS In VPC Example
|
||||
|
||||
The example launches ECS in VPC, vswitch_id parameter is the vswitch id from VPC. It also create disk, and attached the disk on ECS. The variables.tf can let you create specify parameter instances, such as image_id, ecs_type, count etc.
|
||||
|
||||
### 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}
|
||||
var.vswitch_id
|
||||
Enter a value: {vswitch_id}
|
||||
....
|
||||
|
||||
* Apply phase
|
||||
|
||||
terraform apply
|
||||
var.availability_zones
|
||||
Enter a value: {var.availability_zones} /*cn-beijing-b*/
|
||||
var.datacenter
|
||||
Enter a value: {datacenter}
|
||||
var.vswitch_id
|
||||
Enter a value: {vswitch_id}
|
||||
....
|
||||
|
||||
* Destroy
|
||||
|
||||
terraform destroy
|
|
@ -1,45 +0,0 @@
|
|||
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 = "${var.image_id}"
|
||||
instance_type = "${var.ecs_type}"
|
||||
count = "${var.count}"
|
||||
availability_zone = "${var.availability_zones}"
|
||||
security_groups = ["${var.security_groups}"]
|
||||
vswitch_id = "${var.vswitch_id}"
|
||||
|
||||
internet_charge_type = "${var.internet_charge_type}"
|
||||
internet_max_bandwidth_out = "${var.internet_max_bandwidth_out}"
|
||||
|
||||
io_optimized = "${var.io_optimized}"
|
||||
|
||||
allocate_public_ip = "${var.allocate_public_ip}"
|
||||
|
||||
password = "${var.ecs_password}"
|
||||
|
||||
instance_charge_type = "${var.instance_charge_type}"
|
||||
system_disk_category = "${var.system_disk_category}"
|
||||
|
||||
|
||||
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}"
|
||||
}
|
||||
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
output "hostname_list" {
|
||||
value = "${join(",", alicloud_instance.instance.*.instance_name)}"
|
||||
}
|
||||
|
||||
output "ecs_ids" {
|
||||
value = "${join(",", alicloud_instance.instance.*.id)}"
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
variable "count" {
|
||||
default = "1"
|
||||
}
|
||||
variable "count_format" {
|
||||
default = "%02d"
|
||||
}
|
||||
variable "image_id" {
|
||||
default = "ubuntu_140405_64_40G_cloudinit_20161115.vhd"
|
||||
}
|
||||
|
||||
variable "role" {
|
||||
}
|
||||
variable "datacenter" {
|
||||
}
|
||||
variable "short_name" {
|
||||
default = "hi"
|
||||
}
|
||||
variable "ecs_type" {
|
||||
}
|
||||
variable "ecs_password" {
|
||||
default = "Test12345"
|
||||
}
|
||||
variable "availability_zones" {
|
||||
}
|
||||
variable "security_groups" {
|
||||
type = "list"
|
||||
}
|
||||
variable "ssh_username" {
|
||||
default = "root"
|
||||
}
|
||||
|
||||
//if instance_charge_type is "PrePaid", then must be set period, the value is 1 to 30, unit is month
|
||||
variable "instance_charge_type" {
|
||||
default = "PostPaid"
|
||||
}
|
||||
|
||||
variable "system_disk_category" {
|
||||
default = "cloud_efficiency"
|
||||
}
|
||||
|
||||
variable "internet_charge_type" {
|
||||
default = "PayByTraffic"
|
||||
}
|
||||
variable "internet_max_bandwidth_out" {
|
||||
default = 5
|
||||
}
|
||||
|
||||
variable "io_optimized" {
|
||||
default = "optimized"
|
||||
}
|
||||
|
||||
variable "allocate_public_ip" {
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "disk_category" {
|
||||
default = "cloud_ssd"
|
||||
}
|
||||
variable "disk_size" {
|
||||
default = "40"
|
||||
}
|
||||
variable "device_name" {
|
||||
default = "/dev/xvdb"
|
||||
}
|
||||
|
||||
variable "vswitch_id" {
|
||||
default = ""
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
### Ecs Instance Type Data Source Example
|
||||
|
||||
The example launches Ecs instance type Data Resource. Then set ecs parameter instance_type refer to the Data Resource config above.
|
||||
|
||||
### Get up and running
|
||||
|
||||
* Planning phase
|
||||
|
||||
terraform plan
|
||||
|
||||
|
||||
* Apply phase
|
||||
|
||||
terraform apply
|
||||
|
||||
|
||||
* Destroy
|
||||
|
||||
terraform destroy
|
|
@ -1,75 +0,0 @@
|
|||
data "alicloud_instance_types" "1c2g" {
|
||||
cpu_core_count = 1
|
||||
memory_size = 2
|
||||
instance_type_family = "ecs.n1"
|
||||
}
|
||||
|
||||
data "alicloud_zones" "default" {
|
||||
"available_instance_type"= "${data.alicloud_instance_types.1c2g.instance_types.0.id}"
|
||||
"available_disk_category"= "${var.disk_category}"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group" "group" {
|
||||
name = "${var.short_name}"
|
||||
description = "New security group"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group_rule" "http-in" {
|
||||
type = "ingress"
|
||||
ip_protocol = "tcp"
|
||||
nic_type = "internet"
|
||||
policy = "accept"
|
||||
port_range = "80/80"
|
||||
priority = 1
|
||||
security_group_id = "${alicloud_security_group.group.id}"
|
||||
cidr_ip = "0.0.0.0/0"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group_rule" "https-in" {
|
||||
type = "ingress"
|
||||
ip_protocol = "tcp"
|
||||
nic_type = "internet"
|
||||
policy = "accept"
|
||||
port_range = "443/443"
|
||||
priority = 1
|
||||
security_group_id = "${alicloud_security_group.group.id}"
|
||||
cidr_ip = "0.0.0.0/0"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group_rule" "ssh-in" {
|
||||
type = "ingress"
|
||||
ip_protocol = "tcp"
|
||||
nic_type = "internet"
|
||||
policy = "accept"
|
||||
port_range = "22/22"
|
||||
priority = 1
|
||||
security_group_id = "${alicloud_security_group.group.id}"
|
||||
cidr_ip = "0.0.0.0/0"
|
||||
}
|
||||
|
||||
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 = "${data.alicloud_instance_types.1c2g.instance_types.0.id}"
|
||||
count = "${var.count}"
|
||||
availability_zone = "${data.alicloud_zones.default.zones.0.id}"
|
||||
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}"
|
||||
|
||||
instance_charge_type = "PostPaid"
|
||||
system_disk_category = "${var.disk_category}"
|
||||
|
||||
|
||||
tags {
|
||||
role = "${var.role}"
|
||||
dc = "${var.datacenter}"
|
||||
}
|
||||
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
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)}"
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
variable "count" {
|
||||
default = "1"
|
||||
}
|
||||
variable "count_format" {
|
||||
default = "%02d"
|
||||
}
|
||||
|
||||
variable "image_id" {
|
||||
default = "ubuntu_140405_64_40G_cloudinit_20161115.vhd"
|
||||
}
|
||||
|
||||
variable "disk_category" {
|
||||
default = "cloud_ssd"
|
||||
}
|
||||
variable "role" {
|
||||
default = "work"
|
||||
}
|
||||
variable "datacenter" {
|
||||
default = "beijing"
|
||||
}
|
||||
variable "short_name" {
|
||||
default = "hi"
|
||||
}
|
||||
variable "ecs_password" {
|
||||
default = "Test12345"
|
||||
}
|
||||
variable "internet_charge_type" {
|
||||
default = "PayByTraffic"
|
||||
}
|
||||
variable "internet_max_bandwidth_out" {
|
||||
default = 5
|
||||
}
|
||||
variable "io_optimized" {
|
||||
default = "optimized"
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
### ECS Example
|
||||
|
||||
The example launches ECS instance, disk, and attached the disk on ECS. the count parameter in variables.tf can let you 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
|
|
@ -1,76 +0,0 @@
|
|||
data "alicloud_instance_types" "instance_type" {
|
||||
instance_type_family = "ecs.n1"
|
||||
cpu_core_count = "1"
|
||||
memory_size = "2"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group" "group" {
|
||||
name = "${var.short_name}"
|
||||
description = "New security group"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group_rule" "allow_http_80" {
|
||||
type = "ingress"
|
||||
ip_protocol = "tcp"
|
||||
nic_type = "${var.nic_type}"
|
||||
policy = "accept"
|
||||
port_range = "80/80"
|
||||
priority = 1
|
||||
security_group_id = "${alicloud_security_group.group.id}"
|
||||
cidr_ip = "0.0.0.0/0"
|
||||
}
|
||||
|
||||
|
||||
resource "alicloud_security_group_rule" "allow_https_443" {
|
||||
type = "ingress"
|
||||
ip_protocol = "tcp"
|
||||
nic_type = "${var.nic_type}"
|
||||
policy = "accept"
|
||||
port_range = "443/443"
|
||||
priority = 1
|
||||
security_group_id = "${alicloud_security_group.group.id}"
|
||||
cidr_ip = "0.0.0.0/0"
|
||||
}
|
||||
|
||||
resource "alicloud_disk" "disk" {
|
||||
availability_zone = "${alicloud_instance.instance.0.availability_zone}"
|
||||
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 = "${var.image_id}"
|
||||
instance_type = "${data.alicloud_instance_types.instance_type.instance_types.0.id}"
|
||||
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}"
|
||||
|
||||
password = "${var.ecs_password}"
|
||||
|
||||
allocate_public_ip = "${var.allocate_public_ip}"
|
||||
|
||||
io_optimized = "${var.io_optimized}"
|
||||
|
||||
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}"
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
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)}"
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
variable "count" {
|
||||
default = "1"
|
||||
}
|
||||
variable "count_format" {
|
||||
default = "%02d"
|
||||
}
|
||||
variable "image_id" {
|
||||
default = "ubuntu_140405_64_40G_cloudinit_20161115.vhd"
|
||||
}
|
||||
|
||||
variable "availability_zones" {
|
||||
default = ""
|
||||
}
|
||||
|
||||
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 "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_efficiency"
|
||||
}
|
||||
variable "disk_size" {
|
||||
default = "40"
|
||||
}
|
||||
variable "device_name" {
|
||||
default = "/dev/xvdb"
|
||||
}
|
||||
|
||||
variable "nic_type" {
|
||||
default = "internet"
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
### ESS scaling configuration Example
|
||||
|
||||
The example launches ESS scaling configuration, will create ECS instance automatic by system schedule.
|
||||
|
||||
### Get up and running
|
||||
|
||||
* Planning phase
|
||||
|
||||
terraform plan
|
||||
|
||||
* Apply phase
|
||||
|
||||
terraform apply
|
||||
|
||||
* Destroy
|
||||
|
||||
terraform destroy
|
|
@ -1,38 +0,0 @@
|
|||
data "alicloud_images" "ecs_image" {
|
||||
most_recent = true
|
||||
name_regex = "^centos_6\\w{1,5}[64].*"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group" "sg" {
|
||||
name = "${var.security_group_name}"
|
||||
description = "tf-sg"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group_rule" "ssh-in" {
|
||||
type = "ingress"
|
||||
ip_protocol = "tcp"
|
||||
nic_type = "internet"
|
||||
policy = "accept"
|
||||
port_range = "22/22"
|
||||
priority = 1
|
||||
security_group_id = "${alicloud_security_group.sg.id}"
|
||||
cidr_ip = "0.0.0.0/0"
|
||||
}
|
||||
|
||||
resource "alicloud_ess_scaling_group" "scaling" {
|
||||
min_size = "${var.scaling_min_size}"
|
||||
max_size = "${var.scaling_max_size}"
|
||||
scaling_group_name = "tf-scaling"
|
||||
removal_policies = "${var.removal_policies}"
|
||||
|
||||
}
|
||||
|
||||
resource "alicloud_ess_scaling_configuration" "config" {
|
||||
scaling_group_id = "${alicloud_ess_scaling_group.scaling.id}"
|
||||
enable = "${var.enable}"
|
||||
|
||||
image_id = "${data.alicloud_images.ecs_image.images.0.id}"
|
||||
instance_type = "${var.ecs_instance_type}"
|
||||
io_optimized = "optimized"
|
||||
security_group_id = "${alicloud_security_group.sg.id}"
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
output "scaling_group_id" {
|
||||
value = "${alicloud_ess_scaling_group.scaling.id}"
|
||||
}
|
||||
|
||||
output "configuration_id" {
|
||||
value = "${alicloud_ess_scaling_configuration.config.id}"
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
variable "security_group_name" {
|
||||
default = "tf-sg"
|
||||
}
|
||||
|
||||
variable "scaling_min_size" {
|
||||
default = 1
|
||||
}
|
||||
|
||||
variable "scaling_max_size" {
|
||||
default = 1
|
||||
}
|
||||
|
||||
variable "enable" {
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "removal_policies" {
|
||||
type = "list"
|
||||
default = ["OldestInstance", "NewestInstance"]
|
||||
}
|
||||
|
||||
variable "ecs_instance_type" {
|
||||
default = "ecs.s2.large"
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
### ESS scaling schedule Example
|
||||
|
||||
The example launches ESS schedule task, which will create ECS by the schedule time.
|
||||
|
||||
### Get up and running
|
||||
|
||||
* Planning phase
|
||||
|
||||
terraform plan
|
||||
|
||||
* Apply phase
|
||||
|
||||
terraform apply
|
||||
|
||||
* Destroy
|
||||
|
||||
terraform destroy
|
|
@ -1,51 +0,0 @@
|
|||
data "alicloud_images" "ecs_image" {
|
||||
most_recent = true
|
||||
name_regex = "^centos_6\\w{1,5}[64].*"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group" "sg" {
|
||||
name = "${var.security_group_name}"
|
||||
description = "tf-sg"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group_rule" "ssh-in" {
|
||||
type = "ingress"
|
||||
ip_protocol = "tcp"
|
||||
nic_type = "internet"
|
||||
policy = "accept"
|
||||
port_range = "22/22"
|
||||
priority = 1
|
||||
security_group_id = "${alicloud_security_group.sg.id}"
|
||||
cidr_ip = "0.0.0.0/0"
|
||||
}
|
||||
|
||||
resource "alicloud_ess_scaling_group" "scaling" {
|
||||
min_size = "${var.scaling_min_size}"
|
||||
max_size = "${var.scaling_max_size}"
|
||||
scaling_group_name = "tf-scaling"
|
||||
removal_policies = "${var.removal_policies}"
|
||||
|
||||
}
|
||||
|
||||
resource "alicloud_ess_scaling_configuration" "config" {
|
||||
scaling_group_id = "${alicloud_ess_scaling_group.scaling.id}"
|
||||
enable = "${var.enable}"
|
||||
|
||||
image_id = "${data.alicloud_images.ecs_image.images.0.id}"
|
||||
instance_type = "${var.ecs_instance_type}"
|
||||
io_optimized = "optimized"
|
||||
security_group_id = "${alicloud_security_group.sg.id}"
|
||||
}
|
||||
|
||||
resource "alicloud_ess_scaling_rule" "rule" {
|
||||
scaling_group_id = "${alicloud_ess_scaling_group.scaling.id}"
|
||||
adjustment_type = "TotalCapacity"
|
||||
adjustment_value = "${var.rule_adjust_size}"
|
||||
cooldown = 60
|
||||
}
|
||||
|
||||
resource "alicloud_ess_schedule" "run" {
|
||||
scheduled_action = "${alicloud_ess_scaling_rule.rule.ari}"
|
||||
launch_time = "${var.schedule_launch_time}"
|
||||
scheduled_task_name = "tf-run"
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
output "scaling_group_id" {
|
||||
value = "${alicloud_ess_scaling_group.scaling.id}"
|
||||
}
|
||||
|
||||
output "configuration_id" {
|
||||
value = "${alicloud_ess_scaling_configuration.config.id}"
|
||||
}
|
||||
|
||||
output "configuration_ari" {
|
||||
value = "${alicloud_ess_scaling_configuration.config.ari}"
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
variable "security_group_name" {
|
||||
default = "tf-sg"
|
||||
}
|
||||
|
||||
variable "scaling_min_size" {
|
||||
default = 1
|
||||
}
|
||||
|
||||
variable "scaling_max_size" {
|
||||
default = 1
|
||||
}
|
||||
|
||||
variable "enable" {
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "removal_policies" {
|
||||
type = "list"
|
||||
default = ["OldestInstance", "NewestInstance"]
|
||||
}
|
||||
|
||||
variable "ecs_instance_type" {
|
||||
default = "ecs.s2.large"
|
||||
}
|
||||
|
||||
variable "rule_adjust_size" {
|
||||
default = 3
|
||||
}
|
||||
|
||||
variable "schedule_launch_time" {
|
||||
default = "2017-04-01T01:59Z"
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
### RDS Example
|
||||
|
||||
The example launches RDS instance, database, account and grant the database readwrite privilege to the account.
|
||||
|
||||
### Get up and running
|
||||
|
||||
* Planning phase
|
||||
|
||||
terraform plan
|
||||
|
||||
* Apply phase
|
||||
|
||||
terraform apply
|
||||
|
||||
* Destroy
|
||||
|
||||
terraform destroy
|
|
@ -1,17 +0,0 @@
|
|||
|
||||
resource "alicloud_db_instance" "dc" {
|
||||
engine = "${var.engine}"
|
||||
engine_version = "${var.engine_version}"
|
||||
db_instance_class = "${var.instance_class}"
|
||||
db_instance_storage = "${var.storage}"
|
||||
db_instance_net_type = "${var.net_type}"
|
||||
|
||||
master_user_name = "${var.user_name}"
|
||||
master_user_password = "${var.password}"
|
||||
|
||||
db_mappings = [{
|
||||
db_name = "${var.database_name}"
|
||||
character_set_name = "${var.database_character}"
|
||||
db_description = "tf"
|
||||
}]
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
output "port" {
|
||||
value = "${alicloud_db_instance.dc.port}"
|
||||
}
|
||||
|
||||
output "connections" {
|
||||
value = "${alicloud_db_instance.dc.connections}"
|
||||
}
|
||||
|
||||
output "security_ips" {
|
||||
value = "${alicloud_db_instance.dc.security_ips}"
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
variable "engine" {
|
||||
default = "MySQL"
|
||||
}
|
||||
variable "engine_version" {
|
||||
default = "5.6"
|
||||
}
|
||||
variable "instance_class" {
|
||||
default = "rds.mysql.t1.small"
|
||||
}
|
||||
variable "storage" {
|
||||
default = "10"
|
||||
}
|
||||
variable "net_type" {
|
||||
default = "Intranet"
|
||||
}
|
||||
|
||||
variable "user_name" {
|
||||
default = "tf_tester"
|
||||
}
|
||||
variable "password" {
|
||||
default = "Test12345"
|
||||
}
|
||||
|
||||
variable "database_name" {
|
||||
default = "bookstore"
|
||||
}
|
||||
variable "database_character" {
|
||||
default = "utf8"
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
resource "alicloud_security_group" "default" {
|
||||
name = "${var.security_group_name}"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group_rule" "http-in" {
|
||||
type = "ingress"
|
||||
ip_protocol = "tcp"
|
||||
nic_type = "internet"
|
||||
policy = "accept"
|
||||
port_range = "80/80"
|
||||
priority = 1
|
||||
security_group_id = "${alicloud_security_group.default.id}"
|
||||
cidr_ip = "0.0.0.0/0"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group_rule" "ssh-in" {
|
||||
type = "ingress"
|
||||
ip_protocol = "tcp"
|
||||
nic_type = "internet"
|
||||
policy = "accept"
|
||||
port_range = "22/22"
|
||||
priority = 1
|
||||
security_group_id = "${alicloud_security_group.default.id}"
|
||||
cidr_ip = "0.0.0.0/0"
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
output "rule_id" {
|
||||
value = "${alicloud_security_group_rule.allow_all_tcp.id}"
|
||||
}
|
||||
|
||||
output "rule_type" {
|
||||
value = "${alicloud_security_group_rule.allow_all_tcp.type}"
|
||||
}
|
||||
|
||||
output "port_range" {
|
||||
value = "${alicloud_security_group_rule.allow_all_tcp.port_range}"
|
||||
}
|
||||
|
||||
output "ip_protocol" {
|
||||
value = "${alicloud_security_group_rule.allow_all_tcp.ip_protocol}"
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
variable "security_group_name" {
|
||||
default = "default-sg"
|
||||
}
|
||||
|
||||
variable "nic_type" {
|
||||
default = "internet"
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
### SecurityGroup With Vpc Example
|
||||
|
||||
The example create SecurityGroup for specify VPC.
|
||||
|
||||
### Get up and running
|
||||
|
||||
* Planning phase
|
||||
|
||||
terraform plan
|
||||
|
||||
|
||||
* Apply phase
|
||||
|
||||
terraform apply
|
||||
|
||||
|
||||
* Destroy
|
||||
|
||||
terraform destroy
|
|
@ -1,5 +0,0 @@
|
|||
resource "alicloud_security_group" "group" {
|
||||
name = "${var.short_name}"
|
||||
description = "New security group"
|
||||
vpc_id = "${var.vpc_id}"
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
output "security_group" {
|
||||
value = "${alicloud_security_group.group.id}"
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
variable "short_name" {
|
||||
}
|
||||
variable "vpc_id" {
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
### SLB With VPC Example
|
||||
|
||||
The example create SLB in special VPC, The variables.tf can let you create specify parameter instances, such as vpc_id, vswitch_id.
|
||||
|
||||
### Get up and running
|
||||
|
||||
* Planning phase
|
||||
|
||||
terraform plan
|
||||
|
||||
|
||||
* Apply phase
|
||||
|
||||
terraform apply
|
||||
|
||||
|
||||
* Destroy
|
||||
|
||||
terraform destroy
|
|
@ -1,27 +0,0 @@
|
|||
resource "alicloud_vpc" "main" {
|
||||
name = "${var.long_name}"
|
||||
cidr_block = "${var.vpc_cidr}"
|
||||
}
|
||||
|
||||
resource "alicloud_vswitch" "main" {
|
||||
vpc_id = "${alicloud_vpc.main.id}"
|
||||
count = "${length(split(",", var.availability_zones))}"
|
||||
cidr_block = "${lookup(var.cidr_blocks, "az${count.index}")}"
|
||||
availability_zone = "${element(split(",", var.availability_zones), count.index)}"
|
||||
depends_on = [
|
||||
"alicloud_vpc.main"]
|
||||
}
|
||||
|
||||
resource "alicloud_slb" "instance" {
|
||||
name = "${var.name}"
|
||||
vswitch_id = "${alicloud_vswitch.main.id}"
|
||||
internet_charge_type = "${var.internet_charge_type}"
|
||||
listener = [
|
||||
{
|
||||
"instance_port" = "2111"
|
||||
"lb_port" = "21"
|
||||
"lb_protocol" = "tcp"
|
||||
"bandwidth" = "5"
|
||||
}]
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
output "slb_id" {
|
||||
value = "${alicloud_slb.instance.id}"
|
||||
}
|
||||
|
||||
output "slbname" {
|
||||
value = "${alicloud_slb.instance.name}"
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
variable "availability_zones" {
|
||||
default = "cn-beijing-c"
|
||||
}
|
||||
|
||||
variable "name" {
|
||||
default = "slb_alicloud"
|
||||
}
|
||||
|
||||
variable "cidr_blocks" {
|
||||
type = "map"
|
||||
default = {
|
||||
az0 = "10.1.1.0/24"
|
||||
az1 = "10.1.2.0/24"
|
||||
az2 = "10.1.3.0/24"
|
||||
}
|
||||
}
|
||||
|
||||
variable "internet_charge_type" {
|
||||
default = "paybytraffic"
|
||||
}
|
||||
|
||||
variable "long_name" {
|
||||
default = "alicloud"
|
||||
}
|
||||
variable "vpc_cidr" {
|
||||
default = "10.1.0.0/21"
|
||||
}
|
||||
variable "region" {
|
||||
default = "cn-beijing"
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
### SLB Example
|
||||
|
||||
The example create SLB and additional listener, the listener parameter following:
|
||||
|
||||
### SLB Listener parameter describe
|
||||
listener parameter | support protocol | value range | remark |
|
||||
------------- | ------------- | ------------- | ------------- |
|
||||
instance_port | http & https & tcp & udp | 1-65535 | the ecs instance port |
|
||||
lb_port | http & https & tcp & udp | 1-65535 | the slb linstener port |
|
||||
lb_protocol | http & https & tcp & udp | http or https or tcp or udp | |
|
||||
bandwidth | http & https & tcp & udp | -1 / 1-1000 | |
|
||||
scheduler | http & https & tcp & udp | wrr or wlc | |
|
||||
sticky_session | http & https | on or off | |
|
||||
sticky_session_type | http & https | insert or server | if sticky_session is on, the value must have|
|
||||
cookie_timeout | http & https | 1-86400 | if sticky_session is on and sticky_session_type is insert, the value must have|
|
||||
cookie | http & https | | if sticky_session is on and sticky_session_type is server, the value must have|
|
||||
persistence_timeout | tcp & udp | 0-3600 | |
|
||||
health_check | http & https | on or off | |
|
||||
health_check_type | tcp | tcp or http | if health_check is on, the value must have |
|
||||
health_check_domain | http & https & tcp | | example: $_ip/some string/.if health_check is on, the value must have |
|
||||
health_check_uri | http & https & tcp | | example: /aliyun. if health_check is on, the value must have |
|
||||
health_check_connect_port | http & https & tcp & udp | 1-65535 or -520 | if health_check is on, the value must have |
|
||||
healthy_threshold | http & https & tcp & udp | 1-10 | if health_check is on, the value must have |
|
||||
unhealthy_threshold | http & https & tcp & udp | 1-10 | if health_check is on, the value must have |
|
||||
health_check_timeout | http & https & tcp & udp | 1-50 | if health_check is on, the value must have |
|
||||
health_check_interval | http & https & tcp & udp | 1-5 | if health_check is on, the value must have |
|
||||
health_check_http_code | http & https & tcp | http_2xx,http_3xx,http_4xx,http_5xx | if health_check is on, the value must have |
|
||||
ssl_certificate_id | https | | |
|
||||
|
||||
### Get up and running
|
||||
|
||||
* Planning phase
|
||||
|
||||
terraform plan
|
||||
|
||||
* Apply phase
|
||||
|
||||
terraform apply
|
||||
|
||||
|
||||
* Destroy
|
||||
|
||||
terraform destroy
|
|
@ -1,54 +0,0 @@
|
|||
resource "alicloud_slb" "instance" {
|
||||
name = "${var.slb_name}"
|
||||
internet_charge_type = "${var.internet_charge_type}"
|
||||
internet = "${var.internet}"
|
||||
|
||||
listener = [
|
||||
{
|
||||
"instance_port" = "22"
|
||||
"lb_port" = "22"
|
||||
"lb_protocol" = "tcp"
|
||||
"bandwidth" = "10"
|
||||
"health_check_type" = "http"
|
||||
"persistence_timeout" = 3600
|
||||
"healthy_threshold" = 8
|
||||
"unhealthy_threshold" = 8
|
||||
"health_check_timeout" = 8
|
||||
"health_check_interval" = 5
|
||||
"health_check_http_code" = "http_2xx,http_3xx"
|
||||
"health_check_timeout" = 8
|
||||
},
|
||||
|
||||
{
|
||||
"instance_port" = "2001"
|
||||
"lb_port" = "2001"
|
||||
"lb_protocol" = "udp"
|
||||
"bandwidth" = "10"
|
||||
"persistence_timeout" = 3600
|
||||
"healthy_threshold" = 8
|
||||
"unhealthy_threshold" = 8
|
||||
"health_check_timeout" = 8
|
||||
"health_check_interval" = 4
|
||||
"health_check_timeout" = 8
|
||||
},
|
||||
|
||||
{
|
||||
"instance_port" = "80"
|
||||
"lb_port" = "80"
|
||||
"lb_protocol" = "http"
|
||||
"sticky_session" = "on"
|
||||
"sticky_session_type" = "server"
|
||||
"cookie" = "testslblistenercookie"
|
||||
"cookie_timeout" = 86400
|
||||
"health_check" = "on"
|
||||
"health_check_domain" = "$_ip"
|
||||
"health_check_uri" = "/console"
|
||||
"health_check_connect_port" = 20
|
||||
"healthy_threshold" = 8
|
||||
"unhealthy_threshold" = 8
|
||||
"health_check_timeout" = 8
|
||||
"health_check_interval" = 5
|
||||
"health_check_http_code" = "http_2xx,http_3xx"
|
||||
"bandwidth" = 10
|
||||
}]
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
output "slb_id" {
|
||||
value = "${alicloud_slb.instance.id}"
|
||||
}
|
||||
|
||||
output "slbname" {
|
||||
value = "${alicloud_slb.instance.name}"
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
variable "slb_name" {
|
||||
default = "slb_worder"
|
||||
}
|
||||
|
||||
variable "internet_charge_type" {
|
||||
default = "paybytraffic"
|
||||
}
|
||||
|
||||
variable "internet" {
|
||||
default = true
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
### SecurityGroups With Vpc Example
|
||||
|
||||
The example create SecurityGroups for specify VPC Clusters.
|
||||
|
||||
### Get up and running
|
||||
|
||||
* Planning phase
|
||||
|
||||
terraform plan
|
||||
|
||||
|
||||
* Apply phase
|
||||
|
||||
terraform apply
|
||||
|
||||
|
||||
* Destroy
|
||||
|
||||
terraform destroy
|
|
@ -1,23 +0,0 @@
|
|||
resource "alicloud_security_group" "default" {
|
||||
name = "${var.short_name}-default"
|
||||
description = "Default security group for VPC"
|
||||
vpc_id = "${var.vpc_id}"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group" "control" {
|
||||
name = "${var.short_name}-control"
|
||||
description = "Allow inboud traffic for control nodes"
|
||||
vpc_id = "${var.vpc_id}"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group" "edge" {
|
||||
name = "${var.short_name}-edge"
|
||||
description = "Allow inboud traffic for edge routing"
|
||||
vpc_id = "${var.vpc_id}"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group" "worker" {
|
||||
name = "${var.short_name}-worker"
|
||||
description = "Allow inboud traffic for worker nodes"
|
||||
vpc_id = "${var.vpc_id}"
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
output "default_security_group" {
|
||||
value = "${alicloud_security_group.default.id}"
|
||||
}
|
||||
|
||||
output "edge_security_group" {
|
||||
value = "${alicloud_security_group.edge.id}"
|
||||
}
|
||||
|
||||
output "control_security_group" {
|
||||
value = "${alicloud_security_group.control.id}"
|
||||
}
|
||||
|
||||
output "worker_security_group" {
|
||||
value = "${alicloud_security_group.worker.id}"
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
variable "short_name" {
|
||||
}
|
||||
variable "vpc_id" {
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
### VPC Example
|
||||
|
||||
The example will create VPC in multi region use "alias" characters.
|
||||
|
||||
### Get up and running
|
||||
|
||||
* Planning phase
|
||||
|
||||
terraform plan
|
||||
|
||||
* Apply phase
|
||||
|
||||
terraform apply
|
||||
|
||||
|
||||
* Destroy
|
||||
|
||||
terraform destroy
|
|
@ -1,21 +0,0 @@
|
|||
provider "alicloud" {
|
||||
alias = "bj"
|
||||
region = "${var.region1}"
|
||||
}
|
||||
|
||||
provider "alicloud" {
|
||||
alias = "hz"
|
||||
region = "${var.region2}"
|
||||
}
|
||||
|
||||
resource "alicloud_vpc" "work" {
|
||||
provider = "alicloud.hz"
|
||||
name = "${var.long_name}"
|
||||
cidr_block = "${var.vpc_cidr}"
|
||||
}
|
||||
|
||||
resource "alicloud_vpc" "control" {
|
||||
provider = "alicloud.bj"
|
||||
name = "${var.long_name}"
|
||||
cidr_block = "${var.vpc_cidr}"
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
output "vpc_work_id" {
|
||||
value = "${alicloud_vpc.work.id}"
|
||||
}
|
||||
|
||||
output "vpc_control_id" {
|
||||
value = "${alicloud_vpc.control.id}"
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
variable "long_name" {
|
||||
default = "alicloud"
|
||||
}
|
||||
variable "vpc_cidr" {
|
||||
default = "10.1.0.0/21"
|
||||
}
|
||||
variable "region1" {
|
||||
default = "cn-beijing"
|
||||
}
|
||||
variable "region2" {
|
||||
default = "cn-hangzhou"
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
resource "alicloud_vpc" "default" {
|
||||
name = "tf_vpc"
|
||||
cidr_block = "${var.vpc_cidr}"
|
||||
}
|
||||
|
||||
resource "alicloud_vswitch" "default" {
|
||||
vpc_id = "${alicloud_vpc.default.id}"
|
||||
cidr_block = "${var.vswitch_cidr}"
|
||||
availability_zone = "${var.zone_id}"
|
||||
}
|
||||
|
||||
resource "alicloud_route_entry" "default" {
|
||||
router_id = "${alicloud_vpc.default.router_id}"
|
||||
route_table_id = "${alicloud_vpc.default.router_table_id}"
|
||||
destination_cidrblock = "${var.entry_cidr}"
|
||||
nexthop_type = "Instance"
|
||||
nexthop_id = "${alicloud_instance.snat.id}"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group" "sg" {
|
||||
name = "tf_sg"
|
||||
description = "tf_sg"
|
||||
vpc_id = "${alicloud_vpc.default.id}"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group_rule" "ssh-in" {
|
||||
type = "ingress"
|
||||
ip_protocol = "tcp"
|
||||
nic_type = "intranet"
|
||||
policy = "${var.rule_policy}"
|
||||
port_range = "22/22"
|
||||
priority = 1
|
||||
security_group_id = "${alicloud_security_group.sg.id}"
|
||||
cidr_ip = "0.0.0.0/0"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group_rule" "http-in" {
|
||||
type = "ingress"
|
||||
ip_protocol = "tcp"
|
||||
nic_type = "internet"
|
||||
policy = "accept"
|
||||
port_range = "80/80"
|
||||
priority = 1
|
||||
security_group_id = "${alicloud_security_group.sg.id}"
|
||||
cidr_ip = "0.0.0.0/0"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group_rule" "https-in" {
|
||||
type = "ingress"
|
||||
ip_protocol = "tcp"
|
||||
nic_type = "internet"
|
||||
policy = "accept"
|
||||
port_range = "443/443"
|
||||
priority = 1
|
||||
security_group_id = "${alicloud_security_group.sg.id}"
|
||||
cidr_ip = "0.0.0.0/0"
|
||||
}
|
||||
|
||||
resource "alicloud_instance" "snat" {
|
||||
# cn-beijing
|
||||
availability_zone = "${var.zone_id}"
|
||||
security_groups = ["${alicloud_security_group.sg.id}"]
|
||||
|
||||
vswitch_id = "${alicloud_vswitch.default.id}"
|
||||
allocate_public_ip = true
|
||||
|
||||
# series II
|
||||
instance_charge_type = "PostPaid"
|
||||
instance_type = "${var.instance_type}"
|
||||
internet_charge_type = "${var.internet_charge_type}"
|
||||
internet_max_bandwidth_out = 5
|
||||
io_optimized = "${var.io_optimized}"
|
||||
|
||||
system_disk_category = "cloud_efficiency"
|
||||
image_id = "${var.image_id}"
|
||||
instance_name = "tf_snat"
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
output "route_table_id" {
|
||||
value = "${alicloud_route_entry.default.route_table_id}"
|
||||
}
|
||||
|
||||
output "router_id" {
|
||||
value = "${alicloud_route_entry.default.router_id}"
|
||||
}
|
||||
|
||||
output "nexthop_type" {
|
||||
value = "${alicloud_route_entry.default.nexthop_type}"
|
||||
}
|
||||
|
||||
output "nexthop_id" {
|
||||
value = "${alicloud_route_entry.default.nexthop_id}"
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
|
||||
variable "vpc_cidr" {
|
||||
default = "10.1.0.0/21"
|
||||
}
|
||||
variable "vswitch_cidr" {
|
||||
default = "10.1.1.0/24"
|
||||
}
|
||||
variable "zone_id" {
|
||||
default = "cn-beijing-c"
|
||||
}
|
||||
variable "entry_cidr" {
|
||||
default = "172.11.1.1/32"
|
||||
}
|
||||
variable "rule_policy" {
|
||||
default = "accept"
|
||||
}
|
||||
variable "instance_type" {
|
||||
default = "ecs.n1.small"
|
||||
}
|
||||
variable "image_id" {
|
||||
default = "ubuntu_140405_64_40G_cloudinit_20161115.vhd"
|
||||
}
|
||||
variable "internet_charge_type" {
|
||||
default = "PayByTraffic"
|
||||
}
|
||||
variable "io_optimized" {
|
||||
default = "optimized"
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
provider "alicloud" {
|
||||
region = "cn-hangzhou"
|
||||
}
|
||||
|
||||
data "alicloud_instance_types" "1c2g" {
|
||||
cpu_core_count = 1
|
||||
memory_size = 2
|
||||
instance_type_family = "ecs.n1"
|
||||
}
|
||||
|
||||
data "alicloud_zones" "default" {
|
||||
"available_instance_type"= "${data.alicloud_instance_types.1c2g.instance_types.0.id}"
|
||||
"available_disk_category"= "${var.disk_category}"
|
||||
}
|
||||
|
||||
resource "alicloud_vpc" "default" {
|
||||
name = "tf_vpc"
|
||||
cidr_block = "${var.vpc_cidr}"
|
||||
}
|
||||
|
||||
resource "alicloud_vswitch" "default" {
|
||||
vpc_id = "${alicloud_vpc.default.id}"
|
||||
cidr_block = "${var.vswitch_cidr}"
|
||||
availability_zone = "${data.alicloud_zones.default.zones.0.id}"
|
||||
}
|
||||
|
||||
resource "alicloud_nat_gateway" "default" {
|
||||
vpc_id = "${alicloud_vpc.default.id}"
|
||||
spec = "Small"
|
||||
name = "test_foo"
|
||||
bandwidth_packages = [{
|
||||
ip_count = 2
|
||||
bandwidth = 5
|
||||
zone = "${data.alicloud_zones.default.zones.0.id}"
|
||||
}]
|
||||
depends_on = [
|
||||
"alicloud_vswitch.default"]
|
||||
}
|
||||
resource "alicloud_snat_entry" "default"{
|
||||
snat_table_id = "${alicloud_nat_gateway.default.snat_table_ids}"
|
||||
source_vswitch_id = "${alicloud_vswitch.default.id}"
|
||||
snat_ip = "${element(split(",", alicloud_nat_gateway.default.bandwidth_packages.0.public_ip_addresses),0)}"
|
||||
}
|
||||
|
||||
resource "alicloud_forward_entry" "default"{
|
||||
forward_table_id = "${alicloud_nat_gateway.default.forward_table_ids}"
|
||||
external_ip = "${element(split(",", alicloud_nat_gateway.default.bandwidth_packages.0.public_ip_addresses),1)}"
|
||||
external_port = "80"
|
||||
ip_protocol = "tcp"
|
||||
internal_ip = "${alicloud_instance.default.private_ip}"
|
||||
internal_port = "8080"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group" "sg" {
|
||||
name = "tf_sg"
|
||||
description = "tf_sg"
|
||||
vpc_id = "${alicloud_vpc.default.id}"
|
||||
}
|
||||
|
||||
resource "alicloud_security_group_rule" "http-in" {
|
||||
type = "ingress"
|
||||
ip_protocol = "tcp"
|
||||
nic_type = "intranet"
|
||||
policy = "accept"
|
||||
port_range = "80/80"
|
||||
priority = 1
|
||||
security_group_id = "${alicloud_security_group.sg.id}"
|
||||
cidr_ip = "0.0.0.0/0"
|
||||
}
|
||||
|
||||
resource "alicloud_instance" "default" {
|
||||
# cn-beijing
|
||||
availability_zone = "${data.alicloud_zones.default.zones.0.id}"
|
||||
security_groups = ["${alicloud_security_group.sg.id}"]
|
||||
|
||||
vswitch_id = "${alicloud_vswitch.default.id}"
|
||||
|
||||
# series II
|
||||
instance_charge_type = "PostPaid"
|
||||
instance_type = "${var.instance_type}"
|
||||
internet_max_bandwidth_out = 0
|
||||
io_optimized = "${var.io_optimized}"
|
||||
|
||||
system_disk_category = "cloud_efficiency"
|
||||
image_id = "${var.image_id}"
|
||||
instance_name = "tf_vpc_snat"
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
output "instance_id" {
|
||||
value = "${alicloud_instance.default.id}"
|
||||
}
|
||||
|
||||
output "bindwidth_package_ip" {
|
||||
value = "${alicloud_nat_gateway.default.bandwidth_packages.0.public_ip_addresses}"
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
|
||||
variable "vpc_cidr" {
|
||||
default = "10.1.0.0/21"
|
||||
}
|
||||
variable "vswitch_cidr" {
|
||||
default = "10.1.1.0/24"
|
||||
}
|
||||
variable "rule_policy" {
|
||||
default = "accept"
|
||||
}
|
||||
variable "instance_type" {
|
||||
default = "ecs.n1.small"
|
||||
}
|
||||
variable "image_id" {
|
||||
default = "ubuntu_140405_64_40G_cloudinit_20161115.vhd"
|
||||
}
|
||||
variable "io_optimized" {
|
||||
default = "optimized"
|
||||
}
|
||||
variable "disk_category"{
|
||||
default = "cloud_efficiency"
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
### VPC Example
|
||||
|
||||
The example create VPC, VSwitch, Natgateway. The variables.tf can let you create specify parameter instances, such as availability_zone, cidr_block etc.
|
||||
|
||||
### Get up and running
|
||||
|
||||
* Planning phase
|
||||
|
||||
terraform plan
|
||||
|
||||
* Apply phase
|
||||
|
||||
terraform apply
|
||||
|
||||
|
||||
* Destroy
|
||||
|
||||
terraform destroy
|
|
@ -1,28 +0,0 @@
|
|||
resource "alicloud_vpc" "main" {
|
||||
name = "${var.long_name}"
|
||||
cidr_block = "${var.vpc_cidr}"
|
||||
}
|
||||
|
||||
resource "alicloud_vswitch" "main" {
|
||||
vpc_id = "${alicloud_vpc.main.id}"
|
||||
count = "${length(split(",", var.availability_zones))}"
|
||||
cidr_block = "${lookup(var.cidr_blocks, "az${count.index}")}"
|
||||
availability_zone = "${var.availability_zones}"
|
||||
depends_on = [
|
||||
"alicloud_vpc.main"]
|
||||
}
|
||||
|
||||
resource "alicloud_nat_gateway" "main" {
|
||||
vpc_id = "${alicloud_vpc.main.id}"
|
||||
spec = "Small"
|
||||
bandwidth_packages = [
|
||||
{
|
||||
ip_count = 1
|
||||
bandwidth = 5
|
||||
zone = "${var.availability_zones}"
|
||||
}
|
||||
]
|
||||
depends_on = [
|
||||
"alicloud_vswitch.main"]
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
output "vpc_id" {
|
||||
value = "${alicloud_vpc.main.id}"
|
||||
}
|
||||
|
||||
output "vswitch_ids" {
|
||||
value = "${join(",", alicloud_vswitch.main.*.id)}"
|
||||
}
|
||||
|
||||
output "availability_zones" {
|
||||
value = "${join(",",alicloud_vswitch.main.*.availability_zone)}"
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
variable "availability_zones" {
|
||||
default = "cn-beijing-c"
|
||||
}
|
||||
|
||||
variable "cidr_blocks" {
|
||||
type = "map"
|
||||
default = {
|
||||
az0 = "10.1.1.0/24"
|
||||
az1 = "10.1.2.0/24"
|
||||
az2 = "10.1.3.0/24"
|
||||
}
|
||||
}
|
||||
|
||||
variable "long_name" {
|
||||
default = "alicloud"
|
||||
}
|
||||
variable "short_name" {
|
||||
default = "ali"
|
||||
}
|
||||
variable "vpc_cidr" {
|
||||
default = "10.1.0.0/21"
|
||||
}
|
||||
variable "region" {
|
||||
default = "cn-beijing"
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
# ASG example
|
||||
|
||||
This example shows how to launch instances using Auto Scaling Groups.
|
||||
|
||||
This creates a security group, launch configuration, auto scaling group and an ELB. The user data for launch configuration installs nginx and it listens on port 80.
|
||||
|
||||
The example uses latest Ubuntu AMIs.
|
||||
|
||||
Make sure you change the list of availability zones that is applicable to your account and region.
|
||||
|
||||
To run, configure your AWS provider as described in https://www.terraform.io/docs/providers/aws/index.html
|
||||
|
||||
Running the example
|
||||
|
||||
For planning phase
|
||||
|
||||
```
|
||||
terraform plan -var 'key_name={your_key_name}'
|
||||
```
|
||||
|
||||
For apply phase
|
||||
|
||||
```
|
||||
terraform apply -var 'key_name={your_key_name}'
|
||||
```
|
||||
Once the stack is created, wait for few minutes and test the stack by launching a browser with ELB url.
|
||||
|
||||
To remove the stack
|
||||
|
||||
```
|
||||
terraform destroy -var 'key_name={your_key_name}'
|
||||
```
|
|
@ -1,86 +0,0 @@
|
|||
# Specify the provider and access details
|
||||
provider "aws" {
|
||||
region = "${var.aws_region}"
|
||||
}
|
||||
|
||||
resource "aws_elb" "web-elb" {
|
||||
name = "terraform-example-elb"
|
||||
|
||||
# The same availability zone as our instances
|
||||
availability_zones = ["${split(",", var.availability_zones)}"]
|
||||
|
||||
listener {
|
||||
instance_port = 80
|
||||
instance_protocol = "http"
|
||||
lb_port = 80
|
||||
lb_protocol = "http"
|
||||
}
|
||||
|
||||
health_check {
|
||||
healthy_threshold = 2
|
||||
unhealthy_threshold = 2
|
||||
timeout = 3
|
||||
target = "HTTP:80/"
|
||||
interval = 30
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_autoscaling_group" "web-asg" {
|
||||
availability_zones = ["${split(",", var.availability_zones)}"]
|
||||
name = "terraform-example-asg"
|
||||
max_size = "${var.asg_max}"
|
||||
min_size = "${var.asg_min}"
|
||||
desired_capacity = "${var.asg_desired}"
|
||||
force_delete = true
|
||||
launch_configuration = "${aws_launch_configuration.web-lc.name}"
|
||||
load_balancers = ["${aws_elb.web-elb.name}"]
|
||||
|
||||
#vpc_zone_identifier = ["${split(",", var.availability_zones)}"]
|
||||
tag {
|
||||
key = "Name"
|
||||
value = "web-asg"
|
||||
propagate_at_launch = "true"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_launch_configuration" "web-lc" {
|
||||
name = "terraform-example-lc"
|
||||
image_id = "${lookup(var.aws_amis, var.aws_region)}"
|
||||
instance_type = "${var.instance_type}"
|
||||
|
||||
# Security group
|
||||
security_groups = ["${aws_security_group.default.id}"]
|
||||
user_data = "${file("userdata.sh")}"
|
||||
key_name = "${var.key_name}"
|
||||
}
|
||||
|
||||
# Our default security group to access
|
||||
# the instances over SSH and HTTP
|
||||
resource "aws_security_group" "default" {
|
||||
name = "terraform_example_sg"
|
||||
description = "Used in the terraform"
|
||||
|
||||
# SSH access from anywhere
|
||||
ingress {
|
||||
from_port = 22
|
||||
to_port = 22
|
||||
protocol = "tcp"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
|
||||
# HTTP access from anywhere
|
||||
ingress {
|
||||
from_port = 80
|
||||
to_port = 80
|
||||
protocol = "tcp"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
|
||||
# outbound internet access
|
||||
egress {
|
||||
from_port = 0
|
||||
to_port = 0
|
||||
protocol = "-1"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
output "security_group" {
|
||||
value = "${aws_security_group.default.id}"
|
||||
}
|
||||
|
||||
output "launch_configuration" {
|
||||
value = "${aws_launch_configuration.web-lc.id}"
|
||||
}
|
||||
|
||||
output "asg_name" {
|
||||
value = "${aws_autoscaling_group.web-asg.id}"
|
||||
}
|
||||
|
||||
output "elb_name" {
|
||||
value = "${aws_elb.web-elb.dns_name}"
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
#!/bin/bash -v
|
||||
apt-get update -y
|
||||
apt-get install -y nginx > /tmp/nginx.log
|
|
@ -1,41 +0,0 @@
|
|||
variable "aws_region" {
|
||||
description = "The AWS region to create things in."
|
||||
default = "us-east-1"
|
||||
}
|
||||
|
||||
# ubuntu-trusty-14.04 (x64)
|
||||
variable "aws_amis" {
|
||||
default = {
|
||||
"us-east-1" = "ami-5f709f34"
|
||||
"us-west-2" = "ami-7f675e4f"
|
||||
}
|
||||
}
|
||||
|
||||
variable "availability_zones" {
|
||||
default = "us-east-1b,us-east-1c,us-east-1d,us-east-1e"
|
||||
description = "List of availability zones, use AWS CLI to find your "
|
||||
}
|
||||
|
||||
variable "key_name" {
|
||||
description = "Name of AWS key pair"
|
||||
}
|
||||
|
||||
variable "instance_type" {
|
||||
default = "t2.micro"
|
||||
description = "AWS instance type"
|
||||
}
|
||||
|
||||
variable "asg_min" {
|
||||
description = "Min numbers of servers in ASG"
|
||||
default = "1"
|
||||
}
|
||||
|
||||
variable "asg_max" {
|
||||
description = "Max numbers of servers in ASG"
|
||||
default = "2"
|
||||
}
|
||||
|
||||
variable "asg_desired" {
|
||||
description = "Desired numbers of servers in ASG"
|
||||
default = "1"
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
# CloudWatch Event sent to Kinesis Stream
|
||||
|
||||
This example sets up a CloudWatch Event Rule with a Target and IAM Role & Policy
|
||||
to send all autoscaling events into Kinesis stream for further examination.
|
||||
|
||||
See more details about [CloudWatch Events](http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/WhatIsCloudWatchEvents.html)
|
||||
in the official AWS docs.
|
||||
|
||||
## How to run the example
|
||||
|
||||
```
|
||||
terraform apply \
|
||||
-var=aws_region=us-west-2
|
||||
```
|
|
@ -1,76 +0,0 @@
|
|||
provider "aws" {
|
||||
region = "${var.aws_region}"
|
||||
}
|
||||
|
||||
resource "aws_cloudwatch_event_rule" "foo" {
|
||||
name = "${var.rule_name}"
|
||||
|
||||
event_pattern = <<PATTERN
|
||||
{
|
||||
"detail-type": [
|
||||
"AWS API Call via CloudTrail"
|
||||
],
|
||||
"detail": {
|
||||
"eventSource": [
|
||||
"autoscaling.amazonaws.com"
|
||||
]
|
||||
}
|
||||
}
|
||||
PATTERN
|
||||
|
||||
role_arn = "${aws_iam_role.role.arn}"
|
||||
}
|
||||
|
||||
resource "aws_iam_role" "role" {
|
||||
name = "${var.iam_role_name}"
|
||||
|
||||
assume_role_policy = <<POLICY
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Action": "sts:AssumeRole",
|
||||
"Principal": {
|
||||
"Service": "events.amazonaws.com"
|
||||
},
|
||||
"Effect": "Allow",
|
||||
"Sid": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
POLICY
|
||||
}
|
||||
|
||||
resource "aws_iam_role_policy" "policy" {
|
||||
name = "tf-example-policy"
|
||||
role = "${aws_iam_role.role.id}"
|
||||
|
||||
policy = <<POLICY
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Action": [
|
||||
"kinesis:PutRecord",
|
||||
"kinesis:PutRecords"
|
||||
],
|
||||
"Resource": [
|
||||
"*"
|
||||
],
|
||||
"Effect": "Allow"
|
||||
}
|
||||
]
|
||||
}
|
||||
POLICY
|
||||
}
|
||||
|
||||
resource "aws_cloudwatch_event_target" "foobar" {
|
||||
rule = "${aws_cloudwatch_event_rule.foo.name}"
|
||||
target_id = "${var.target_name}"
|
||||
arn = "${aws_kinesis_stream.foo.arn}"
|
||||
}
|
||||
|
||||
resource "aws_kinesis_stream" "foo" {
|
||||
name = "${var.stream_name}"
|
||||
shard_count = 1
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
output "rule_arn" {
|
||||
value = "${aws_cloudwatch_event_rule.foo.arn}"
|
||||
}
|
||||
|
||||
output "kinesis_stream_arn" {
|
||||
value = "${aws_kinesis_stream.foo.arn}"
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
variable "aws_region" {
|
||||
description = "The AWS region to create resources in."
|
||||
default = "us-east-1"
|
||||
}
|
||||
|
||||
variable "rule_name" {
|
||||
description = "The name of the CloudWatch Event Rule"
|
||||
default = "tf-example-cloudwatch-event-rule-for-kinesis"
|
||||
}
|
||||
|
||||
variable "iam_role_name" {
|
||||
description = "The name of the IAM Role"
|
||||
default = "tf-example-iam-role-for-kinesis"
|
||||
}
|
||||
|
||||
variable "target_name" {
|
||||
description = "The name of the CloudWatch Event Target"
|
||||
default = "tf-example-cloudwatch-event-target-for-kinesis"
|
||||
}
|
||||
|
||||
variable "stream_name" {
|
||||
description = "The name of the Kinesis Stream to send events to"
|
||||
default = "tf-example-kinesis-stream"
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
# CloudWatch Event sent to SNS Topic
|
||||
|
||||
This example sets up a CloudWatch Event Rule with a Target and SNS Topic
|
||||
to send any CloudTrail API operation into that SNS topic. This allows you
|
||||
to add SNS subscriptions which may notify you about suspicious activity.
|
||||
|
||||
See more details about [CloudWatch Events](http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/WhatIsCloudWatchEvents.html)
|
||||
in the official AWS docs.
|
||||
|
||||
## How to run the example
|
||||
|
||||
```
|
||||
terraform apply \
|
||||
-var=aws_region=us-west-2
|
||||
```
|
|
@ -1,30 +0,0 @@
|
|||
provider "aws" {
|
||||
region = "${var.aws_region}"
|
||||
}
|
||||
|
||||
resource "aws_cloudwatch_event_rule" "foo" {
|
||||
name = "${var.rule_name}"
|
||||
|
||||
event_pattern = <<PATTERN
|
||||
{
|
||||
"detail-type": [
|
||||
"AWS API Call via CloudTrail"
|
||||
],
|
||||
"detail": {
|
||||
"eventSource": [
|
||||
"cloudtrail.amazonaws.com"
|
||||
]
|
||||
}
|
||||
}
|
||||
PATTERN
|
||||
}
|
||||
|
||||
resource "aws_cloudwatch_event_target" "bar" {
|
||||
rule = "${aws_cloudwatch_event_rule.foo.name}"
|
||||
target_id = "${var.target_name}"
|
||||
arn = "${aws_sns_topic.foo.arn}"
|
||||
}
|
||||
|
||||
resource "aws_sns_topic" "foo" {
|
||||
name = "${var.sns_topic_name}"
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
output "rule_arn" {
|
||||
value = "${aws_cloudwatch_event_rule.foo.arn}"
|
||||
}
|
||||
|
||||
output "sns_topic_arn" {
|
||||
value = "${aws_sns_topic.foo.arn}"
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
variable "aws_region" {
|
||||
description = "The AWS region to create resources in."
|
||||
default = "us-east-1"
|
||||
}
|
||||
|
||||
variable "rule_name" {
|
||||
description = "The name of the CloudWatch Event Rule"
|
||||
default = "tf-example-cloudwatch-event-rule-for-sns"
|
||||
}
|
||||
|
||||
variable "target_name" {
|
||||
description = "The name of the CloudWatch Event Target"
|
||||
default = "tf-example-cloudwatch-event-target-for-sns"
|
||||
}
|
||||
|
||||
variable "sns_topic_name" {
|
||||
description = "The name of the SNS Topic to send events to"
|
||||
default = "tf-example-sns-topic"
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue