github.com/candidpartners/terraform@v0.9.5-0.20171005231213-29f5f88820f6/examples/alicloud-ecs-nat/main.tf (about) 1 resource "alicloud_vpc" "main" { 2 cidr_block = "${var.vpc_cidr}" 3 } 4 5 resource "alicloud_vswitch" "main" { 6 vpc_id = "${alicloud_vpc.main.id}" 7 cidr_block = "${var.vswitch_cidr}" 8 availability_zone = "${var.zone}" 9 depends_on = ["alicloud_vpc.main"] 10 } 11 12 resource "alicloud_route_entry" "entry" { 13 router_id = "${alicloud_vpc.main.router_id}" 14 route_table_id = "${alicloud_vpc.main.router_table_id}" 15 destination_cidrblock = "0.0.0.0/0" 16 nexthop_type = "Instance" 17 nexthop_id = "${alicloud_instance.nat.id}" 18 } 19 20 resource "alicloud_instance" "nat" { 21 image_id = "${var.image}" 22 instance_type = "${var.instance_nat_type}" 23 availability_zone = "${var.zone}" 24 security_groups = ["${alicloud_security_group.group.id}"] 25 vswitch_id = "${alicloud_vswitch.main.id}" 26 instance_name = "nat" 27 io_optimized = "optimized" 28 system_disk_category = "cloud_efficiency" 29 password= "${var.instance_pwd}" 30 31 depends_on = ["alicloud_instance.worker"] 32 user_data = "${data.template_file.shell.rendered}" 33 34 tags { 35 Name = "ecs-nat" 36 } 37 } 38 39 data "template_file" "shell" { 40 template = "${file("userdata.sh")}" 41 42 vars { 43 worker_private_ip = "${alicloud_instance.worker.private_ip}" 44 vswitch_cidr = "${var.vswitch_cidr}" 45 } 46 } 47 48 resource "alicloud_instance" "worker" { 49 image_id = "${var.image}" 50 instance_type = "${var.instance_worker_type}" 51 availability_zone = "${var.zone}" 52 security_groups = ["${alicloud_security_group.group.id}"] 53 vswitch_id = "${alicloud_vswitch.main.id}" 54 instance_name = "worker" 55 io_optimized = "optimized" 56 system_disk_category = "cloud_efficiency" 57 password= "${var.instance_pwd}" 58 59 tags { 60 Name = "ecs-worker" 61 } 62 } 63 64 resource "alicloud_eip" "eip" { 65 } 66 67 resource "alicloud_eip_association" "attach" { 68 allocation_id = "${alicloud_eip.eip.id}" 69 instance_id = "${alicloud_instance.nat.id}" 70 } 71 72 resource "alicloud_security_group" "group" { 73 name = "terraform-test-group" 74 description = "New security group" 75 vpc_id = "${alicloud_vpc.main.id}" 76 } 77 78 resource "alicloud_security_group_rule" "allow_in" { 79 security_group_id = "${alicloud_security_group.group.id}" 80 type = "ingress" 81 cidr_ip= "0.0.0.0/0" 82 policy = "accept" 83 ip_protocol= "all" 84 nic_type= "intranet" 85 port_range= "-1/-1" 86 priority= 1 87 } 88 89 resource "alicloud_security_group_rule" "allow_out" { 90 security_group_id = "${alicloud_security_group.group.id}" 91 type = "egress" 92 cidr_ip= "0.0.0.0/0" 93 policy = "accept" 94 ip_protocol= "all" 95 nic_type= "intranet" 96 port_range= "-1/-1" 97 priority= 1 98 }