github.com/candidpartners/terraform@v0.9.5-0.20171005231213-29f5f88820f6/examples/alicloud-ecs-image/main.tf (about)

     1  data "alicloud_images" "ecs_image" {
     2    most_recent = "${var.most_recent}"
     3    owners = "${var.image_owners}"
     4    name_regex = "${var.name_regex}"
     5  }
     6  
     7  resource "alicloud_security_group" "group" {
     8    name = "${var.short_name}"
     9    description = "New security group"
    10  }
    11  
    12  resource "alicloud_security_group_rule" "http-in" {
    13    type = "ingress"
    14    ip_protocol = "tcp"
    15    nic_type = "internet"
    16    policy = "accept"
    17    port_range = "80/80"
    18    priority = 1
    19    security_group_id = "${alicloud_security_group.group.id}"
    20    cidr_ip = "0.0.0.0/0"
    21  }
    22  
    23  resource "alicloud_security_group_rule" "https-in" {
    24    type = "ingress"
    25    ip_protocol = "tcp"
    26    nic_type = "internet"
    27    policy = "accept"
    28    port_range = "443/443"
    29    priority = 1
    30    security_group_id = "${alicloud_security_group.group.id}"
    31    cidr_ip = "0.0.0.0/0"
    32  }
    33  
    34  resource "alicloud_security_group_rule" "ssh-in" {
    35    type = "ingress"
    36    ip_protocol = "tcp"
    37    nic_type = "internet"
    38    policy = "accept"
    39    port_range = "22/22"
    40    priority = 1
    41    security_group_id = "${alicloud_security_group.group.id}"
    42    cidr_ip = "0.0.0.0/0"
    43  }
    44  
    45  
    46  resource "alicloud_disk" "disk" {
    47    availability_zone = "${var.availability_zones}"
    48    category = "${var.disk_category}"
    49    size = "${var.disk_size}"
    50    count = "${var.count}"
    51  }
    52  
    53  resource "alicloud_instance" "instance" {
    54    instance_name = "${var.short_name}-${var.role}-${format(var.count_format, count.index+1)}"
    55    host_name = "${var.short_name}-${var.role}-${format(var.count_format, count.index+1)}"
    56    image_id = "${data.alicloud_images.ecs_image.images.0.id}"
    57    instance_type = "${var.ecs_type}"
    58    count = "${var.count}"
    59    availability_zone = "${var.availability_zones}"
    60    security_groups = ["${alicloud_security_group.group.*.id}"]
    61  
    62    internet_charge_type = "${var.internet_charge_type}"
    63    internet_max_bandwidth_out = "${var.internet_max_bandwidth_out}"
    64  
    65    io_optimized = "${var.io_optimized}"
    66  
    67    password = "${var.ecs_password}"
    68  
    69    allocate_public_ip = "${var.allocate_public_ip}"
    70  
    71    instance_charge_type = "PostPaid"
    72    system_disk_category = "cloud_efficiency"
    73  
    74  
    75    tags {
    76      role = "${var.role}"
    77      dc = "${var.datacenter}"
    78    }
    79  
    80  }
    81  
    82  resource "alicloud_disk_attachment" "instance-attachment" {
    83    count = "${var.count}"
    84    disk_id = "${element(alicloud_disk.disk.*.id, count.index)}"
    85    instance_id = "${element(alicloud_instance.instance.*.id, count.index)}"
    86    device_name = "${var.device_name}"
    87  }
    88