Skip to content

Commit

Permalink
Add Cloudflare-sg module.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Barnum authored and Dave Barnum committed Jan 12, 2024
1 parent 3cdb99e commit e8185df
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
25 changes: 25 additions & 0 deletions aws/cloudflare-sg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# aws/cloudflare-sg - Cloudflare Security Group
This module is used to create a security group to allow HTTPS/443 traffic from
Cloudflare IP addresses only.

## What this does

- Create security group allowing HTTPS traffic on port 443 from Cloudflare IPs

## Required Inputs

- `vpc_id` - ID of VPC to place security group

## Outputs

- `id` - ID of security group created
- `name` - Name of security group created

## Example Usage

```hcl
module "cloudflare-sg" {
source = "github.com/wycliffe-usa/terraform-modules//aws/cloudflare-sg"
vpc_id = "${var.vpc_id}"
}
```
18 changes: 18 additions & 0 deletions aws/cloudflare-sg/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module "cf_ips" {
source = "github.com/wycliffe-usa/terraform-modules//cloudflare/ips?ref=1.7.1"
}

resource "aws_security_group" "cloudflare_https" {
name = "cloudflare-https"
description = "Allow HTTPS traffic from Cloudflare"
vpc_id = var.vpc_id
}

resource "aws_security_group_rule" "cloudflare_ipv4" {
type = "ingress"
from_port = 443
to_port = 443
protocol = "tcp"
security_group_id = aws_security_group.cloudflare_https.id
cidr_blocks = module.cf_ips.ipv4_cidrs
}
7 changes: 7 additions & 0 deletions aws/cloudflare-sg/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "id" {
value = aws_security_group.cloudflare_https.id
}

output "name" {
value = aws_security_group.cloudflare_https.name
}
3 changes: 3 additions & 0 deletions aws/cloudflare-sg/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "vpc_id" {
type = string
}
11 changes: 11 additions & 0 deletions aws/cloudflare-sg/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

terraform {
required_version = ">= 1.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.0.0, < 6.0.0"
}
}
}

0 comments on commit e8185df

Please sign in to comment.