-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from nitinda/terraform-12/master
Terraform 12/master
- Loading branch information
Showing
3 changed files
with
86 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,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 | ||
} |
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,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", []) | ||
} | ||
} | ||
} |
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,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 = [] | ||
} |