networking: calculate subnet cidr from vcn

add a missing vcn attribute
add subnet cidr outputs
remove a placeholder comment
This commit is contained in:
bdeshi 2024-05-28 00:32:52 +06:00
parent a0e732cda2
commit 9377d43630
Signed by: bdeshi
GPG Key ID: 410D03DA9A3468E0
2 changed files with 28 additions and 16 deletions

View File

@ -1,10 +1,11 @@
resource "oci_core_vcn" "vcn" {
compartment_id = oci_identity_compartment.compartment.id
cidr_block = var.vcn_cidr
is_ipv6enabled = var.enable_ipv6
display_name = join("", [var.prefix, "vcn"])
dns_label = local.vcn_dns_label
freeform_tags = local.freeform_tags
compartment_id = oci_identity_compartment.compartment.id
cidr_block = var.vcn_cidr
is_ipv6enabled = var.enable_ipv6
is_oracle_gua_allocation_enabled = true
display_name = join("", [var.prefix, "vcn"])
dns_label = local.vcn_dns_label
freeform_tags = local.freeform_tags
}
resource "oci_core_internet_gateway" "igw" {
@ -48,7 +49,6 @@ resource "oci_core_default_security_list" "default" {
}
}
# oci_core_network_security_group
resource "oci_core_network_security_group" "default" {
compartment_id = oci_identity_compartment.compartment.id
vcn_id = oci_core_vcn.vcn.id
@ -77,13 +77,15 @@ resource "oci_core_network_security_group_security_rule" "default" {
protocol = try(each.value.protocol, "all")
}
resource "oci_core_subnet" "public_subnet" {
compartment_id = oci_identity_compartment.compartment.id
vcn_id = oci_core_vcn.vcn.id
cidr_block = var.vcn_cidr
display_name = "public"
dns_label = "public"
route_table_id = oci_core_default_route_table.default.id
security_list_ids = [oci_core_default_security_list.default.id]
freeform_tags = merge(local.freeform_tags, { type = "public" })
resource "oci_core_subnet" "public" {
compartment_id = oci_identity_compartment.compartment.id
vcn_id = oci_core_vcn.vcn.id
cidr_block = cidrsubnets(oci_core_vcn.vcn.cidr_blocks[0], 8)[0]
ipv6cidr_block = var.enable_ipv6 ? cidrsubnets(oci_core_vcn.vcn.ipv6cidr_blocks[0], 8)[0] : null
display_name = "public"
dns_label = "public"
availability_domain = null
route_table_id = oci_core_default_route_table.default.id
security_list_ids = [oci_core_default_security_list.default.id]
freeform_tags = merge(local.freeform_tags, { type = "public" })
}

View File

@ -72,6 +72,16 @@ output "vcn_ipv6_cidr_private_blocks" {
value = oci_core_vcn.vcn.ipv6private_cidr_blocks
}
output "subnet_cidr_block" {
description = "The CIDR block for the subnet"
value = oci_core_subnet.public.cidr_block
}
output "subnet_ipv6_cidr_block" {
description = "The IPv6 CIDR block for the subnet"
value = oci_core_subnet.public.ipv6cidr_block
}
output "ssh_key_public" {
description = "The public SSH key for the compute instances"
value = local.compute_ssh_key