Skip to content

Commit

Permalink
Merge pull request #1 from subhamay-bhattacharyya/initial-release
Browse files Browse the repository at this point in the history
Initial Release of Terraform AWS Security Group Module
  • Loading branch information
bsubhamay authored Dec 30, 2024
2 parents c758029 + c03dd04 commit 8d263d2
Show file tree
Hide file tree
Showing 9 changed files with 511 additions and 26 deletions.
37 changes: 13 additions & 24 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,37 +1,26 @@
# Local .terraform directories
**/.terraform/*

# .tfstate files
# Terraform files
*.tfstate
*.tfstate.*

# Crash log files
crash.log
crash.*.log

# Exclude all .tfvars files, which are likely to contain sensitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
*.tfvars
*.tfvars.json

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Ignore transient lock info files created by terraform apply
.terraform.tfstate.lock.info
# Terraform directories
.terraform/
.terraform.lock.hcl

# Include override files you do wish to add to version control using negated pattern
# !example_override.tf
# Local .env files
.env
.env.*

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*
# IDE files
.vscode/
.idea/

# Ignore CLI configuration files
.terraformrc
terraform.rc
# OS generated files
.DS_Store
Thumbs.db
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#### Change Log

[1.0.0] - 2024-12-29

##### Added
- Initial release of the Terraform AWS Security Group module.
- Create security groups with or without specified ingress and egress rules.
- Add rules to an existing security group.
- Support for tagging resources.
- Example usage provided in README.
- Default tags configuration.
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

MIT License

Copyright (c) 2024

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
186 changes: 184 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,184 @@
# terraform-aws-security-group
◉ 🚩Private Terraform Registry Module - Security Group with Rules
![](https://img.shields.io/github/commit-activity/t/subhamay-bhattacharyya/terraform-aws-security-group) ![](https://img.shields.io/github/last-commit/subhamay-bhattacharyya/terraform-aws-security-group) ![](https://img.shields.io/github/release-date/subhamay-bhattacharyya/terraform-aws-security-group) ![](https://img.shields.io/github/repo-size/subhamay-bhattacharyya/terraform-aws-security-group) ![](https://img.shields.io/github/directory-file-count/subhamay-bhattacharyya/terraform-aws-security-group) [](https://img.shields.io/github/issues/subhamay-bhattacharyya/terraform-aws-security-group) ![](https://img.shields.io/github/languages/top/subhamay-bhattacharyya/terraform-aws-security-group) ![](https://img.shields.io/github/commit-activity/m/subhamay-bhattacharyya/terraform-aws-security-group) ![](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/bsubhamay/889647c4be2d0f8fb1ef2fb965f2daba/raw/terraform-aws-security-group.json?)

## Terraform AWS Security Group Module

### Usage

* Terraform module to create security groups.
* Module source: app.terraform.io/subhamay-bhattacharyya/security-group/aws
* Version: 1.0.0

### Required Inputs:
- `project-name`: The name of the project.
- `vpc-id`: The ID of the VPC where the security group will be created.
- `security_group_configuration`: A map defining the security group wilth associated rules.
- `ci-build`: A string representing the CI build identifier.

### Example Usage:

```hcl
module "security_group" {
source = "app.terraform.io/subhamay-bhattacharyya/security-group/aws"
version = "1.0.0"
project-name = "your-project-name"
vpc-id = "your-vpc-id"
security-group-configuration = "your-security-group-configuration"
ci-build = "your-ci-build-string"
}
```

### Security Group configuration

##### Configure the security group with associated rules as a map type variable
```hcl
security-group-configuration = {
name = "ec2-sg"
description = "EC2 Security Group"
ingress = {
ssh = {
name = "Allows SSH"
description = "Allows inbound SSH traffic on port 22 from anywhere."
from = 22
to = 22
protocol = "tcp"
cidr-blocks = "0.0.0.0/0"
}
ssh = {
name = "Allows SSH"
description = "Allows inbound traffic from ec2 instance connect endpoints on port 22."
from = 22
to = 22
protocol = "tcp"
referenced-sg-id = module.ecic_security_group.security-group-id
}
egress = {
https = {
name = "Allows HTTPS"
description = "Allows outbound traffic from ec2 instance security group to s3 prefix list."
from = 443
to = 443
protocol = "tcp"
prefix-list-id = data.aws_ec2_managed_prefix_list.s3_vpce_prefix_list.id
}
}
}
```

##### Default tags

Use local variables to configure the default tags.
_The default resource tags are implemented using the CI/CD Pipeline. The following mao just refers to it._
```hcl
locals {
tags = {
Environment = var.environment-name
ProjectName = var.project-name
GitHubRepository = var.github-repo
GitHubRef = var.github-ref
GitHubURL = var.github-url
GitHubSHA = var.github-sha
}
}
Use local variable to configure the security group configuration.
locals {
vpc-endpoint-sg = {
name = "vpc-endpoint"
description = "VPC Endpoint Security Group"
ingress = {
https = {
name = "Allows HTTPS"
description = "Allows inbound traffic from the VPC on port 443."
from = 443
to = 443
protocol = "tcp"
cidr-blocks = var.vpc-cidr
}
}
egress = {}
}
ec2-instance-sg = {
name = "ec2-instance"
description = "EC2 Instance Security Group"
ingress = {}
egress = {}
}
ec2-instance-connect-sg = {
name = "ec2-instance-connect"
description = "EC2 Instance Connect Security Group"
ingress = {}
egress = {}
}
ec2-instance-sg-rules = {
security-group-id = module.ec2_security_group.security-group-id
ingress = {
ssh = {
name = "Allows SSH"
description = "Allows inbound traffic from ec2 instance connect endpoints on port 22."
from = 22
to = 22
protocol = "tcp"
referenced-sg-id = module.ecic_security_group.security-group-id
}
}
egress = {
https = {
name = "Allows HTTPS"
description = "Allows outbound traffic to the endpoints on port 443."
from = 443
to = 443
protocol = "tcp"
referenced-sg-id = module.vpce_security_group.security-group-id
}
https1 = {
name = "Allows HTTPS"
description = "Allows outbound traffic from ec2 instance security group to s3 prefix list."
from = 443
to = 443
protocol = "tcp"
prefix-list-id = data.aws_ec2_managed_prefix_list.s3_vpce_prefix_list.id
}
}
}
ec2-instance-connect-sg-rules = {
security-group-id = module.ecic_security_group.security-group-id
ingress = {}
egress = {
ssh = {
name = "Allows SSH"
description = "Allows outbound SSH traffic on port 22 to ec2 instance security group."
from = 22
to = 22
protocol = "tcp"
referenced-sg-id = module.ec2_security_group.security-group-id
}
}
}
```
#### Note


## Inputs

| Name | Description | Type | Default | Required |
|- |- |- |- |- |
| project-name | The name of the project | string | n/a | yes |
| vpc-id | The VPC ID where the security group will be created | string | n/a | yes |
| security-group-configuration | Configuration for the security group | object | n/a | yes |
| ci-build | A string representing the CI build identifier | string | "" | yes |

## Outputs

| Name | Description |
|- |- |
| security-group-id | The ID of the security group. |
| security-group-name | The name of the security group. |
| security-group-arn | The ARN of the security group. |
| security-group-rules | The security group rules (inbound and outbound). |
13 changes: 13 additions & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#### Version: 1.0.0
Initial release of the Terraform AWS Security Group module.
Version: 1.0.0
Author: Subhamay Bhattacharyya
Created: 25-Dec-2024
Updated:
Description: This module creates and manages AWS Security Groups with specified ingress and egress rules using Terraform.

## Features
- Create security groups with specified ingress and egress rules
- Support for tagging resources
- Example usage provided in README
- Default tags configuration
17 changes: 17 additions & 0 deletions data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
####################################################################################################
# Terraform Security Group Module Data Block Configuration
#
# Description: This module creates a Security Group in AWS with the specified rules.
#
# Author: Subhamay Bhattacharyya
# Created: 29-Dec-2024
# Version: 1.0
#
####################################################################################################
*/

# AWS Region and Caller Identity
data "aws_region" "current" {}

data "aws_caller_identity" "current" {}
Loading

0 comments on commit 8d263d2

Please sign in to comment.