Skip to content

Commit

Permalink
tests 1/n added
Browse files Browse the repository at this point in the history
  • Loading branch information
johnricords committed Oct 31, 2023
1 parent f1cdc46 commit 63822ff
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 30 deletions.
12 changes: 6 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 11 additions & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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]
# }
65 changes: 54 additions & 11 deletions tests/create_all/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
]
Expand All @@ -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
},
]
}
Expand All @@ -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

# }
}
}

}
8 changes: 8 additions & 0 deletions tests/create_all/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
output "ipam" {
value = module.create_ipam
}


output "pool" {
value = module.create_pool
}
26 changes: 14 additions & 12 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
Expand All @@ -56,20 +58,20 @@ variable "vpc_ipam" {

}]
}
pool = [{
pools = [{

}]
pool_cidr = [{
pool_cidrs = [{

}]

pool_cidr_allocation = [{
pool_cidr_allocations = [{

}]
preview_next_cidr = {

}
scope = [{
scopes = [{

}]
}
Expand Down

0 comments on commit 63822ff

Please sign in to comment.