AWS Security Group (SG) Terraform Module
Terraform module to provision AWS VPC Security Group
on AWS.
Usage
Simple setup
Create a simple security group with default rules.
module "security_group" {
source = "app.terraform.io/ncodelibrary/security-group/aws"
version = "0.1.2"
identifier = "example-sg"
vpc_id = "vpc-xxxxxxxxxxxxx"
tags = {
Owner = "sysops"
env = "dev"
Cost_Center = "XYZ"
}
}
For more details on a working example, please visit examples/simple
Advanced Setup
If you want to create security group with custom rules, you can use the module like this:
module "security_group" {
source = "app.terraform.io/ncodelibrary/security-group/aws"
version = "0.1.2"
identifier = "example-sg"
vpc_id = "vpc-xxxxxxxxxxxxx"
ingress_rule_list = [
{
cidr_blocks = ["0.0.0.0/0"],
description = "HTTPS inbound",
from_port = 443,
protocol = "tcp",
to_port = 443
},
{
cidr_blocks = ["0.0.0.0/0"],
description = "HTTP inbound",
from_port = 80,
protocol = "tcp",
to_port = 80
}]
egress_rule_list = [{
cidr_blocks = ["0.0.0.0/0"],
description = "HTTPS outbound",
from_port = 443,
protocol = "tcp",
to_port = 443
},
{
cidr_blocks = ["0.0.0.0/0"],
description = "HTTP outbound",
from_port = 80,
protocol = "tcp",
to_port = 80
}
]
tags = var.tags
}
For more options refer to a working example at examples/advanced
Examples
Here are some working examples of using this module:
Requirements
Name | Version |
---|---|
terraform | >= 0.12 |
Providers
Name | Version |
---|---|
aws | n/a |
Modules
No Modules.
Resources
Name |
---|
aws_security_group |
aws_security_group_rule |
Inputs
Name | Description | Type | Default | Required |
---|---|---|---|---|
append_workspace | Appends the terraform workspace at the end of resource names, |
bool |
true |
no |
description | A description for the security group | string |
"Security group created by terraform" |
no |
egress_rule_list | List of security group egress rules | list(object({ |
[ |
no |
identifier | The name of the security group | string |
n/a | yes |
ingress_rule_list | List of security group ingress rules | list(object({ |
[] |
no |
self_rule | Set to ‘true’ to create a self ingress rule in the security group | bool |
false |
no |
tags | Tags to be applied to the resource | map |
{} |
no |
vpc_id | The id of the VPC where the security group is being deployed | string |
n/a | yes |
Outputs
Name | Description |
---|---|
output | n/a |
Contributing
If you want to contribute to this repository check all the guidelines specified here before submitting a new PR.