From f3c6fb35ea4ebc6772ca3be2a55b5d8453751f52 Mon Sep 17 00:00:00 2001 From: Sergei Ugdyzhekov Date: Sat, 18 Apr 2020 20:33:18 +0200 Subject: [PATCH] feat: Use user specified CIDR instead of calculated --- README.md | 15 +++++++-------- variables.tf | 12 +++--------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index b79e4c4..3886af8 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/variables.tf b/variables.tf index 0407df5..084fd3d 100644 --- a/variables.tf +++ b/variables.tf @@ -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." @@ -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)