Skip to content

Commit

Permalink
add subnet attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Sungmin Lee authored and Sungmin Lee committed Oct 11, 2022
1 parent 46ca8e9 commit d6c0ed5
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 34 deletions.
57 changes: 43 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ vpcs = [
name = string
ipv4_cidr_block = string(cidr)
// Subnet declaration (Optional, List)
subnets = [
{
name = string
usage_type = "GEN" // GEN | LOADB
subnet_type = "PRIVATE" // PUBLIC | PRIVATE
// If usage_type is LOADB in the KR region, only PRIVATE is allowed.
zone = string(zone) // (PUB) KR-1 | KR-2 // (FIN) FKR-1 | FKR-2 // (GOV) KR | KRS
subnet = string(cidr)
network_acl = string // default | NetworkAclName,
// if set "default", then "default Network ACL" will be set.
}
]
// Deprecated
// Subnet declaration (Optional, List)
public_subnets = [
{
Expand Down Expand Up @@ -140,43 +155,51 @@ vpcs = [
name = "vpc-foo"
ipv4_cidr_block = "10.0.0.0/16"
public_subnets = [
subnets = [
{
name = "sbn-foo-public-1"
usage_type = "GEN"
subnet_type = "PUBLIC"
zone = "KR-1"
subnet = "10.0.1.0/24"
network_acl = "default"
},
{
name = "sbn-foo-public-2"
usage_type = "GEN"
subnet_type = "PUBLIC"
zone = "KR-2"
subnet = "10.0.2.0/24"
network_acl = "default"
}
]
private_subnets = [
},
{
name = "sbn-foo-private-1"
usage_type = "GEN"
subnet_type = "PRIVATE"
zone = "KR-1"
subnet = "10.0.3.0/24"
network_acl = "default"
},
{
name = "sbn-foo-private-2"
usage_type = "GEN"
subnet_type = "PRIVATE"
zone = "KR-2"
subnet = "10.0.4.0/24"
network_acl = "default"
}
]
loadbalancer_subnets = [
},
{
name = "sbn-foo-lb-1"
usage_type = "LOADB"
subnet_type = "PRIVATE"
zone = "KR-1"
subnet = "10.0.5.0/24"
network_acl = "nacl-foo-loadbalancer"
},
{
name = "sbn-foo-lb-2"
usage_type = "LOADB"
subnet_type = "PRIVATE"
zone = "KR-2"
subnet = "10.0.6.0/24"
network_acl = "nacl-foo-loadbalancer"
Expand Down Expand Up @@ -277,23 +300,26 @@ vpcs = [
name = "vpc-bar"
ipv4_cidr_block = "10.10.0.0/16"
public_subnets = [
subnets = [
{
name = "sbn-bar-public"
usage_type = "GEN"
subnet_type = "PUBLIC"
zone = "KR-1"
subnet = "10.10.1.0/24"
network_acl = "default"
}
]
private_subnets = [
},
{
name = "sbn-bar-private"
usage_type = "GEN"
subnet_type = "PRIVATE"
zone = "KR-1"
subnet = "10.10.2.0/24"
network_acl = "default"
}
]
access_control_groups = [
{
name = "acg-bar-public"
Expand Down Expand Up @@ -362,9 +388,12 @@ module "vpcs" {
name = each.value.name
ipv4_cidr_block = each.value.ipv4_cidr_block
public_subnets = lookup(each.value, "public_subnets", [])
private_subnets = lookup(each.value, "private_subnets", [])
loadbalancer_subnets = lookup(each.value, "loadbalancer_subnets", [])
subnets = lookup(each.value, "subnets", [])
// Deprecated. It has been replaced by "subnets"
// public_subnets = lookup(each.value, "public_subnets", [])
// private_subnets = lookup(each.value, "private_subnets", [])
// loadbalancer_subnets = lookup(each.value, "loadbalancer_subnets", [])
network_acls = lookup(each.value, "network_acls", [])
deny_allow_groups = lookup(each.value, "deny_allow_groups", [])
Expand Down
19 changes: 18 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ resource "ncloud_vpc" "vpc" {
ipv4_cidr_block = var.ipv4_cidr_block
}


resource "ncloud_subnet" "subnets" {
for_each = { for subnet in var.subnets : subnet.name => subnet }

name = each.value.name
vpc_no = ncloud_vpc.vpc.id
usage_type = each.value.usage_type
subnet_type = each.value.subnet_type
zone = each.value.zone
subnet = each.value.subnet
network_acl_no = each.value.network_acl == "default" ? ncloud_vpc.vpc.default_network_acl_no : ncloud_network_acl.network_acls[each.value.network_acl].id

}

// Deprecated. It has been replaced by "subnets"
resource "ncloud_subnet" "public_subnets" {
for_each = { for subnet in var.public_subnets : subnet.name => subnet }

Expand All @@ -16,6 +31,7 @@ resource "ncloud_subnet" "public_subnets" {

}

// Deprecated. It has been replaced by "subnets"
resource "ncloud_subnet" "private_subnets" {
for_each = { for subnet in var.private_subnets : subnet.name => subnet }

Expand All @@ -29,6 +45,7 @@ resource "ncloud_subnet" "private_subnets" {

}

// Deprecated. It has been replaced by "subnets"
resource "ncloud_subnet" "loadbalancer_subnets" {
for_each = { for subnet in var.loadbalancer_subnets : subnet.name => subnet }

Expand All @@ -43,7 +60,7 @@ resource "ncloud_subnet" "loadbalancer_subnets" {
}

locals {
subnets = merge(ncloud_subnet.public_subnets, ncloud_subnet.private_subnets, ncloud_subnet.loadbalancer_subnets)
subnets = merge(ncloud_subnet.subnets, ncloud_subnet.public_subnets, ncloud_subnet.private_subnets, ncloud_subnet.loadbalancer_subnets)
}

resource "ncloud_network_acl" "network_acls" {
Expand Down
8 changes: 7 additions & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ output "vpc" {
value = ncloud_vpc.vpc
}


output "subnets" {
value = merge(ncloud_subnet.subnets, ncloud_subnet.public_subnets, ncloud_subnet.private_subnets, ncloud_subnet.loadbalancer_subnets)
}

// Deprecated. It has been replaced by "subnets"
output "all_subnets" {
value = merge(ncloud_subnet.public_subnets, ncloud_subnet.private_subnets, ncloud_subnet.loadbalancer_subnets)
value = merge(ncloud_subnet.subnets, ncloud_subnet.public_subnets, ncloud_subnet.private_subnets, ncloud_subnet.loadbalancer_subnets)
}

output "public_subnets" {
Expand Down
42 changes: 24 additions & 18 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,41 +1,47 @@
variable "name" {
description = "See the description in the readme"
type = string
type = string
}

variable "ipv4_cidr_block" {
description = "See the description in the readme"
type = string
type = string
}

variable "subnets" {
description = "See the description in the readme"
type = list(any)
default = []
}

variable "public_subnets" {
description = "See the description in the readme"
type = list(any)
default = []
type = list(any)
default = []
}

variable "private_subnets" {
description = "See the description in the readme"
type = list(any)
default = []
type = list(any)
default = []
}

variable "loadbalancer_subnets" {
description = "See the description in the readme"
type = list(any)
default = []
type = list(any)
default = []
}

variable "network_acls" {
description = "See the description in the readme"
type = list(any)
default = []
type = list(any)
default = []
}

variable "deny_allow_groups" {
description = "See the description in the readme"
type = list(any)
default = []
type = list(any)
default = []
}

variable "access_control_groups" {
Expand All @@ -46,18 +52,18 @@ variable "access_control_groups" {

variable "public_route_tables" {
description = "See the description in the readme"
type = list(any)
default = []
type = list(any)
default = []
}

variable "private_route_tables" {
description = "See the description in the readme"
type = list(any)
default = []
type = list(any)
default = []
}

variable "nat_gateways" {
description = "See the description in the readme"
type = list(any)
default = []
type = list(any)
default = []
}

0 comments on commit d6c0ed5

Please sign in to comment.