github.com/andresvia/terraform@v0.6.15-0.20160412045437-d51c75946785/examples/clc/main.tf (about)

     1  # --------------------
     2  # Credentials
     3  provider "clc" {
     4    username = "${var.clc_username}"
     5    password = "${var.clc_password}"
     6    account = "${var.clc_account}"
     7  }
     8  
     9  # --------------------
    10  # Provision/Resolve a server group
    11  resource "clc_group" "frontends" {
    12    location_id = "CA1"
    13    name = "frontends"
    14    parent = "Default Group"
    15  }
    16  
    17  # --------------------
    18  # Provision a server
    19  resource "clc_server" "node" {
    20    name_template = "trusty"
    21    source_server_id = "UBUNTU-14-64-TEMPLATE"
    22    group_id = "${clc_group.frontends.id}"
    23    cpu = 2
    24    memory_mb = 2048
    25    password = "Green123$"
    26    additional_disks
    27      {
    28          path = "/var"
    29          size_gb = 100
    30          type = "partitioned"
    31      }
    32    additional_disks
    33      {
    34          size_gb = 10
    35          type = "raw"
    36      }
    37  }
    38  
    39  # --------------------
    40  # Provision a public ip
    41  resource "clc_public_ip" "backdoor" {
    42    server_id = "${clc_server.node.0.id}"
    43    internal_ip_address = "${clc_server.node.0.private_ip_address}"
    44    ports
    45      {
    46        protocol = "ICMP"
    47        port = -1
    48      }
    49    ports
    50      {
    51        protocol = "TCP"
    52        port = 22
    53      }
    54    source_restrictions
    55       { cidr = "173.60.0.0/16" }
    56  
    57  
    58    # ssh in and start a simple http server on :8080
    59    provisioner "remote-exec" {
    60      inline = [
    61        "cd /tmp; python -mSimpleHTTPServer > /dev/null 2>&1 &"
    62      ]
    63      connection {
    64        host = "${clc_public_ip.backdoor.id}"
    65        user = "root"
    66        password = "${clc_server.node.password}"
    67      }
    68    }
    69    
    70  }
    71  
    72  
    73  # --------------------
    74  # Provision a load balancer
    75  resource "clc_load_balancer" "frontdoor" {
    76    data_center = "${clc_group.frontends.location_id}"
    77    name = "frontdoor"
    78    description = "frontdoor"
    79    status = "enabled"
    80  }
    81  
    82  # --------------------
    83  # Provision a load balancer pool
    84  resource "clc_load_balancer_pool" "pool" {
    85    data_center = "${clc_group.frontends.location_id}"
    86    load_balancer = "${clc_load_balancer.frontdoor.id}"
    87    method = "roundRobin"
    88    persistence = "standard"
    89    port = 80
    90    nodes
    91      {
    92        status = "enabled"
    93        ipAddress = "${clc_server.node.private_ip_address}"
    94        privatePort = 8000
    95      }
    96  }