-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kamlesh
committed
Aug 12, 2019
0 parents
commit 1a9f6be
Showing
5 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module "security_group" { | ||
source = "../" | ||
name = "security-group" | ||
application = "clouddrove" | ||
environment = "test" | ||
vpc_id = "vpc-3242342342432" | ||
cidr_blocks = ["10.0.0.0/16"] | ||
allowed_ports = [22, 80] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
locals { | ||
security_group_count = "${var.create_default_security_group == "true" ? 1 : 0}" | ||
} | ||
|
||
module "labels" { | ||
source = "git::https://github.com/clouddrove/terraform-lables.git?ref=tags/0.11.0" | ||
application = "${var.application}" | ||
name = "${var.name}" | ||
environment = "${var.environment}" | ||
} | ||
|
||
resource "aws_security_group" "default" { | ||
count = "${local.security_group_count}" | ||
name = "${module.labels.id}" | ||
vpc_id = "${var.vpc_id}" | ||
description = "Instance default security group (only egress access is allowed)" | ||
tags = "${module.labels.tags}" | ||
|
||
lifecycle { | ||
create_before_destroy = true | ||
} | ||
} | ||
|
||
resource "aws_security_group_rule" "egress" { | ||
count = "${var.create_default_security_group == "true" ? 1 : 0}" | ||
type = "egress" | ||
from_port = 0 | ||
to_port = 65535 | ||
protocol = "-1" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
security_group_id = "${aws_security_group.default.id}" | ||
} | ||
|
||
resource "aws_security_group_rule" "ingress" { | ||
count = "${var.create_default_security_group == "true" ? length(compact(var.allowed_ports)) : 0}" | ||
type = "ingress" | ||
from_port = "${element(var.allowed_ports, count.index)}" | ||
to_port = "${element(var.allowed_ports, count.index)}" | ||
protocol = "tcp" | ||
cidr_blocks = ["${var.cidr_blocks}"] | ||
security_group_id = "${aws_security_group.default.id}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
output "security_group_ids" { | ||
description = "IDs on the AWS Security Groups associated with the instance" | ||
value = "${compact(concat(list(var.create_default_security_group == "true" ? join("", aws_security_group.default.*.id) : ""), var.security_groups))}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
variable "create_default_security_group" { | ||
description = "Create default Security Group with only Egress traffic allowed" | ||
default = "true" | ||
} | ||
|
||
variable "vpc_id" { | ||
description = "The ID of the VPC that the instance security group belongs to" | ||
default = "" | ||
} | ||
|
||
variable "allowed_ports" { | ||
type = "list" | ||
description = "List of allowed ingress ports" | ||
default = [] | ||
} | ||
|
||
variable "application" { | ||
type = "string" | ||
description = "application (e.g. `cp` or `clouddrove`)" | ||
} | ||
|
||
variable "environment" { | ||
type = "string" | ||
description = "Environment (e.g. `prod`, `dev`, `staging`)" | ||
} | ||
|
||
variable "name" { | ||
description = "Name (e.g. `bastion` or `db`)" | ||
} | ||
|
||
variable "delimiter" { | ||
default = "-" | ||
description = "Delimiter to be used between `name`, `namespace`, `stage`, etc." | ||
} | ||
|
||
variable "attributes" { | ||
description = "Additional attributes (e.g. `1`)" | ||
type = "list" | ||
default = [] | ||
} | ||
|
||
variable "tags" { | ||
description = "Additional tags" | ||
type = "map" | ||
default = {} | ||
} | ||
|
||
variable "cidr_blocks" { | ||
description = "List of CIDR blocks" | ||
type = "list" | ||
default = [] | ||
} | ||
|
||
variable "security_groups" { | ||
description = "List of Security Group IDs allowed to connect to the instance" | ||
type = "list" | ||
default = [] | ||
} |