Add private cidr
This commit is contained in:
parent
a5f6e7bb17
commit
c2aa4919bd
3 changed files with 33 additions and 0 deletions
utils/private-cidr
15
utils/private-cidr/cidr.tf
Normal file
15
utils/private-cidr/cidr.tf
Normal file
|
@ -0,0 +1,15 @@
|
|||
resource "random_integer" "upper_mid_byte" {
|
||||
min = 18
|
||||
max = 31
|
||||
}
|
||||
resource "random_integer" "lower_mid_byte" {
|
||||
min = 10
|
||||
max = 254
|
||||
}
|
||||
locals {
|
||||
// Generate a subnet
|
||||
subnet = "172.${random_integer.upper_mid_byte.result}.${random_integer.lower_mid_byte.result}.0/24"
|
||||
// Calculate the gateway from the subnet
|
||||
gateway = cidrhost(local.subnet, 1)
|
||||
}
|
||||
|
6
utils/private-cidr/outputs.tf
Normal file
6
utils/private-cidr/outputs.tf
Normal file
|
@ -0,0 +1,6 @@
|
|||
output "subnet" {
|
||||
value = local.subnet
|
||||
}
|
||||
output "gateway" {
|
||||
value = local.gateway
|
||||
}
|
12
utils/private-cidr/terraform.tf
Normal file
12
utils/private-cidr/terraform.tf
Normal file
|
@ -0,0 +1,12 @@
|
|||
terraform {
|
||||
required_version = "~> 1.6"
|
||||
|
||||
required_providers {
|
||||
random = {
|
||||
source = "hashicorp/random"
|
||||
version = "~> 3.5"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in a new issue