Skip to content

Commit

Permalink
feat: Use user specified CIDR instead of calculated
Browse files Browse the repository at this point in the history
  • Loading branch information
sugdyzhekov committed Apr 18, 2020
1 parent fcdbf0b commit f3c6fb3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@ Terraform module to create network subnet with custom route tablea

Features:
* Assign route table to forward traffic through NAT or IGW e.g.
* Network calculation based on VPC CIDR

## Usage

Private subnet:
```
A private subnet:
```hcl
module "subnet" {
source = "github.com/jetbrains-infra/terraform-aws-subnet"
project = "FooBar"
project = "FooBar"
vpc_id = "${local.vpc_id}"
name = "DB"
name = "DB"
route_table = "${aws_route_table.intenert_access.id}"
}
```

All options with default values:
```
```hcl
module "subnet" {
source = "github.com/jetbrains-infra/terraform-aws-subnet"
project = "FooBar" // required
Expand All @@ -28,9 +27,9 @@ module "subnet" {
zone = "eu-west-1a"
type = "private"
group = "dbs"
shift = 0 // How many subnets were already taken from VPC cidr block
network_mask = 8 // means 256 IP
subnet_cidr = "10.0.0.0/24"
route_table = "${aws_route_table.intenert_access.id}"
}
```

## Outputs
Expand Down
12 changes: 3 additions & 9 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@ variable "group" {
description = "Group tag. You may specify it to define varous scopes for subnets of one type."
default = "common"
}
variable "shift" {
description = "How many subnets were already taken from VPC cidr block."
default = 0
}
variable "network_mask" {
description = "Network mask in bites. 2 for /24 e.g. Default is 2 (256 IPs for subnet in VPC with /22 CIDR)."
default = 2
variable "subnet_cidr" {
description = "Subnet CIDR."
}
variable "route_table" {
description = "Route table id."
Expand All @@ -38,8 +33,7 @@ locals {
route_table = var.route_table
vpc_id = var.vpc_id
vpc_cidr = data.aws_vpc.default.cidr_block
newbites = var.network_mask
subnet_cidr = cidrsubnet(local.vpc_cidr, local.newbites, var.shift) // var.shift because local.shift will not work
subnet_cidr = var.subnet_cidr
purpose = title(var.name)
name = "${local.purpose} ${var.type}"
type = lower(var.type)
Expand Down

0 comments on commit f3c6fb3

Please sign in to comment.