46 lines
1.1 KiB
Terraform
46 lines
1.1 KiB
Terraform
resource "aws_security_group" "protected" {
|
|
count = var.protect_from_destroy ? 1 : 0
|
|
|
|
region = var.region
|
|
|
|
name = local.security_group_name
|
|
description = var.security_group.description
|
|
vpc_id = var.vpc_id
|
|
tags = var.security_group.tags
|
|
|
|
lifecycle {
|
|
prevent_destroy = true
|
|
}
|
|
}
|
|
|
|
resource "aws_security_group" "unprotected" {
|
|
count = var.protect_from_destroy ? 0 : 1
|
|
|
|
region = var.region
|
|
|
|
name = local.security_group_name
|
|
description = var.security_group.description
|
|
vpc_id = var.vpc_id
|
|
tags = var.security_group.tags
|
|
}
|
|
|
|
resource "aws_vpc_security_group_ingress_rule" "this" {
|
|
for_each = var.ingress_rules
|
|
|
|
region = var.region
|
|
security_group_id = local.security_group.id
|
|
description = each.value.description
|
|
ip_protocol = each.value.ip_protocol
|
|
from_port = each.value.from_port
|
|
to_port = each.value.to_port
|
|
cidr_ipv4 = each.value.cidr_ipv4
|
|
}
|
|
|
|
resource "aws_vpc_security_group_egress_rule" "all_ipv4" {
|
|
region = var.region
|
|
|
|
security_group_id = local.security_group.id
|
|
ip_protocol = "-1"
|
|
cidr_ipv4 = "0.0.0.0/0"
|
|
}
|