Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d250c09b91 | ||
|
|
68205e8f20 | ||
|
|
a7ec6de10d |
No files matched your search
@@ -4,6 +4,9 @@ repos:
|
|||||||
hooks:
|
hooks:
|
||||||
- id: terraform_fmt
|
- id: terraform_fmt
|
||||||
- id: terraform_validate
|
- id: terraform_validate
|
||||||
|
args:
|
||||||
|
- --hook-config=--parallelism-limit=1
|
||||||
|
- --hook-config=--retry-once-with-cleanup=true
|
||||||
- id: terraform_tflint
|
- id: terraform_tflint
|
||||||
args:
|
args:
|
||||||
- '--args=--recursive'
|
- '--args=--recursive'
|
||||||
@@ -15,6 +18,7 @@ repos:
|
|||||||
- id: terraform_checkov
|
- id: terraform_checkov
|
||||||
args:
|
args:
|
||||||
- '--args=--quiet'
|
- '--args=--quiet'
|
||||||
|
- '--args=--compact'
|
||||||
- '--args=--skip-check CKV_AWS_229' # Ensure no NACL allow ingress from 0.0.0.0:0 to port 21
|
- '--args=--skip-check CKV_AWS_229' # Ensure no NACL allow ingress from 0.0.0.0:0 to port 21
|
||||||
- '--args=--skip-check CKV_AWS_230' # Ensure no NACL allow ingress from 0.0.0.0:0 to port 20
|
- '--args=--skip-check CKV_AWS_230' # Ensure no NACL allow ingress from 0.0.0.0:0 to port 20
|
||||||
- '--args=--skip-check CKV_AWS_231' # Ensure no NACL allow ingress from 0.0.0.0:0 to port 3389
|
- '--args=--skip-check CKV_AWS_231' # Ensure no NACL allow ingress from 0.0.0.0:0 to port 3389
|
||||||
|
|||||||
@@ -95,11 +95,8 @@ No modules.
|
|||||||
|
|
||||||
| Name | Description | Type | Default | Required |
|
| Name | Description | Type | Default | Required |
|
||||||
|------|-------------|------|---------|:--------:|
|
|------|-------------|------|---------|:--------:|
|
||||||
| <a name="input_availability_zones"></a> [availability\_zones](#input\_availability\_zones) | Target availability zones. | `list(string)` | `null` | no |
|
| <a name="input_config_file"></a> [config\_file](#input\_config\_file) | Network configuration file. | `string` | `null` | no |
|
||||||
| <a name="input_cidr_block"></a> [cidr\_block](#input\_cidr\_block) | The IPv4 CIDR block for the VPC. | `string` | `null` | no |
|
| <a name="input_config_template"></a> [config\_template](#input\_config\_template) | value | `string` | `"default"` | no |
|
||||||
| <a name="input_network_acl_disabled"></a> [network\_acl\_disabled](#input\_network\_acl\_disabled) | If disabled, default Network ACLs allow all inbound and outbound protocols. | `bool` | `true` | no |
|
|
||||||
| <a name="input_prefix_name"></a> [prefix\_name](#input\_prefix\_name) | Value used to prefix resources name. | `string` | `null` | no |
|
|
||||||
| <a name="input_subnet_groups"></a> [subnet\_groups](#input\_subnet\_groups) | One subnet in each availablity zone is created per subnet group. | <pre>map(object({<br> cidr_block = string<br> default_route = optional(string, "")<br> }))</pre> | `null` | no |
|
|
||||||
|
|
||||||
## Outputs
|
## Outputs
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
cidr_block: 10.1.0.0/16
|
||||||
|
# max_azs: 2
|
||||||
|
nacl_disabled: true
|
||||||
|
|
||||||
|
subnet_groups:
|
||||||
|
public:
|
||||||
|
default_route: igw
|
||||||
|
private:
|
||||||
|
default_route: ngw/public
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
cidr_block: 10.2.0.0/16
|
||||||
|
# max_azs: 2
|
||||||
|
nacl_disabled: true
|
||||||
|
|
||||||
|
subnet_groups:
|
||||||
|
public:
|
||||||
|
default_route: igw
|
||||||
|
tags:
|
||||||
|
kubernetes.io/role/elb: 1
|
||||||
|
private:
|
||||||
|
default_route: ngw/public
|
||||||
|
tags:
|
||||||
|
kubernetes.io/role/internal-elb: 1
|
||||||
@@ -5,24 +5,24 @@ data "aws_availability_zones" "current" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
locals {
|
locals {
|
||||||
# Configure defaults when attributes are not defined
|
config_file = var.config_file == null ? "${path.module}/config/${var.config_template}.yaml" : var.config_file
|
||||||
prefix_name = var.prefix_name != null ? var.prefix_name : basename(path.cwd)
|
config = yamldecode(file(local.config_file))
|
||||||
cidr_block = var.cidr_block != null ? var.cidr_block : "10.0.0.0/16"
|
|
||||||
azs = var.availability_zones != null ? var.availability_zones : slice(data.aws_availability_zones.current.names, 0, 2)
|
|
||||||
|
|
||||||
nets = var.subnet_groups != null ? var.subnet_groups : {
|
# Configure defaults when attributes are not defined
|
||||||
public = {
|
prefix_name = try(local.config.prefix_name, basename(path.cwd))
|
||||||
cidr_block = cidrsubnet(local.cidr_block, 1, 0)
|
cidr_block = try(local.config.cidr_block, "10.0.0.0/16")
|
||||||
default_route = "igw"
|
azs_count = min(try(local.config.max_azs, 2), length(data.aws_availability_zones.current.names))
|
||||||
}
|
azs = try(local.config.availability_zones, slice(data.aws_availability_zones.current.names, 0, local.azs_count))
|
||||||
private = {
|
nets = try(local.config.subnet_groups, {})
|
||||||
cidr_block = cidrsubnet(local.cidr_block, 1, 1)
|
nacl_disabled = try(local.config.nacl_disabled, false)
|
||||||
default_route = "ngw/public"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# subnets
|
# subnets
|
||||||
subnet_newbits = ceil(log(length(local.azs), 2))
|
nets_newbits = ceil(log(length(local.nets), 2))
|
||||||
|
azs_newbits = ceil(log(length(local.azs), 2))
|
||||||
|
|
||||||
|
net_cidr_blocks = {
|
||||||
|
for i, v in keys(local.nets) : v => try(local.nets[v].cidr_block, cidrsubnet(local.cidr_block, local.nets_newbits, i))
|
||||||
|
}
|
||||||
|
|
||||||
subnets_attributes = merge(flatten([
|
subnets_attributes = merge(flatten([
|
||||||
for k, v in local.nets : [
|
for k, v in local.nets : [
|
||||||
@@ -30,18 +30,19 @@ locals {
|
|||||||
join("-", [k, z]) = {
|
join("-", [k, z]) = {
|
||||||
availability_zone = z
|
availability_zone = z
|
||||||
subnet_group = k
|
subnet_group = k
|
||||||
default_route = v.default_route
|
default_route = try(v.default_route, "")
|
||||||
cidr_block = cidrsubnet(v.cidr_block, local.subnet_newbits, i)
|
cidr_block = cidrsubnet(local.net_cidr_blocks[k], local.azs_newbits, i)
|
||||||
|
tags = try(v.tags, { test : "none" })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
])...)
|
])...)
|
||||||
|
|
||||||
# internet gateway
|
# internet gateway
|
||||||
igw_enabled = contains([for g in local.nets : g.default_route == "igw"], true)
|
igw_enabled = contains([for g in local.nets : try(g.default_route == "igw", false)], true)
|
||||||
|
|
||||||
# NAT gateways
|
# NAT gateways
|
||||||
nat_subnet_groups = distinct([for k, v in local.nets : basename(v.default_route) if startswith(v.default_route, "ngw/")])
|
nat_subnet_groups = distinct([for g in local.nets : basename(g.default_route) if try(startswith(g.default_route, "ngw/"), false)])
|
||||||
nat_gateways = toset(flatten([
|
nat_gateways = toset(flatten([
|
||||||
for k in local.nat_subnet_groups : [
|
for k in local.nat_subnet_groups : [
|
||||||
for i, z in local.azs : join("-", [k, z])
|
for i, z in local.azs : join("-", [k, z])
|
||||||
|
|||||||
+2
-2
@@ -6,9 +6,9 @@ resource "aws_subnet" "self" {
|
|||||||
cidr_block = each.value.cidr_block
|
cidr_block = each.value.cidr_block
|
||||||
availability_zone = each.value.availability_zone
|
availability_zone = each.value.availability_zone
|
||||||
|
|
||||||
tags = {
|
tags = merge(each.value.tags, {
|
||||||
Name = join("-", compact([local.prefix_name, each.key]))
|
Name = join("-", compact([local.prefix_name, each.key]))
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_eip" "self" {
|
resource "aws_eip" "self" {
|
||||||
|
|||||||
+9
-25
@@ -1,34 +1,18 @@
|
|||||||
# variables.tf
|
# variables.tf
|
||||||
|
|
||||||
variable "prefix_name" {
|
variable "config_file" {
|
||||||
description = "Value used to prefix resources name."
|
description = "Network configuration file."
|
||||||
type = string
|
type = string
|
||||||
default = null
|
default = null
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "cidr_block" {
|
variable "config_template" {
|
||||||
description = "The IPv4 CIDR block for the VPC."
|
description = "value"
|
||||||
type = string
|
type = string
|
||||||
default = null
|
default = "default"
|
||||||
}
|
|
||||||
|
|
||||||
variable "availability_zones" {
|
validation {
|
||||||
description = "Target availability zones."
|
condition = contains(["default", "eks"], var.config_template)
|
||||||
type = list(string)
|
error_message = "config_template must be one of 'default' 'eks'"
|
||||||
default = null
|
}
|
||||||
}
|
|
||||||
|
|
||||||
variable "subnet_groups" {
|
|
||||||
description = "One subnet in each availablity zone is created per subnet group."
|
|
||||||
type = map(object({
|
|
||||||
cidr_block = string
|
|
||||||
default_route = optional(string, "")
|
|
||||||
}))
|
|
||||||
default = null
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "network_acl_disabled" {
|
|
||||||
description = "If disabled, default Network ACLs allow all inbound and outbound protocols."
|
|
||||||
type = bool
|
|
||||||
default = true
|
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ resource "aws_default_network_acl" "self" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_network_acl_rule" "all_ingress" {
|
resource "aws_network_acl_rule" "all_ingress" {
|
||||||
count = var.network_acl_disabled == true ? 1 : 0
|
count = local.nacl_disabled ? 1 : 0
|
||||||
network_acl_id = aws_default_network_acl.self.id
|
network_acl_id = aws_default_network_acl.self.id
|
||||||
rule_number = 100
|
rule_number = 100
|
||||||
rule_action = "allow"
|
rule_action = "allow"
|
||||||
@@ -42,7 +42,7 @@ resource "aws_network_acl_rule" "all_ingress" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_network_acl_rule" "all_egress" {
|
resource "aws_network_acl_rule" "all_egress" {
|
||||||
count = var.network_acl_disabled ? 1 : 0
|
count = local.nacl_disabled ? 1 : 0
|
||||||
network_acl_id = aws_default_network_acl.self.id
|
network_acl_id = aws_default_network_acl.self.id
|
||||||
rule_number = 100
|
rule_number = 100
|
||||||
rule_action = "allow"
|
rule_action = "allow"
|
||||||
|
|||||||
Reference in new issue
Block a user