website: add count example

This commit is contained in:
Jack Pearkes 2014-07-28 12:30:49 -04:00
parent df56dc25a8
commit 1323870c10
2 changed files with 79 additions and 0 deletions

View File

@ -41,6 +41,7 @@ resource.
variable "aws_access_key" {}
variable "aws_secret_key" {}
variable "key_path" {}
variable "key_name" {}
variable "aws_region" {
default = "us-west-2"
}

View File

@ -0,0 +1,78 @@
---
layout: "intro"
page_title: "Count"
sidebar_current: "examples-count"
---
# Count Example
The count parameter on resources can simplify configurations
and let you scale resources by simply incrementing a number.
Additionally, variables can be used to expand a list of resources
for use elsewhere.
## Command
```
terraform apply \
-var 'aws_access_key=YOUR_ACCESS_KEY' \
-var 'aws_secret_key=YOUR_SECRET_KEY'
```
## Configuration
```
variable "aws_access_key" {}
variable "aws_secret_key" {}
variable "aws_region" {
default = "us-west-2"
}
# Ubuntu Precise 12.04 LTS (x64)
variable "aws_amis" {
default = {
"eu-west-1": "ami-b1cf19c6",
"us-east-1": "ami-de7ab6b6",
"us-west-1": "ami-3f75767a",
"us-west-2": "ami-21f78e11"
}
}
# Specify the provider and access details
provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
region = "${var.aws_region}"
}
resource "aws_elb" "web" {
name = "terraform-example-elb"
# The same availability zone as our instances
availability_zones = ["${aws_instance.web.*.availability_zone}"]
listener {
instance_port = 80
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
# The instances are registered automatically
instances = ["${aws_instance.web.*.id}"]
}
resource "aws_instance" "web" {
instance_type = "m1.small"
ami = "${lookup(var.aws_amis, var.aws_region)}"
# This will create 4 instances
count = 4
}
output "address" {
value = "Instances: ${aws_instance.web.*.id}"
}
```