Skip to content

Instantly share code, notes, and snippets.

@spinx
Created December 27, 2015 20:45
Show Gist options
  • Save spinx/047afb19996b91795dd5 to your computer and use it in GitHub Desktop.
Save spinx/047afb19996b91795dd5 to your computer and use it in GitHub Desktop.
Terraform AWS EC2 classic launch in VPC
# Define VPC id and VPC subnets
variable "vpc_id" {
default = "vpc-6d408308"
}
variable "vpc_subnets" {
default = "subnet-fdda6a98,subnet-17914860,subnet-71708228"
}
# Use VPC id for SG
resource "aws_security_group" "consul" {
vpc_id = "${var.vpc_id}"
}
# Use subnet ids
resource "aws_instance" "consul_server" {
subnet_id = "${ element(split(",", var.vpc_subnets), count.index) }" # you don't need availability_zone if you have one subnet per AZ
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment