Skip to content

Commit

Permalink
rds-postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
ashle001 committed Apr 20, 2021
1 parent a4a5651 commit 9e47116
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rds-postgres/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# v1.3 -- 20200604

* add module version, update tags
57 changes: 57 additions & 0 deletions rds-postgres/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# About

This describes how to use the aws-common-security-groups submodule for rds-postgres

# Usage

```code
module "rds-postgres" {
source = "git::https://vc1.csvd.census.gov/terraform-modules/aws-common-security-groups.git//rds-postgres"
# name = "m-rds-postgres"
vpc_id = var.vpc_id
# Name, CostAllocation, and Environment are pre-set
# tags = { }
}
```

## Requirements

| Name | Version |
|------|---------|
| terraform | >= 0.12 |

## Providers

| Name | Version |
|------|---------|
| aws | n/a |

## Modules

No Modules.

## Resources

| Name |
|------|
| [aws_security_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| \_module\_version | Module version number | `string` | `"1.3"` | no |
| egress\_networks | List of egress networks (all ports) | `list(string)` | <pre>[<br> "0.0.0.0/0"<br>]</pre> | no |
| name | Security group Name | `string` | `"m-postgres-db"` | no |
| networks | List of ingress networks (applies to all ports) | `list(string)` | <pre>[<br> "0.0.0.0/0"<br>]</pre> | no |
| tags | Extra security group tags | `map` | <pre>{<br> "CostAllocation": "csvd:infrastructure",<br> "Environment": "csvd-infrastructure"<br>}</pre> | no |
| vpc\_full\_name | VPC Name | `string` | `""` | no |
| vpc\_id | VPC ID Number | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| this\_security\_group\_arn | Created security group ARN |
| this\_security\_group\_id | Created security group ID |
52 changes: 52 additions & 0 deletions rds-postgres/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* # About
*
* This describes how to use the aws-common-security-groups submodule for rds-oracle
*
* # Usage
*
* ```code
* module "rds-postgres" {
* source = "git::https://vc1.csvd.census.gov/terraform-modules/aws-common-security-groups.git//rds-postgres"
*
* # name = "m-rds-postgres"
* vpc_id = var.vpc_id
* # Name, CostAllocation, and Environment are pre-set
* # tags = { }
* }
* ```
*/

resource "aws_security_group" "this_security_group" {
name = local.name
description = local.description
vpc_id = var.vpc_id

# portlist
dynamic "ingress" {
for_each = local.ports_map
iterator = p
content {
description = "${local.description}: ${p.value["description"]}"
from_port = p.value["from"]
to_port = p.value["to"]
protocol = p.value["proto"]
cidr_blocks = length(p.value["cidr"]) == 0 ? local.ingress_networks : p.value["cidr"]
}
}

egress {
description = "${local.description}: All"
from_port = 0
to_port = 0
protocol = -1
cidr_blocks = local.egress_networks
}

tags = merge(
map("Name", "sg-${local.name}"),
var.tags,
map("boc:tf_module_version", var._module_version),
map("boc:vpc:info", join(" ", compact(list(var.vpc_id, var.vpc_full_name)))),
)
}
9 changes: 9 additions & 0 deletions rds-postgres/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "this_security_group_id" {
description = "Created security group ID"
value = aws_security_group.this_security_group.id
}

output "this_security_group_arn" {
description = "Created security group ARN"
value = aws_security_group.this_security_group.arn
}
11 changes: 11 additions & 0 deletions rds-postgres/ports.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
locals {
description = "module: PostGres common ports"
name = var.name
ports = [
[5482, 5482, "tcp", "postgres-db", []],
]
ingress_networks = var.networks
egress_networks = var.egress_networks
ports_fields = ["from", "to", "proto", "description", "cidr"]
ports_map = [for p in local.ports : zipmap(local.ports_fields, p)]
}
38 changes: 38 additions & 0 deletions rds-postgres/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
variable "vpc_id" {
description = "VPC ID Number"
type = string
}

variable "vpc_full_name" {
description = "VPC Name"
type = string
default = ""
}

variable "name" {
description = "Security group Name"
type = string
# default = "m-rds-postgres"
default = "m-postgres-db"
}

variable "networks" {
description = "List of ingress networks (applies to all ports)"
type = list(string)
default = ["0.0.0.0/0"]
}

variable "egress_networks" {
description = "List of egress networks (all ports)"
type = list(string)
default = ["0.0.0.0/0"]
}

variable "tags" {
description = "Extra security group tags"
type = map
default = {
"CostAllocation" = "csvd:infrastructure"
"Environment" = "csvd-infrastructure"
}
}
5 changes: 5 additions & 0 deletions rds-postgres/version.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variable "_module_version" {
description = "Module version number"
type = string
default = "1.3"
}
4 changes: 4 additions & 0 deletions rds-postgres/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

terraform {
required_version = ">= 0.12"
}

0 comments on commit 9e47116

Please sign in to comment.