Skip to content

Commit

Permalink
feat: added description and update example.tf
Browse files Browse the repository at this point in the history
  • Loading branch information
theprashantyadav committed Jun 14, 2023
1 parent 61803d6 commit ca21e6b
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 59 deletions.
13 changes: 9 additions & 4 deletions _example/new_security_group/example.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
####----------------------------------------------------------------------------------
## Provider block added, Use the Amazon Web Services (AWS) provider to interact with the many resources supported by AWS.
####----------------------------------------------------------------------------------
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"
Expand All @@ -11,19 +17,18 @@ module "vpc" {
cidr_block = "10.0.0.0/16"
}

##----------------------------------------------------------------------------------
## Below module will create SECURITY-GROUP and its components.
##----------------------------------------------------------------------------------
module "security_group" {
source = "../../"

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

enable_security_group = true
vpc_id = module.vpc.vpc_id
protocol = "tcp"
description = "Instance default security group (only egress access is allowed)."
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-xxxxxxxxxxxx"]
prefix_list_ids = ["pl-xxxxxxxxxxxx"]
Expand Down
13 changes: 9 additions & 4 deletions _example/new_security_group_with_egress/example.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
####----------------------------------------------------------------------------------
## Provider block added, Use the Amazon Web Services (AWS) provider to interact with the many resources supported by AWS.
####----------------------------------------------------------------------------------
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"
Expand All @@ -11,17 +17,17 @@ module "vpc" {
cidr_block = "10.0.0.0/16"
}

##----------------------------------------------------------------------------------
## Below module will create SECURITY-GROUP and its components.
##----------------------------------------------------------------------------------
module "security_group" {
source = "../../"

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

enable_security_group = true
vpc_id = module.vpc.vpc_id
protocol = "tcp"
description = "Instance default security group (only egress access is allowed)."
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]
Expand All @@ -32,7 +38,6 @@ module "security_group" {
egress_allowed_ip = ["172.16.0.0/16", "10.0.0.0/16"]
egress_allowed_ports = [22, 27017]
egress_protocol = "tcp"
egress_allowed_ipv6 = ["2405:201:5e00:3684:cd17:9397:5734:a167/128"]
egress_prefix_list_ids = ["pl-xxxxxxxxx"]
egress_security_groups = ["sg-xxxxxxxxx"]

Expand Down
11 changes: 0 additions & 11 deletions _example/new_security_group_with_egress/versions.tf

This file was deleted.

12 changes: 9 additions & 3 deletions _example/updated_existing/example.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
####----------------------------------------------------------------------------------
## Provider block added, Use the Amazon Web Services (AWS) provider to interact with the many resources supported by AWS.
####----------------------------------------------------------------------------------
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"
Expand All @@ -11,6 +17,9 @@ module "vpc" {
cidr_block = "10.0.0.0/16"
}

##----------------------------------------------------------------------------------
## Below module will create SECURITY-GROUP and its components.
##----------------------------------------------------------------------------------
module "security_group" {
source = "../../"

Expand All @@ -21,10 +30,7 @@ module "security_group" {
is_external = true
existing_sg_id = "sg-xxxxxxxxxxxx"
vpc_id = module.vpc.vpc_id
protocol = "tcp"
description = "Instance default security group (only egress access is allowed)."
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-xxxxxxxxxxxxx"]
}
11 changes: 0 additions & 11 deletions _example/updated_existing/versions.tf

This file was deleted.

38 changes: 19 additions & 19 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# Managed By : CloudDrove
# Description : This Script is used to create Security Group.
# Copyright @ CloudDrove. All Right Reserved.

#Module : Label
#Description : This terraform module is designed to generate consistent label names and tags
# for resources. You can use terraform-labels to implement a strict naming
# convention.

##----------------------------------------------------------------------------------
## This terraform module is designed to generate consistent label names and
## tags for resources. You can use terraform-labels to implement a strict naming convention.
##----------------------------------------------------------------------------------
module "labels" {
source = "clouddrove/labels/aws"
version = "1.3.0"
Expand Down Expand Up @@ -48,9 +43,9 @@ locals {

}

#Module : SECURITY GROUP
#Description : Here are an example of how you can use this module in your inventory
# structure:
##----------------------------------------------------------------------------------
## Here are an example of how you can use this resource in your inventory structure.
##----------------------------------------------------------------------------------
resource "aws_security_group" "default" {
count = local.security_group_count

Expand All @@ -69,9 +64,10 @@ data "aws_security_group" "existing" {
vpc_id = var.vpc_id
}

#Module : SECURITY GROUP RULE FOR EGRESS
#Description : Provides a security group rule resource. Represents a single egress
# group rule, which can be added to external Security Groups.
##----------------------------------------------------------------------------------
## Provides a security group rule resource. Represents a single egress
## group rule, which can be added to external Security Groups.
##----------------------------------------------------------------------------------
resource "aws_security_group_rule" "egress" {
count = (var.enable_security_group == true && local.sg_existing == false && local.egress_rule == false) ? 1 : 0

Expand All @@ -93,9 +89,11 @@ resource "aws_security_group_rule" "egress_ipv6" {
security_group_id = local.id
prefix_list_ids = var.prefix_list
}
#Module : SECURITY GROUP RULE FOR INGRESS
#Description : Provides a security group rule resource. Represents a single ingress
# group rule, which can be added to external Security Groups.

##----------------------------------------------------------------------------------
## Provides a security group rule resource. Represents a single ingress
## group rule, which can be added to external Security Groups.
##----------------------------------------------------------------------------------
resource "aws_security_group_rule" "ingress" {
count = local.enable_cidr_rules == true ? length(compact(var.allowed_ports)) : 0

Expand Down Expand Up @@ -139,8 +137,10 @@ resource "aws_security_group_rule" "ingress_prefix" {
security_group_id = local.id
}

#egress rules configuration

##----------------------------------------------------------------------------------
## egress rules configuration.
##----------------------------------------------------------------------------------
resource "aws_security_group_rule" "egress_ipv4_rule" {
count = local.egress_rule == true ? length(compact(var.allowed_ports)) : 0

Expand Down
7 changes: 4 additions & 3 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Module : SECURITY GROUP
#Description : This terraform module creates set of Security Group and Security Group Rules
# resources in various combinations.
##----------------------------------------------------------------------------------
## This terraform module creates set of Security Group and Security Group Rules
## resources in various combinations..
##----------------------------------------------------------------------------------
output "security_group_ids" {
value = try(local.id, null)
description = "IDs on the AWS Security Groups associated with the instance."
Expand Down
4 changes: 2 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ variable "protocol" {

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

Expand Down Expand Up @@ -152,7 +152,7 @@ variable "egress_security_groups" {

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

Expand Down
4 changes: 2 additions & 2 deletions _example/new_security_group/versions.tf → versions.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Terraform version
terraform {
required_version = ">= 1.3.6"
required_version = ">= 1.4.6"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.48.0"
version = ">= 5.1.0"
}
}
}

0 comments on commit ca21e6b

Please sign in to comment.