Skip to content

Commit

Permalink
terraform 0.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamlesh committed Aug 12, 2019
0 parents commit 1a9f6be
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


9 changes: 9 additions & 0 deletions example/example.tf
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]
}
42 changes: 42 additions & 0 deletions main.tf
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}"
}
4 changes: 4 additions & 0 deletions outputs.tf
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))}"
}
58 changes: 58 additions & 0 deletions variables.tf
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 = []
}

0 comments on commit 1a9f6be

Please sign in to comment.