Skip to content

Commit

Permalink
Added public and private suffixes accordingly to subnet types (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
const-bon authored Aug 16, 2017
1 parent f490e35 commit 21f9024
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,29 @@ you plan to use new (separate) VPC.
* `vpc_default_route_table_id`: A default route table for public subnets. Provides access to Internet. If not set here - will be created.

```
module "tf_subnets" {
module "subnets" {
source = "git::https://github.com/cloudposse/tf_subnets.git?ref=master"
availability_zones = "${var.availability_zones}"
namespace = "${var.namespace}"
name = "${var.name}"
stage = "${var.stage}"
region = "${var.region}"
vpc_id = "${var.vpc_id}"
igw_id = "${var.igw_id}"
availability_zones = "${var.availability_zones}"
namespace = "${var.namespace}"
name = "${var.name}"
stage = "${var.stage}"
region = "${var.region}"
vpc_id = "${var.vpc_id}"
igw_id = "${var.igw_id}"
vpc_default_route_table_id = "${var.vpc_default_route_table_id}"
}
```

## Variables

| Name | Default | Description | Required |
|:----------------------------:|:--------------:|:--------------------------------------------------------:|:--------:|
| namespace | `` | Namespace (e.g. `cp` or `cloudposse`) | Yes |
| stage | `` | Stage (e.g. `prod`, `dev`, `staging`) | Yes |
| name | `` | Name (e.g. `bastion` or `db`) | Yes |
| region | `` | AWS Region where module should operate (e.g. `us-east-1`)| Yes |
| vpc_id | `` | The VPC ID where subnets will be created (e.g. `vpc-aceb2723`) | Yes |
| igw_id | `` | The Internet Gateway ID public route table will point to (e.g. `igw-9c26a123`) | Yes |
| vpc_default_route_table_id | `` | The scheduling expression. (e.g. cron(0 20 * * ? *) or rate(5 minutes) | No |
| availability_zones | [] | The scheduling expression. (e.g. cron(0 20 * * ? *) or rate(5 minutes) | Yes |
7 changes: 0 additions & 7 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ provider "aws" {
region = "${var.region}"
}

module "tf_label" {
source = "git::https://github.com/cloudposse/tf_label.git?ref=tags/0.1.0"
namespace = "${var.namespace}"
stage = "${var.stage}"
name = "${var.name}"
}

# Get object aws_vpc by vpc_id
data "aws_vpc" "default" {
id = "${var.vpc_id}"
Expand Down
11 changes: 9 additions & 2 deletions private.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
module "private_label" {
source = "git::https://github.com/cloudposse/tf_label.git?ref=tags/0.1.0"
namespace = "${var.namespace}"
stage = "${var.stage}"
name = "${var.name}-private"
}

resource "aws_subnet" "private" {
count = "${length(var.availability_zones)}"

vpc_id = "${data.aws_vpc.default.id}"
availability_zone = "${element(var.availability_zones, count.index)}"
cidr_block = "${cidrsubnet(data.aws_vpc.default.cidr_block, length(var.availability_zones), length(var.availability_zones) + count.index)}"
tags = "${module.tf_label.tags}"
tags = "${module.private_label.tags}"
}

resource "aws_route_table" "private" {
Expand All @@ -16,7 +23,7 @@ resource "aws_route_table" "private" {
nat_gateway_id = "${element(aws_nat_gateway.default.*.id, count.index)}"
}

tags = "${module.tf_label.tags}"
tags = "${module.private_label.tags}"
}

resource "aws_route_table_association" "private" {
Expand Down
11 changes: 9 additions & 2 deletions public.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
module "public_label" {
source = "git::https://github.com/cloudposse/tf_label.git?ref=tags/0.1.0"
namespace = "${var.namespace}"
stage = "${var.stage}"
name = "${var.name}-public"
}

resource "aws_subnet" "public" {
count = "${length(var.availability_zones)}"

vpc_id = "${data.aws_vpc.default.id}"
availability_zone = "${element(var.availability_zones, count.index)}"
cidr_block = "${cidrsubnet(data.aws_vpc.default.cidr_block, length(var.availability_zones), count.index)}"

tags = "${module.tf_label.tags}"
tags = "${module.public_label.tags}"
}

resource "aws_route_table" "public" {
Expand All @@ -16,7 +23,7 @@ resource "aws_route_table" "public" {
cidr_block = "0.0.0.0/0"
gateway_id = "${var.igw_id}"
}
tags = "${module.tf_label.tags}"
tags = "${module.public_label.tags}"
}

resource "aws_route_table_association" "public" {
Expand Down

0 comments on commit 21f9024

Please sign in to comment.