Last active
January 26, 2016 21:05
-
-
Save hairyhenderson/153d0e5c451df4e8c513 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provider "aws" { | |
region = "us-east-1" | |
} | |
provider "aws" { | |
alias = "us-east-1" | |
region = "us-east-1" | |
} | |
provider "aws" { | |
alias = "eu-west-1" | |
region = "eu-west-1" | |
} | |
provider "aws" { | |
alias = "us-west-1" | |
region = "us-west-1" | |
} | |
variable "regions" { | |
default = "us-east-1,eu-west-1,us-west-1" | |
} | |
resource "aws_vpc" "vpc" { | |
count = 3 | |
provider = "aws.${element(split(",",var.regions), count.index)}" | |
cidr_block = "10.1.${count.index}.0/24" | |
} |
$ terraform plan
provider.aws.${element(split(",",var.regions), count.index)}.region
The region where AWS operations will take place. Examples
are us-east-1, us-west-2, etc.
Default: us-east-1
Enter a value:
Basically, you'd setup a variable for each attribute being passed into the resource. The value for that variable will be a comma-separated list. Like this:
variable "regions" {
default = "us-east-1,us-east-2,us-east-3"
}
variable "flavors" {
default = "X,Y,Z"
}
resource "aws_vpc" "vpc" {
count = 3
region = "${element(split(",",var.regions), count.index)}"
# Just an example!
flavor = "${element(split(",",var.flavors), count.index)}"
}
This seems to compile without errors:
variable "count" {
default = 1
}
variable "regions" {
default = {
"0" = "us-east-1"
"1" = "eu-west-2"
"2" = "us-west-1"
}
provider "aws" {
alias = "0"
region = "us-east-1"
}
provider "aws" {
alias = "1"
region = "eu-west-1"
}
provider "aws" {
alias = "2"
region = "us-west-1"
}
resource "aws_vpc" "vpc" {
count = 3
provider = "aws.aws_${count.index}"
cidr_block = "10.1.${count.index}.0/24"
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
variable "regions" {
default = "us-east-1,us-east-2,us-east-3"
}
resource "aws_vpc" "vpc" {
count = 3
provider = "${element(split(",",var.regions), count.index)}"
}