|
| 1 | + |
| 2 | +# [terraform-aws-arc-security-group](https://github.com/sourcefuse/terraform-aws-arc-security-group) |
| 3 | + |
| 4 | +<a href="https://github.com/sourcefuse/terraform-aws-arc-security-group/releases/latest"><img src="https://img.shields.io/github/release/sourcefuse/terraform-aws-arc-security-group.svg?style=for-the-badge" alt="Latest Release"/></a> <a href="https://github.com/sourcefuse/terraform-aws-arc-security-group/commits"><img src="https://img.shields.io/github/last-commit/sourcefuse/terraform-aws-arc-security-group.svg?style=for-the-badge" alt="Last Updated"/></a>   |
| 5 | + |
| 6 | +[](https://sonarcloud.io/summary/new_code?id=sourcefuse_terraform-aws-arc-security-group) |
| 7 | + |
| 8 | +[](https://github.com/sourcefuse/terraform-aws-arc-security-group/actions/workflows/snyk.yaml) |
| 9 | + |
| 10 | +## Introduction |
| 11 | + |
| 12 | +The SourceFuse AWS Reference Architecture (ARC) Terraform module for creating and managing AWS security groups with customizable rules. It simplifies defining inbound and outbound rules for specific protocols, ports, and CIDR ranges, ensuring secure and efficient network traffic control in your infrastructure. |
| 13 | + |
| 14 | +For more information about this repository and its usage, please see [Terraform AWS ARC Security Group Module Usage Guide](docs/module-usage-guide/README.md). |
| 15 | + |
| 16 | +### Prerequisites |
| 17 | +Before using this module, ensure you have the following: |
| 18 | + |
| 19 | +- AWS credentials configured. |
| 20 | +- Terraform installed. |
| 21 | +- A working knowledge of Terraform. |
| 22 | + |
| 23 | +## Usage |
| 24 | +See the `examples` folder for a complete example. |
| 25 | + |
| 26 | +```hcl |
| 27 | +
|
| 28 | +locals { |
| 29 | + security_group_data = { |
| 30 | + create = true |
| 31 | + description = "Security Group for Loadbalancer" |
| 32 | +
|
| 33 | + ingress_rules = [ |
| 34 | + { |
| 35 | + description = "Allow VPC traffic" |
| 36 | + cidr_block = data.aws_vpc.this.cidr_block |
| 37 | + from_port = 0 |
| 38 | + ip_protocol = "tcp" |
| 39 | + to_port = 65535 |
| 40 | + }, |
| 41 | + { |
| 42 | + description = "Allow traffic from self" |
| 43 | + self = true |
| 44 | + from_port = 0 |
| 45 | + ip_protocol = "tcp" |
| 46 | + to_port = 65535 |
| 47 | + }, |
| 48 | + { |
| 49 | + description = "Allow traffic from security group" |
| 50 | + source_security_group_id = data.aws_security_group.default.id |
| 51 | + from_port = 0 |
| 52 | + ip_protocol = "tcp" |
| 53 | + to_port = 65535 |
| 54 | + } |
| 55 | + ] |
| 56 | +
|
| 57 | + egress_rules = [ |
| 58 | + { |
| 59 | + description = "Allow all outbound traffic" |
| 60 | + cidr_block = "0.0.0.0/0" |
| 61 | + from_port = -1 |
| 62 | + ip_protocol = "-1" |
| 63 | + to_port = -1 |
| 64 | + } |
| 65 | + ] |
| 66 | + } |
| 67 | +} |
| 68 | +
|
| 69 | +module "arc_security_group" { |
| 70 | + source = "sourcefuse/arc-security-group/aws" |
| 71 | + version = "0.0.1" |
| 72 | +
|
| 73 | + name = "${var.namespace}-${var.environment}-sg" |
| 74 | + vpc_id = data.aws_vpc.this.id |
| 75 | + ingress_rules = local.security_group_data.ingress_rules |
| 76 | + egress_rules = local.security_group_data.egress_rules |
| 77 | +
|
| 78 | + tags = module.tags.tags |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
| 83 | +## Requirements |
| 84 | + |
| 85 | +| Name | Version | |
| 86 | +|------|---------| |
| 87 | +| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | > 1.4, < 2.0.0 | |
| 88 | +| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 5.0 | |
| 89 | + |
| 90 | +## Providers |
| 91 | + |
| 92 | +| Name | Version | |
| 93 | +|------|---------| |
| 94 | +| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.80.0 | |
| 95 | + |
| 96 | +## Modules |
| 97 | + |
| 98 | +No modules. |
| 99 | + |
| 100 | +## Resources |
| 101 | + |
| 102 | +| Name | Type | |
| 103 | +|------|------| |
| 104 | +| [aws_security_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) | resource | |
| 105 | +| [aws_vpc_security_group_egress_rule.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_security_group_egress_rule) | resource | |
| 106 | +| [aws_vpc_security_group_ingress_rule.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_security_group_ingress_rule) | resource | |
| 107 | + |
| 108 | +## Inputs |
| 109 | + |
| 110 | +| Name | Description | Type | Default | Required | |
| 111 | +|------|-------------|------|---------|:--------:| |
| 112 | +| <a name="input_description"></a> [description](#input\_description) | (optional) Description of Security Group | `string` | `null` | no | |
| 113 | +| <a name="input_egress_rules"></a> [egress\_rules](#input\_egress\_rules) | (optional) List of egress rules for the security group. | <pre>list(object({<br> description = optional(string, null)<br> cidr_block = optional(string, null)<br> destination_security_group_id = optional(string, null)<br> from_port = number<br> ip_protocol = string<br> to_port = string<br> prefix_list_id = optional(string, null)<br> }))</pre> | `[]` | no | |
| 114 | +| <a name="input_ingress_rules"></a> [ingress\_rules](#input\_ingress\_rules) | (optional) List of ingress rules for the security group. | <pre>list(object({<br> description = optional(string, null)<br> cidr_block = optional(string, null)<br> source_security_group_id = optional(string, null)<br> from_port = number<br> ip_protocol = string<br> to_port = string<br> self = optional(bool, false)<br> }))</pre> | `[]` | no | |
| 115 | +| <a name="input_name"></a> [name](#input\_name) | Security Group name | `string` | n/a | yes | |
| 116 | +| <a name="input_tags"></a> [tags](#input\_tags) | Tags for Security Group | `map(string)` | `{}` | no | |
| 117 | +| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | VPC Id for creating security group | `string` | n/a | yes | |
| 118 | + |
| 119 | +## Outputs |
| 120 | + |
| 121 | +| Name | Description | |
| 122 | +|------|-------------| |
| 123 | +| <a name="output_id"></a> [id](#output\_id) | Security Group ID | |
| 124 | +<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
| 125 | + |
| 126 | +## Versioning |
| 127 | +This project uses a `.version` file at the root of the repo which the pipeline reads from and does a git tag. |
| 128 | + |
| 129 | +When you intend to commit to `main`, you will need to increment this version. Once the project is merged, |
| 130 | +the pipeline will kick off and tag the latest git commit. |
| 131 | + |
| 132 | +## Development |
| 133 | + |
| 134 | +### Prerequisites |
| 135 | + |
| 136 | +- [terraform](https://learn.hashicorp.com/terraform/getting-started/install#installing-terraform) |
| 137 | +- [terraform-docs](https://github.com/segmentio/terraform-docs) |
| 138 | +- [pre-commit](https://pre-commit.com/#install) |
| 139 | +- [golang](https://golang.org/doc/install#install) |
| 140 | +- [golint](https://github.com/golang/lint#installation) |
| 141 | + |
| 142 | +### Configurations |
| 143 | + |
| 144 | +- Configure pre-commit hooks |
| 145 | + ```sh |
| 146 | + pre-commit install |
| 147 | + ``` |
| 148 | + |
| 149 | +### Versioning |
| 150 | + |
| 151 | +while Contributing or doing git commit please specify the breaking change in your commit message whether its major,minor or patch |
| 152 | + |
| 153 | +For Example |
| 154 | + |
| 155 | +```sh |
| 156 | +git commit -m "your commit message #major" |
| 157 | +``` |
| 158 | +By specifying this , it will bump the version and if you don't specify this in your commit message then by default it will consider patch and will bump that accordingly |
| 159 | + |
| 160 | +### Tests |
| 161 | +- Tests are available in `test` directory |
| 162 | +- Configure the dependencies |
| 163 | + ```sh |
| 164 | + cd test/ |
| 165 | + go mod init github.com/sourcefuse/terraform-aws-refarch-<module_name> |
| 166 | + go get github.com/gruntwork-io/terratest/modules/terraform |
| 167 | + ``` |
| 168 | +- Now execute the test |
| 169 | + ```sh |
| 170 | + go test -timeout 30m |
| 171 | + ``` |
| 172 | + |
| 173 | +## Authors |
| 174 | + |
| 175 | +This project is authored by: |
| 176 | +- SourceFuse ARC Team |
0 commit comments