From 63822ff2c99a02499b626d678db9f8f9524aecd5 Mon Sep 17 00:00:00 2001 From: John Ricords <122303445+johnricords@users.noreply.github.com> Date: Tue, 31 Oct 2023 11:44:48 -0400 Subject: [PATCH] tests 1/n added --- main.tf | 12 +++---- outputs.tf | 12 ++++++- tests/create_all/main.tf | 65 ++++++++++++++++++++++++++++++------- tests/create_all/outputs.tf | 8 +++++ variables.tf | 26 ++++++++------- 5 files changed, 93 insertions(+), 30 deletions(-) create mode 100644 tests/create_all/outputs.tf diff --git a/main.tf b/main.tf index 0a645c2..e877fb1 100644 --- a/main.tf +++ b/main.tf @@ -15,7 +15,7 @@ resource "aws_vpc_ipam" "this" { # #plural, and nestable to 10 deep resource "aws_vpc_ipam_pool" "this" { - for_each = { for index, pool in coalesce(var.vpc_ipam.pool, []) : index => pool } + for_each = { for pool in coalesce(var.vpc_ipam.pools, []) : pool.name => pool } address_family = each.value.address_family #expects lowercase (need conditional) @@ -36,10 +36,10 @@ resource "aws_vpc_ipam_pool" "this" { } -#can be plural, but likely not -#provisions a CIDR from an IPAM pool +#can be plural, but likely not, provisions a CIDR from an IPAM pool +#netmask conflisks with cidr and for_each statement resource "aws_vpc_ipam_pool_cidr" "this" { - for_each = { for cidr in coalesce(var.vpc_ipam.pool_cidr, []) : cidr.name => cidr } + for_each = { for cidr in coalesce(var.vpc_ipam.pool_cidrs, []) : cidr.cidr => cidr } cidr = each.value.cidr @@ -53,7 +53,7 @@ resource "aws_vpc_ipam_pool_cidr" "this" { #plural, reserves a CIDR from IPAM pool, preventing usage by IPAM resource "aws_vpc_ipam_pool_cidr_allocation" "this" { - for_each = { for allocation in coalesce(var.vpc_ipam.pool_cidr_allocation, []) : allocation.name => allocation } + for_each = { for allocation in coalesce(var.vpc_ipam.pool_cidr_allocations, []) : allocation.cidr => allocation } cidr = each.value.cidr description = each.value.description @@ -73,7 +73,7 @@ resource "aws_vpc_ipam_preview_next_cidr" "this" { #plural, multiple disconnected networks resource "aws_vpc_ipam_scope" "this" { - for_each = { for scope in coalesce(var.vpc_ipam.scope, []) : scope.name => scope } + for_each = { for scope in coalesce(var.vpc_ipam.scopes, []) : scope.name => scope } ipam_id = each.value.ipam_id description = each.value.description diff --git a/outputs.tf b/outputs.tf index 01f9d2d..02f8b24 100644 --- a/outputs.tf +++ b/outputs.tf @@ -4,6 +4,16 @@ output "ipam_out" { } output "pool_out" { - description = "Object of all AWS VPC IPAM" + description = "map of objects" value = aws_vpc_ipam_pool.this } + +# output "pool_out2" { +# description = "List of objects" +# value = values(aws_vpc_ipam_pool.this)[*] +# } + +# output "pool_out3" { +# description = "List of strings" +# value = [for pool in aws_vpc_ipam_pool.this : pool.id] +# } diff --git a/tests/create_all/main.tf b/tests/create_all/main.tf index ef006fa..290d0b1 100644 --- a/tests/create_all/main.tf +++ b/tests/create_all/main.tf @@ -20,20 +20,55 @@ module "create_ipam" { } } +module "scope" { + source = "../.." + + vpc_ipam = { + scopes = [ + { + name = "high_container" + ipam_id = module.create_ipam.ipam_out[0].private_default_scope_id + description = random_string.this.result + tags = { + name = "broker_managed" + } + }, + ] + } +} + module "create_pool" { source = "../.." vpc_ipam = { - pool = [ + pools = [ { + name = "pool_of_cidrs" address_family = "ipv4" allocation_default_netmask_length = "16" allocation_min_netmask_length = "16" allocation_max_netmask_length = "16" description = random_string.this.result locale = "us-east-1" - ipam_scope_id = module.create_ipam[0].ipam_out.private_default_scope_id + tags = { + name = "broker_managed" + } + ipam_scope_id = module.create_ipam.ipam_out[0].private_default_scope_id + #can also be output of vpc_ipam.scope, need to tweak to check @ implementation + }, + { + name = "pool_of_cidrs2" + address_family = "ipv4" + allocation_default_netmask_length = "16" + allocation_min_netmask_length = "16" + allocation_max_netmask_length = "16" + description = random_string.this.result + locale = "us-east-1" + tags = { + name = "broker_managed" + } + ipam_scope_id = module.create_ipam.ipam_out[0].private_default_scope_id #can also be output of vpc_ipam.scope, need to tweak to check @ implementation }, ] @@ -44,10 +79,10 @@ module "provision_cidr" { source = "../.." vpc_ipam = { - pool_cidr = [ + pool_cidrs = [ { cidr = "10.0.0.0/16" - ipam_pool_id = module.create_pool[0].pool_out.id + ipam_pool_id = module.create_pool.pool_out["pool_of_cidrs"].id }, ] } @@ -57,20 +92,28 @@ module "reserve_cidr" { source = "../.." vpc_ipam = { - pool_cidr_allocation = [ + pool_cidr_allocations = [ { cidr = "10.2.0.0/16" - ipam_pool_id = module.create_pool[0].pool_out.id + ipam_pool_id = module.create_pool.pool_out["pool_of_cidrs"].id + # ipam_pool_id = module.create_pool.pool_out3[0] }, ] } } +module "preview_cidr" { + source = "../.." -# preview_next_cidr = { - -# } -# scope = { + vpc_ipam = { + preview_next_cidr = { + disallowed_cidrs = [ + "10.4.0.0/16", + "10.5.0.0/16" + ] + ipam_pool_id = module.create_pool.pool_out["pool_of_cidrs"].id -# } + } + } +} diff --git a/tests/create_all/outputs.tf b/tests/create_all/outputs.tf new file mode 100644 index 0000000..20bd62f --- /dev/null +++ b/tests/create_all/outputs.tf @@ -0,0 +1,8 @@ +output "ipam" { + value = module.create_ipam +} + + +output "pool" { + value = module.create_pool +} diff --git a/variables.tf b/variables.tf index f233316..094e521 100644 --- a/variables.tf +++ b/variables.tf @@ -3,13 +3,14 @@ variable "vpc_ipam" { type = object({ ipam = optional(object({ operating_regions = list(object({ - region_name = optional(string) #required + region_name = string })) tags = optional(map(string)) cascade = optional(bool) description = optional(string) })) - pool = optional(list(object({ + pools = optional(list(object({ + name = optional(string) address_family = optional(string) allocation_default_netmask_length = optional(number) allocation_max_netmask_length = optional(number) @@ -25,26 +26,27 @@ variable "vpc_ipam" { source_ipam_pool_id = optional(string) tags = optional(map(string)) }))) - pool_cidr = optional(list(object({ + pool_cidrs = optional(list(object({ cidr = optional(string) cidr_authorization_context_message = optional(string) cidr_authorization_context_signature = optional(string) - ipam_pool_id = optional(string) #required + ipam_pool_id = string netmask_length = optional(number) }))) - pool_cidr_allocation = optional(list(object({ + pool_cidr_allocations = optional(list(object({ cidr = optional(string) description = optional(string) disallowed_cidrs = optional(list(string)) - ipam_pool_id = optional(string) #required + ipam_pool_id = string netmask_length = optional(number) }))) preview_next_cidr = optional(object({ disallowed_cidrs = optional(list(string)) - ipam_pool_id = optional(string) #required + ipam_pool_id = string netmask_length = optional(number) })) - scope = optional(list(object({ + scopes = optional(list(object({ + name = optional(string) ipam_id = optional(string) description = optional(string) tags = optional(map(string)) @@ -56,20 +58,20 @@ variable "vpc_ipam" { }] } - pool = [{ + pools = [{ }] - pool_cidr = [{ + pool_cidrs = [{ }] - pool_cidr_allocation = [{ + pool_cidr_allocations = [{ }] preview_next_cidr = { } - scope = [{ + scopes = [{ }] }