Skip to content

Commit

Permalink
Merge pull request #1 from nitinda/terraform-12/master
Browse files Browse the repository at this point in the history
Terraform 12/master
  • Loading branch information
nitinda authored Mar 17, 2020
2 parents 143b2ac + a470e86 commit 185bdb2
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
11 changes: 11 additions & 0 deletions output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
output "id" {
value = aws_security_group.security_group.id
}

output "arn" {
value = aws_security_group.security_group.arn
}

output "name" {
value = aws_security_group.security_group.name
}
41 changes: 41 additions & 0 deletions security-groups.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
resource "aws_security_group" "security_group" {
name_prefix = var.name_prefix
description = var.description
vpc_id = var.vpc_id
revoke_rules_on_delete = var.revoke_rules_on_delete
tags = var.tags

lifecycle {
create_before_destroy = true
}

dynamic "ingress" {
for_each = var.ingress_rules
content {
from_port = lookup(ingress.value, "from_port", null)
to_port = lookup(ingress.value, "to_port", null)
protocol = lookup(ingress.value, "protocol", null)
cidr_blocks = lookup(ingress.value, "cidr_blocks", [])
description = lookup(ingress.value, "description", null)
self = lookup(ingress.value, "self", false)
security_groups = lookup(ingress.value, "security_groups", [])
ipv6_cidr_blocks = lookup(ingress.value, "ipv6_cidr_blocks", [])
prefix_list_ids = lookup(ingress.value, "prefix_list_ids", [])
}
}

dynamic "egress" {
for_each = var.egress_rules
content {
from_port = lookup(egress.value, "from_port", null)
to_port = lookup(egress.value, "to_port", null)
protocol = lookup(egress.value, "protocol", null)
cidr_blocks = lookup(egress.value, "cidr_blocks", [])
description = lookup(egress.value, "description", null)
self = lookup(egress.value, "self", false)
security_groups = lookup(egress.value, "security_groups", [])
ipv6_cidr_blocks = lookup(egress.value, "ipv6_cidr_blocks", [])
prefix_list_ids = lookup(egress.value, "prefix_list_ids", [])
}
}
}
34 changes: 34 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
variable "name_prefix" {
description = "Creates a unique name beginning with the specified prefix."
}

variable "description" {
description = "The security group description. Defaults to Managed by Terraform."
}

variable "revoke_rules_on_delete" {
description = "Instruct Terraform to revoke all of the Security Groups attached ingress and egress rules before deleting the rule itself."
type = bool
default = false
}

variable "vpc_id" {
description = "The VPC ID."
}

variable "tags" {
description = "A mapping of tags to assign to the resource."
type = map(string)
}

variable "ingress_rules" {
description = "Ingress rules for security group"
type = any
default = []
}

variable "egress_rules" {
description = "Egress rules for security group"
type = any
default = []
}

0 comments on commit 185bdb2

Please sign in to comment.