Skip to content

Instantly share code, notes, and snippets.

@ascendantlogic
Created October 23, 2015 22:01
Show Gist options
  • Save ascendantlogic/6951af12cd26e6ac43ec to your computer and use it in GitHub Desktop.
Save ascendantlogic/6951af12cd26e6ac43ec to your computer and use it in GitHub Desktop.
access_key = ""
secret_key = ""
provider "aws" {
alias = "west"
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
region = "us-west-2"
}
module "vpc" {
source = "./modules/vpc"
name = "derp-vpc"
cidr = "10.1.0.0/16"
public_subnets = "10.1.0.0/19,10.1.64.0/19,10.1.128.0/19"
private_subnets = "10.1.32.0/19,10.1.96.0/19,10.1.160.0/19"
az_names = "us-west-2a,us-west-2b,us-west-2c"
aws_provider = "aws.west"
nat_instance_size = "t2.small"
nat_ami = "ami-290f4119"
}
resource "aws_vpc" "module" {
provider = "${var.aws_provider}"
cidr_block = "${var.cidr}"
tags { Name = "${var.name}" }
}
resource "aws_internet_gateway" "module" {
provider = "${var.aws_provider}"
vpc_id = "${aws_vpc.module.id}"
}
resource "aws_route_table" "public" {
provider = "${var.aws_provider}"
vpc_id = "${aws_vpc.module.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.module.id}"
}
tags { Name = "${var.name}-public" }
}
resource "aws_subnet" "public" {
provider = "${var.aws_provider}"
count = "${length(split(",", var.public_subnets))}"
vpc_id = "${aws_vpc.module.id}"
cidr_block = "${element(split(",", var.public_subnets), count.index)}"
availability_zone = "${element(split(",", var.az_names), count.index)}"
map_public_ip_on_launch = true
tags { Name = "${var.name}-public" }
}
resource "aws_route_table_association" "public" {
provider = "${var.aws_provider}"
count = "${length(split(",", var.public_subnets))}"
subnet_id = "${element(aws_subnet.public.*.id, count.index)}"
route_table_id = "${aws_route_table.public.id}"
}
resource "aws_instance" "nat" {
provider = "${var.aws_provider}"
count = "${length(split(",", var.private_subnets))}"
ami = "${var.nat_ami}"
instance_type = "${var.nat_instance_type}"
source_dest_check = false
subnet_id = "${element(aws_subnet.public.*.id, count.index)}"
security_groups = ["${split(",", var.security_groups)}"]
tags {
Name = "${var.name}-#{aws_subnet.public.*.availability_zone, count.index}-nat"
}
}
resource "aws_route_table" "private" {
provider = "${var.aws_provider}"
count = "${length(split(",", var.private_subnets))}"
vpc_id = "${aws_vpc.module.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${element(aws_instance.nat.*.id, count.index)}"
}
tags { Name = "${var.name}-private" }
}
resource "aws_subnet" "private" {
provider = "${var.aws_provider}"
count = "${length(split(",", var.private_subnets))}"
vpc_id = "${aws_vpc.module.id}"
cidr_block = "${element(split(",", var.private_subnets), count.index)}"
availability_zone = "${element(split(",", var.az_names), count.index)}"
tags { Name = "${var.name}-private" }
}
resource "aws_route_table_association" "private" {
provider = "${var.aws_provider}"
count = "${length(split(",", var.private_subnets))}"
subnet_id = "${element(aws_subnet.private.*.id, count.index)}"
route_table_id = "${aws_route_table.private.id}"
}
variable "aws_provider" { }
variable "name" { }
variable "cidr" { }
variable "public_subnets" { }
variable "private_subnets" { }
variable "az_names" { }
variable "nat_instance_type" { }
variable "nat_ami" { }
~  workspace  infrastructure  terraform  master +  $  terraform plan -var-file aws-creds.tfvars
There are warnings and/or errors related to your configuration. Please
fix these before continuing.
Errors:
* 1 error(s) occurred:
* module vpc.root: 10 error(s) occurred:
* resource 'aws_instance.nat' config: unknown variable referenced: 'security_groups'. define it with 'variable' blocks
* aws_subnet.public: resource depends on non-configured provider '${var.aws_provider}'
* aws_subnet.private: resource depends on non-configured provider '${var.aws_provider}'
* aws_route_table.public: resource depends on non-configured provider '${var.aws_provider}'
* aws_internet_gateway.module: resource depends on non-configured provider '${var.aws_provider}'
* aws_route_table_association.public: resource depends on non-configured provider '${var.aws_provider}'
* aws_instance.nat: resource depends on non-configured provider '${var.aws_provider}'
* aws_route_table.private: resource depends on non-configured provider '${var.aws_provider}'
* aws_route_table_association.private: resource depends on non-configured provider '${var.aws_provider}'
* aws_vpc.module: resource depends on non-configured provider '${var.aws_provider}'
variable "access_key" { }
variable "secret_key" { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment