feat: config from yaml file
This commit is contained in:
1 parent
a7ec6de10d
commit
68205e8f20
6 files changed
+41
-52
No files matched your search
@@ -95,11 +95,7 @@ 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_cidr_block"></a> [cidr\_block](#input\_cidr\_block) | The IPv4 CIDR block for the VPC. | `string` | `null` | 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_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,8 @@
|
|||||||
|
cidr_block: 10.1.0.0/16
|
||||||
|
max_azs: 2
|
||||||
|
|
||||||
|
subnet_groups:
|
||||||
|
public:
|
||||||
|
default_route: igw
|
||||||
|
private:
|
||||||
|
default_route: nat/public
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
cidr_block: 10.0.0.0/16
|
||||||
|
max_azs: 2
|
||||||
|
|
||||||
|
subnet_groups:
|
||||||
|
public:
|
||||||
|
default_route: igw
|
||||||
|
tags:
|
||||||
|
kubernetes.io/role/elb: 1
|
||||||
|
private:
|
||||||
|
default_route: nat/public
|
||||||
|
tags:
|
||||||
|
kubernetes.io/role/internal-elb: 1
|
||||||
@@ -5,24 +5,22 @@ data "aws_availability_zones" "current" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
locals {
|
locals {
|
||||||
|
config_file = "${path.module}/config/default.yaml"
|
||||||
|
config = yamldecode(file(local.config_file))
|
||||||
# Configure defaults when attributes are not defined
|
# Configure defaults when attributes are not defined
|
||||||
prefix_name = var.prefix_name != null ? var.prefix_name : basename(path.cwd)
|
prefix_name = try(local.config.prefix_name, basename(path.cwd))
|
||||||
cidr_block = var.cidr_block != null ? var.cidr_block : "10.0.0.0/16"
|
cidr_block = try(local.config.cidr_block, "10.0.0.0/16")
|
||||||
azs = var.availability_zones != null ? var.availability_zones : slice(data.aws_availability_zones.current.names, 0, 2)
|
azs_count = min(try(local.config.max_azs, 5), length(data.aws_availability_zones.current.names))
|
||||||
|
azs = try(local.config.availability_zones, slice(data.aws_availability_zones.current.names, 0, local.azs_count))
|
||||||
nets = var.subnet_groups != null ? var.subnet_groups : {
|
nets = try(local.config.subnet_groups, {})
|
||||||
public = {
|
|
||||||
cidr_block = cidrsubnet(local.cidr_block, 1, 0)
|
|
||||||
default_route = "igw"
|
|
||||||
}
|
|
||||||
private = {
|
|
||||||
cidr_block = cidrsubnet(local.cidr_block, 1, 1)
|
|
||||||
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 +28,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" {
|
||||||
|
|||||||
@@ -1,32 +1,5 @@
|
|||||||
# variables.tf
|
# variables.tf
|
||||||
|
|
||||||
variable "prefix_name" {
|
|
||||||
description = "Value used to prefix resources name."
|
|
||||||
type = string
|
|
||||||
default = null
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "cidr_block" {
|
|
||||||
description = "The IPv4 CIDR block for the VPC."
|
|
||||||
type = string
|
|
||||||
default = null
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "availability_zones" {
|
|
||||||
description = "Target availability zones."
|
|
||||||
type = list(string)
|
|
||||||
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" {
|
variable "network_acl_disabled" {
|
||||||
description = "If disabled, default Network ACLs allow all inbound and outbound protocols."
|
description = "If disabled, default Network ACLs allow all inbound and outbound protocols."
|
||||||
type = bool
|
type = bool
|
||||||
|
|||||||
Reference in new issue
Block a user