github.com/candidpartners/terraform@v0.9.5-0.20171005231213-29f5f88820f6/examples/alicloud-vpc-snat/main.tf (about) 1 provider "alicloud" { 2 region = "cn-hangzhou" 3 } 4 5 data "alicloud_instance_types" "1c2g" { 6 cpu_core_count = 1 7 memory_size = 2 8 instance_type_family = "ecs.n1" 9 } 10 11 data "alicloud_zones" "default" { 12 "available_instance_type"= "${data.alicloud_instance_types.1c2g.instance_types.0.id}" 13 "available_disk_category"= "${var.disk_category}" 14 } 15 16 resource "alicloud_vpc" "default" { 17 name = "tf_vpc" 18 cidr_block = "${var.vpc_cidr}" 19 } 20 21 resource "alicloud_vswitch" "default" { 22 vpc_id = "${alicloud_vpc.default.id}" 23 cidr_block = "${var.vswitch_cidr}" 24 availability_zone = "${data.alicloud_zones.default.zones.0.id}" 25 } 26 27 resource "alicloud_nat_gateway" "default" { 28 vpc_id = "${alicloud_vpc.default.id}" 29 spec = "Small" 30 name = "test_foo" 31 bandwidth_packages = [{ 32 ip_count = 2 33 bandwidth = 5 34 zone = "${data.alicloud_zones.default.zones.0.id}" 35 }] 36 depends_on = [ 37 "alicloud_vswitch.default"] 38 } 39 resource "alicloud_snat_entry" "default"{ 40 snat_table_id = "${alicloud_nat_gateway.default.snat_table_ids}" 41 source_vswitch_id = "${alicloud_vswitch.default.id}" 42 snat_ip = "${element(split(",", alicloud_nat_gateway.default.bandwidth_packages.0.public_ip_addresses),0)}" 43 } 44 45 resource "alicloud_forward_entry" "default"{ 46 forward_table_id = "${alicloud_nat_gateway.default.forward_table_ids}" 47 external_ip = "${element(split(",", alicloud_nat_gateway.default.bandwidth_packages.0.public_ip_addresses),1)}" 48 external_port = "80" 49 ip_protocol = "tcp" 50 internal_ip = "${alicloud_instance.default.private_ip}" 51 internal_port = "8080" 52 } 53 54 resource "alicloud_security_group" "sg" { 55 name = "tf_sg" 56 description = "tf_sg" 57 vpc_id = "${alicloud_vpc.default.id}" 58 } 59 60 resource "alicloud_security_group_rule" "http-in" { 61 type = "ingress" 62 ip_protocol = "tcp" 63 nic_type = "intranet" 64 policy = "accept" 65 port_range = "80/80" 66 priority = 1 67 security_group_id = "${alicloud_security_group.sg.id}" 68 cidr_ip = "0.0.0.0/0" 69 } 70 71 resource "alicloud_instance" "default" { 72 # cn-beijing 73 availability_zone = "${data.alicloud_zones.default.zones.0.id}" 74 security_groups = ["${alicloud_security_group.sg.id}"] 75 76 vswitch_id = "${alicloud_vswitch.default.id}" 77 78 # series II 79 instance_charge_type = "PostPaid" 80 instance_type = "${var.instance_type}" 81 internet_max_bandwidth_out = 0 82 io_optimized = "${var.io_optimized}" 83 84 system_disk_category = "cloud_efficiency" 85 image_id = "${var.image_id}" 86 instance_name = "tf_vpc_snat" 87 }