feat: switch to yaml config file for settings

This commit is contained in:
David FILLON committed 2024-05-03 18:30:20 +02:00
1 parent 68205e8f20
commit d250c09b91
6 files changed
+30 -14

No files matched your search

+2 -1
View File
@@ -95,7 +95,8 @@ No modules.
| Name | Description | Type | Default | Required | | Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:| |------|-------------|------|---------|:--------:|
| <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_config_file"></a> [config\_file](#input\_config\_file) | Network configuration file. | `string` | `null` | no |
| <a name="input_config_template"></a> [config\_template](#input\_config\_template) | value | `string` | `"default"` | no |
## Outputs ## Outputs
+3 -2
View File
@@ -1,8 +1,9 @@
cidr_block: 10.1.0.0/16 cidr_block: 10.1.0.0/16
max_azs: 2 # max_azs: 2
nacl_disabled: true
subnet_groups: subnet_groups:
public: public:
default_route: igw default_route: igw
private: private:
default_route: nat/public default_route: ngw/public
+4 -3
View File
@@ -1,6 +1,7 @@
cidr_block: 10.0.0.0/16 cidr_block: 10.2.0.0/16
max_azs: 2 # max_azs: 2
nacl_disabled: true
subnet_groups: subnet_groups:
public: public:
@@ -8,6 +9,6 @@ subnet_groups:
tags: tags:
kubernetes.io/role/elb: 1 kubernetes.io/role/elb: 1
private: private:
default_route: nat/public default_route: ngw/public
tags: tags:
kubernetes.io/role/internal-elb: 1 kubernetes.io/role/internal-elb: 1
+4 -2
View File
@@ -5,14 +5,16 @@ data "aws_availability_zones" "current" {
} }
locals { locals {
config_file = "${path.module}/config/default.yaml" config_file = var.config_file == null ? "${path.module}/config/${var.config_template}.yaml" : var.config_file
config = yamldecode(file(local.config_file)) config = yamldecode(file(local.config_file))
# Configure defaults when attributes are not defined # Configure defaults when attributes are not defined
prefix_name = try(local.config.prefix_name, basename(path.cwd)) prefix_name = try(local.config.prefix_name, basename(path.cwd))
cidr_block = try(local.config.cidr_block, "10.0.0.0/16") cidr_block = try(local.config.cidr_block, "10.0.0.0/16")
azs_count = min(try(local.config.max_azs, 5), length(data.aws_availability_zones.current.names)) 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)) azs = try(local.config.availability_zones, slice(data.aws_availability_zones.current.names, 0, local.azs_count))
nets = try(local.config.subnet_groups, {}) nets = try(local.config.subnet_groups, {})
nacl_disabled = try(local.config.nacl_disabled, false)
# subnets # subnets
nets_newbits = ceil(log(length(local.nets), 2)) nets_newbits = ceil(log(length(local.nets), 2))
+15 -4
View File
@@ -1,7 +1,18 @@
# variables.tf # variables.tf
variable "network_acl_disabled" { variable "config_file" {
description = "If disabled, default Network ACLs allow all inbound and outbound protocols." description = "Network configuration file."
type = bool type = string
default = true default = null
}
variable "config_template" {
description = "value"
type = string
default = "default"
validation {
condition = contains(["default", "eks"], var.config_template)
error_message = "config_template must be one of 'default' 'eks'"
}
} }
+2 -2
View File
@@ -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"