Git Product home page Git Product logo

terraform-aws-security-group-bulk-rules's Introduction

Terraform AWS Security Group bulk rules

This Terraform AWS module is for managing bulk AWS security group rules. This module allows large volumes of rules to be defined in a concise Terraform map type. The map is then looped through using For_Each meta-argument to define individual AWS Security Group Rules. These rules are deployed into an AWS Security Group.

Features

Current version supports:

  • IPv4 CIDR source
  • Security Group source
  • Self source
  • Ingress and Egress rules
  • Description fields
  • Rules limited only by AWS quota

Upcoming features

Usage

In a local map type define your required rules, with one rule per line.

Allowed values:

  • type: "ingress", "egress"
  • protocol: "tcp", "udp", "icmp", "all", "-1"
  • source_type: "cidr" "sg" "self"

Example

locals {
  web_server_rules = {
    1 = { type = "ingress", protocol = "tcp", from = 443,  to = 443,  source_type = "cidr", source = "0.0.0.0/0", desc = "Inbound Public HTTPS web traffic" },
    2 = { type = "ingress", protocol = "tcp", from = 80,   to = 80,   source_type = "cidr", source = "0.0.0.0/0", desc = "Inbound Public HTTP web traffic" },
    3 = { type = "ingress", protocol = "tcp", from = 22,   to = 22,   source_type = "sg",   source = "sg-000000000", desc = "Inbound SSH from Security Group" },
    4 = { type = "ingress", protocol = "tcp", from = 8001, to = 8009, source_type = "self", source = true, desc = "Inbound service traffic from security group" },
    5 = { type = "egress",  protocol = "all",  from = -1,   to = -1,   source_type = "cidr", source = "0.0.0.0/0", desc = "Outbound all ports and protocols" },
    6 = { type = "egress",  protocol = "icmp",  from = -1,   to = -1,   source_type = "sg", source = aws_security_group.differentSG.id, desc = "Outbound all ports and protocols" },
  }
}

module "bulk-aws-security-groups-rules" {
  source = "./modules/bulk-aws-security-groups-rules"
  sg_name = "webserver_sg"
  vpc = "vpc-0aa00aa0"
  sg_description = "Web server cluster security rules"
  sg_rules = web_server_rules
}

Managing larges rulesets

Ideally all of our security groups should be only in code so we dont have to update documentation. The reality is that many companies still rely on spreadsheets to help them manage, review, and audit their infrastructure. This module can be (manually) powered by a master security group rule spreadsheet with a little bit of Excel formula "fun". This spreadsheet can have all the inbound and outbound rules that have been implemented in the environment and is easily consumed by auditors and management. This is obviously not the ideal state but one that many of us live in :)

Below is an example format you could use as a template for this master spreadsheet, along with the Excel formula to create the Map input rules.

Security_group_name Rule_id Direction Protocol Port_from Port_to Source_dest_type Source_or_dest Description TF_map_input

terraform-aws-security-group-bulk-rules's People

Contributors

codecker avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.