Skip to content

Commit

Permalink
feat: add prefix list id argument
Browse files Browse the repository at this point in the history
  • Loading branch information
theprashantyadav committed Jul 18, 2023
1 parent ac15889 commit 925ac6c
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 57 deletions.
23 changes: 22 additions & 1 deletion _example/new_security_group/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,41 @@ provider "aws" {
region = "eu-west-1"
}

####----------------------------------------------------------------------------------
## A VPC is a virtual network that closely resembles a traditional network that you'd operate in your own data center.
####----------------------------------------------------------------------------------

module "vpc" {
source = "clouddrove/vpc/aws"
version = "1.3.1"

name = "vpc"
environment = "test"
label_order = ["name", "environment"]
cidr_block = "10.0.0.0/16"
}


module "security_group" {
source = "./../../"

## new_enable_security_group #######
name = "security-group"
environment = "test"
label_order = ["name", "environment"]

## new_enable_security_group #######
vpc_id = module.vpc.vpc_id
new_enable_security_group = true
allowed_ip = ["172.16.0.0/16", "10.0.0.0/16"]
allowed_ports = [22, 27017]
security_groups = []

#-------------------------------------------------------------------------------
### prefix_list
#-------------------------------------------------------------------------------
max_entries = 5
prefix_list_enabled = true
prefix_list_id = []
entry = [
{
cidr = "10.0.0.0/16"
Expand Down
18 changes: 18 additions & 0 deletions _example/new_security_group/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
output "tags" {
value = module.security_group.tags
description = "A mapping of tags to assign to the resource."
}

output "security_group_ids" {
value = module.security_group.security_group_ids
description = "A mapping of security group ids."
}
output "vpc_cidr_block" {
value = module.vpc.vpc_cidr_block
description = "VPC IPV4 CIDR Block."
}

output "vpc_cidr_block_ipv6" {
value = module.vpc.ipv6_cidr_block
description = "VPC IPV4 CIDR Block."
}
22 changes: 11 additions & 11 deletions _example/new_security_group_with_egress/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ provider "aws" {
## A VPC is a virtual network that closely resembles a traditional network that you'd operate in your own data center.
####----------------------------------------------------------------------------------
module "vpc" {
source = "clouddrove/vpc/aws"
version = "1.3.1"
source = "clouddrove/vpc/aws"
version = "1.3.1"

name = "vpc"
environment = "test"
label_order = ["name", "environment"]
Expand All @@ -21,24 +22,23 @@ module "vpc" {
## Below module will create SECURITY-GROUP and its components.
##----------------------------------------------------------------------------------
module "security_group" {
source = "../../"
source = "./../../"

name = "security-group"
environment = "test"
label_order = ["name", "environment"]

vpc_id = module.vpc.vpc_id
allowed_ip = ["172.16.0.0/16", "10.0.0.0/16"]
allowed_ipv6 = ["2405:201:5e00:3684:cd17:9397:5734:a167/128"]
allowed_ports = [22, 27017]
security_groups = ["sg-xxxxxxxxx"]
prefix_list_ids = ["pl-6da54004"]

vpc_id = module.vpc.vpc_id
prefix_list_enabled = false
allowed_ip = ["172.16.0.0/16", "10.0.0.0/16"]
allowed_ipv6 = ["2405:201:5e00:3684:cd17:9397:5734:a167/128"]
allowed_ports = [22, 27017]
security_groups = ["sg-xxxxxxxxx"]
prefix_list_id = ["pl-6da54004"]
egress_rule = true
egress_allowed_ip = ["172.16.0.0/16", "10.0.0.0/16"]
egress_allowed_ports = [22, 27017]
egress_protocol = "tcp"
egress_prefix_list_ids = ["pl-xxxxxxxxx"]
egress_security_groups = ["sg-xxxxxxxxx"]

}
46 changes: 22 additions & 24 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@

####----------------------------------------------------------------------------------
## A VPC is a virtual network that closely resembles a traditional network that you'd operate in your own data center.
####----------------------------------------------------------------------------------

module "vpc" {
source = "clouddrove/vpc/aws"
version = "1.3.1"
name = "vpc"
environment = "prashant"
label_order = ["name", "environment"]
cidr_block = "10.0.0.0/16"
}

#-------------------------------------------------------------------------------
### prefix_list
#-------------------------------------------------------------------------------
module "prefix_list" {
source = "./modules/prefix_list"

name = "prefix_list"
environment = "prashant"
label_order = ["name", "environment"]
name = var.name
environment = var.environment
label_order = var.label_order

max_entries = var.max_entries
prefix_list_enabled = var.prefix_list_enabled
entry = var.entry
entry = var.entry
}

##----------------------------------------------------------------------------------
Expand All @@ -34,10 +23,19 @@ module "security_group" {
environment = "test"
label_order = ["name", "environment"]

enable_security_group = var.new_enable_security_group
vpc_id = module.vpc.vpc_id
allowed_ip = var.allowed_ip
allowed_ports = var.allowed_ports
security_groups = var.security_groups
prefix_list_ids = length(var.prefix_list_id) < 1 ? module.prefix_list.prefix_id : var.prefix_list_id
enable_security_group = var.new_enable_security_group
vpc_id = var.vpc_id
allowed_ip = var.allowed_ip
allowed_ports = var.allowed_ports
security_groups = var.security_groups
allowed_ipv6 = var.allowed_ipv6
egress_rule = var.egress_rule
egress_allowed_ip = var.egress_allowed_ip
egress_allowed_ports = var.egress_allowed_ports
egress_protocol = var.egress_protocol
egress_prefix_list_ids = var.egress_prefix_list_ids
egress_security_groups = var.egress_security_groups
is_external = var.is_external
existing_sg_id = var.existing_sg_id
prefix_list_ids = length(var.prefix_list_id) < 1 ? module.prefix_list.prefix_id : var.prefix_list_id
}
11 changes: 0 additions & 11 deletions modules/security_group/versions.tf

This file was deleted.

9 changes: 0 additions & 9 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ output "security_group_ids" {
value = module.security_group.security_group_ids
description = "A mapping of security group ids."
}
output "vpc_cidr_block" {
value = module.vpc.vpc_cidr_block
description = "VPC IPV4 CIDR Block."
}

output "vpc_cidr_block_ipv6" {
value = module.vpc.ipv6_cidr_block
description = "VPC IPV4 CIDR Block."
}

output "prefix_id" {
value = module.prefix_list.*.prefix_id
Expand Down
81 changes: 80 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
variable "name" {
type = string
default = ""
description = "Name (e.g. `app` or `cluster`)."
}

variable "environment" {
type = string
default = ""
description = "Environment (e.g. `prod`, `dev`, `staging`)."
}

variable "label_order" {
type = list(any)
default = []
description = "Label order, e.g. `name`,`application`."
}

variable "vpc_id" {
type = string
default = ""
description = "The ID of the VPC that the instance security group belongs to."
sensitive = true
}

variable "prefix_list_id" {
type = list(string)
default = []
Expand Down Expand Up @@ -44,4 +69,58 @@ variable "new_enable_security_group" {
type = bool
default = true
description = "Enable default Security Group with only Egress traffic allowed."
}
}

variable "allowed_ipv6" {
type = list(any)
default = ["2405:201:5e00:3684:cd17:9397:5734:a167/128"]
description = "List of allowed ipv6."
}

variable "egress_rule" {
type = bool
default = false
description = "Enable to create egress rule"
}

variable "egress_allowed_ip" {
type = list(any)
default = []
description = "List of allowed ip."
}

variable "egress_allowed_ports" {
type = list(any)
default = []
description = "List of allowed ingress ports"
}

variable "egress_protocol" {
type = string
default = "tcp"
description = "The protocol. If not icmp, tcp, udp, or all use the."
}

variable "egress_prefix_list_ids" {
type = list(any)
default = []
description = "List of prefix list IDs (for allowing access to VPC endpoints)Only valid with egress"
}

variable "egress_security_groups" {
type = list(string)
default = []
description = "List of Security Group IDs allowed to connect to the instance."
}

variable "is_external" {
type = bool
default = false
description = "enable to udated existing security Group"
}

variable "existing_sg_id" {
type = string
default = null
description = "Provide existing security group id for updating existing rule"
}
File renamed without changes.

0 comments on commit 925ac6c

Please sign in to comment.