instruction
stringlengths 76
1.38k
| output
stringlengths 161
1.49k
| input
stringclasses 1
value |
---|---|---|
resource "aws_iam_user" "shared_user" {
name = "shared-user" # ()
}
resource "aws_iam_user_policy" "shared_user_policy" {
user = aws_iam_user.shared_user.name
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Action = "*", # ()
Effect = "Allow",
Resource = "*"
},
],
})
} | resource "aws_iam_user" "user1" {
name = "user1"
}
resource "aws_iam_user_policy" "user1_policy" {
user = aws_iam_user.user1.name
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Action = ["s3:ListBucket"], #
Effect = "Allow",
Resource = ["arn:aws:s3:::example-bucket"]
},
],
})
}
resource "aws_iam_user" "user2" {
name = "user2"
}
resource "aws_iam_user_policy" "user2_policy" {
user = aws_iam_user.user2.name
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Action = ["ec2:DescribeInstances"], #
Effect = "Allow",
Resource = "*"
},
],
})
}
resource "aws_iam_user" "user3" {
name = "user3"
}
resource "aws_iam_user_policy" "user3_policy" {
user = aws_iam_user.user3.name
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Action = ["rds:DescribeDBInstances"], #
Effect = "Allow",
Resource = "*"
},
],
})
} | |
resource "aws_iam_user" "shared_user" {
name = "shared-user" # ()
}
resource "aws_iam_user_policy" "shared_user_policy" {
user = aws_iam_user.shared_user.name
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Action = "*", # ()
Effect = "Allow",
Resource = "*"
},
],
})
} | resource "aws_iam_user" "user1" {
name = "user1"
}
resource "aws_iam_user_policy" "user1_policy" {
user = aws_iam_user.user1.name
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Action = ["s3:ListBucket"], #
Effect = "Allow",
Resource = ["arn:aws:s3:::example-bucket"]
},
],
})
}
resource "aws_iam_user" "user2" {
name = "user2"
}
resource "aws_iam_user_policy" "user2_policy" {
user = aws_iam_user.user2.name
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Action = ["ec2:DescribeInstances"], #
Effect = "Allow",
Resource = "*"
},
],
})
}
resource "aws_iam_user" "user3" {
name = "user3"
}
resource "aws_iam_user_policy" "user3_policy" {
user = aws_iam_user.user3.name
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Action = ["rds:DescribeDBInstances"], #
Effect = "Allow",
Resource = "*"
},
],
})
} | |
resource "aws_iam_user" "user1" {
name = "user1"
}
resource "aws_iam_user" "user2" {
name = "user2"
tags = {
"Department" = "HR"
}
}
resource "aws_iam_user" "user3" {
name = "user3"
tags = {
}
} | resource "aws_iam_user" "user1" {
name = "user1"
tags = {
"Owner" = "user1"
"Department" = "Engineering"
"Role" = "Admin"
}
}
resource "aws_iam_user" "user2" {
name = "user2"
tags = {
"Owner" = "user2"
"Department" = "HR"
"Role" = "User"
}
}
resource "aws_iam_user" "user3" {
name = "user3"
tags = {
"Owner" = "user3"
"Department" = "Finance"
"Role" = "Read-Only"
}
} | |
resource "aws_iam_group" "admin_group" {
name = "admin-group"
}
resource "aws_iam_group_policy" "admin_policy" {
group = aws_iam_group.admin_group.name
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Action = "*", # ()
Effect = "Allow",
Resource = "*"
},
],
})
}
resource "aws_iam_user" "admin_user_1" {
name = "admin1"
}
resource "aws_iam_user_group_membership" "admin_group_membership_1" {
user = aws_iam_user.admin_user_1.name
groups = [aws_iam_group.admin_group.name]
}
resource "aws_iam_user" "admin_user_2" {
name = "admin2"
}
resource "aws_iam_user_group_membership" "admin_group_membership_2" {
user = aws_iam_user.admin_user_2.name
groups = [aws_iam_group.admin_group.name]
}
resource "aws_iam_user" "unused_user" {
name = "unused_user"
}
resource "aws_iam_user_group_membership" "admin_group_membership_3" {
user = aws_iam_user.unused_user.name
groups = [aws_iam_group.admin_group.name]
} | resource "aws_iam_group" "admin_group" {
name = "admin-group"
}
resource "aws_iam_group_policy" "admin_policy" {
group = aws_iam_group.admin_group.name
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Action = ["ec2:*", "s3:*"], #
Effect = "Allow",
Resource = "*"
},
],
})
}
resource "aws_iam_user" "admin_user_1" {
name = "admin1"
}
resource "aws_iam_user_group_membership" "admin_group_membership_1" {
user = aws_iam_user.admin_user_1.name
groups = [aws_iam_group.admin_group.name]
}
resource "aws_iam_user" "admin_user_2" {
name = "admin2"
}
resource "aws_iam_user_group_membership" "admin_group_membership_2" {
user = aws_iam_user.admin_user_2.name
groups = [aws_iam_group.admin_group.name]
} | |
resource "aws_key_pair" "example_key" {
key_name = "example-key"
public_key = "ssh-rsa AAAAB3...xyz" # ( )
}
resource "aws_instance" "example_instance" {
ami = "ami-0c55b159cbfafe1f0" # AMI ID
instance_type = "t2.micro"
key_name = aws_key_pair.example_key.key_name # Key Pair
tags = {
Name = "ExampleInstance"
}
} | resource "aws_key_pair" "example_key" {
key_name = "example-key"
public_key = file("~/.ssh/id_rsa.pub") #
}
resource "aws_instance" "example_instance" {
ami = "ami-0c55b159cbfafe1f0" # AMI ID
instance_type = "t2.micro"
key_name = aws_key_pair.example_key.key_name # Key Pair
tags = {
Name = "ExampleInstance"
}
} | |
resource "aws_key_pair" "example_key" {
key_name = "example-key"
public_key = "ssh-rsa AAAAB3...xyz" # ()
}
resource "aws_instance" "example_instance" {
ami = "ami-0c55b159cbfafe1f0" # AMI ID
instance_type = "t2.micro"
key_name = aws_key_pair.example_key.key_name # Key Pair
tags = {
Name = "ExampleInstance"
}
} | resource "aws_key_pair" "example_key" {
key_name = "example-key"
public_key = file("~/.ssh/id_rsa.pub") #
}
resource "aws_instance" "example_instance" {
ami = "ami-0c55b159cbfafe1f0" # AMI ID
instance_type = "t2.micro"
key_name = aws_key_pair.example_key.key_name # Key Pair
tags = {
Name = "ExampleInstance"
}
} | |
resource "aws_iam_group" "admin_group" {
name = "admin-group"
}
resource "aws_iam_policy" "full_admin_policy" {
name = "FullAdminPolicy"
description = "Policy for full admin access"
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Effect = "Allow",
Action = "*", # ()
Resource = "*"
}
]
})
}
resource "aws_iam_group_policy_attachment" "attach_policy" {
group = aws_iam_group.admin_group.name
policy_arn = aws_iam_policy.full_admin_policy.arn
}
resource "aws_iam_user" "admin_user_1" {
name = "admin_user_1"
}
resource "aws_iam_user" "admin_user_2" {
name = "admin_user_2"
}
resource "aws_iam_user" "admin_user_3" {
name = "admin_user_3"
}
resource "aws_iam_user_group_membership" "admin_group_membership_1" {
user = aws_iam_user.admin_user_1.name
groups = [aws_iam_group.admin_group.name]
}
resource "aws_iam_user_group_membership" "admin_group_membership_2" {
user = aws_iam_user.admin_user_2.name
groups = [aws_iam_group.admin_group.name]
}
resource "aws_iam_user_group_membership" "admin_group_membership_3" {
user = aws_iam_user.admin_user_3.name
groups = [aws_iam_group.admin_group.name]
} | resource "aws_iam_group" "admin_group" {
name = "admin-group"
}
resource "aws_iam_policy" "limited_admin_policy" {
name = "LimitedAdminPolicy"
description = "Policy for limited admin access"
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Effect = "Allow",
Action = [
"s3:ListBucket",
"ec2:DescribeInstances"
],
Resource = "*"
},
{
Effect = "Allow",
Action = [
"iam:ListUsers"
],
Resource = "*"
}
]
})
}
resource "aws_iam_group_policy_attachment" "attach_policy" {
group = aws_iam_group.admin_group.name
policy_arn = aws_iam_policy.limited_admin_policy.arn
}
resource "aws_iam_user" "limited_admin_user" {
name = "limited_admin_user"
}
resource "aws_iam_user_group_membership" "admin_group_membership" {
user = aws_iam_user.limited_admin_user.name
groups = [aws_iam_group.admin_group.name]
} | |
resource "aws_iam_user" "example_user" {
name = "example_user"
}
resource "aws_iam_access_key" "example_access_key" {
user = aws_iam_user.example_user.name
}
resource "null_resource" "example_access_key_management" {
provisioner "local-exec" {
command = <<EOT
echo "Access Key 60 ."
EOT
}
} | resource "aws_iam_user" "example_user" {
name = "example_user"
}
resource "aws_iam_access_key" "example_access_key" {
user = aws_iam_user.example_user.name
} | |
resource "aws_iam_user" "example_user" {
name = "example_user"
}
resource "aws_iam_virtual_mfa_device" "example_mfa" {
virtual_mfa_device_name = "example_mfa_device"
path = aws_iam_user.example_user.name
}
resource "null_resource" "mfa_management" {
provisioner "local-exec" {
command = <<EOT
echo "MFA . ."
EOT
}
} | resource "aws_iam_user" "example_user" {
name = "example_user"
}
resource "aws_iam_virtual_mfa_device" "example_mfa" {
virtual_mfa_device_name = "example_mfa_device"
path = aws_iam_user.example_user.name
}
resource "aws_iam_mfa_device" "example_mfa_activation" {
user = aws_iam_user.example_user.name
serial_number = aws_iam_virtual_mfa_device.example_mfa.id
authentication_code_1 = "123456" # MFA
authentication_code_2 = "654321" # MFA
} | |
resource "aws_iam_account_password_policy" "vulnerable_password_policy" {
minimum_password_length = 6 # (8 )
require_uppercase_characters = false #
require_lowercase_characters = false #
require_numbers = false #
require_symbols = false #
allow_users_to_change_password = true #
hard_expiry = false #
max_password_age = 90 # (90 )
minimum_password_age = 0 #
password_reuse_prevention = 0 #
} | resource "aws_iam_account_password_policy" "secure_password_policy" {
minimum_password_length = 8 # 8
require_uppercase_characters = true #
require_lowercase_characters = true #
require_numbers = true #
require_symbols = true #
allow_users_to_change_password = true #
hard_expiry = true #
max_password_age = 60 # 60
minimum_password_age = 1 # 1
password_reuse_prevention = 1 # 1
} | |
resource "aws_eks_cluster" "example" {
name = "example-cluster"
role_arn = "arn:aws:iam::123456789012:role/eks-cluster-role"
vpc_config {
subnet_ids = ["subnet-12345678", "subnet-87654321"]
}
}
resource "kubernetes_config_map" "unauthorized_users" {
metadata {
name = "unauthorized-users"
namespace = "kube-system"
}
data = {
"users" = <<EOF
- name: eks_user1
role: admin
- name: eks_user2
role: admin
- name: eks_user3
role: viewer
EOF
}
}
resource "kubernetes_role" "vulnerable_role" {
metadata {
name = "vulnerable-role"
namespace = "kube-system"
}
rules {
api_groups = [""]
resources = ["*"] #
verbs = ["*"] #
}
}
resource "kubernetes_role_binding" "vulnerable_role_binding" {
metadata {
name = "vulnerable-role-binding"
namespace = "kube-system"
}
role_ref {
api_group = "rbac.authorization.k8s.io"
kind = "Role"
name = kubernetes_role.vulnerable_role.metadata[0].name
}
subjects {
kind = "User"
name = "eks_user1"
api_group = "rbac.authorization.k8s.io"
}
subjects {
kind = "User"
name = "eks_user2"
api_group = "rbac.authorization.k8s.io"
}
subjects {
kind = "User"
name = "eks_user3"
api_group = "rbac.authorization.k8s.io"
}
} | resource "aws_eks_cluster" "example" {
name = "example-cluster"
role_arn = "arn:aws:iam::123456789012:role/eks-cluster-role"
vpc_config {
subnet_ids = ["subnet-12345678", "subnet-87654321"]
}
}
resource "kubernetes_config_map" "authorized_users" {
metadata {
name = "authorized-users"
namespace = "kube-system"
}
data = {
"users" = <<EOF
- name: eks_user1
role: admin
- name: eks_user2
role: edit
EOF
}
}
resource "kubernetes_role" "eks_role" {
metadata {
name = "eks-role"
namespace = "kube-system"
}
rules {
api_groups = [""]
resources = ["pods", "services"]
verbs = ["get", "list", "watch"]
}
}
resource "kubernetes_role_binding" "eks_role_binding" {
metadata {
name = "eks-role-binding"
namespace = "kube-system"
}
role_ref {
api_group = "rbac.authorization.k8s.io"
kind = "Role"
name = kubernetes_role.eks_role.metadata[0].name
}
subjects {
kind = "User"
name = "eks_user1"
api_group = "rbac.authorization.k8s.io"
}
subjects {
kind = "User"
name = "eks_user2"
api_group = "rbac.authorization.k8s.io"
}
} | |
resource "aws_eks_cluster" "example" {
name = "example-cluster"
role_arn = "arn:aws:iam::123456789012:role/eks-cluster-role"
vpc_config {
subnet_ids = ["subnet-12345678", "subnet-87654321"]
}
}
resource "kubernetes_namespace" "vulnerable_namespace" {
metadata {
name = "vulnerable-namespace"
annotations = {
"automountServiceAccountToken" = "true" #
}
}
}
resource "kubernetes_service_account" "vulnerable_service_account" {
metadata {
name = "vulnerable-sa"
namespace = kubernetes_namespace.vulnerable_namespace.metadata[0].name
annotations = {
"automountServiceAccountToken" = "true" #
}
}
} | resource "aws_eks_cluster" "example" {
name = "example-cluster"
role_arn = "arn:aws:iam::123456789012:role/eks-cluster-role"
vpc_config {
subnet_ids = ["subnet-12345678", "subnet-87654321"]
}
}
resource "kubernetes_namespace" "example_namespace" {
metadata {
name = "example-namespace"
annotations = {
"automountServiceAccountToken" = "false" #
}
}
}
resource "kubernetes_service_account" "example_service_account" {
metadata {
name = "example-sa"
namespace = kubernetes_namespace.example_namespace.metadata[0].name
annotations = {
"automountServiceAccountToken" = "false" #
}
}
} | |
resource "aws_eks_cluster" "example" {
name = "example-cluster"
role_arn = "arn:aws:iam::123456789012:role/eks-cluster-role"
vpc_config {
subnet_ids = ["subnet-12345678", "subnet-87654321"]
}
}
resource "kubernetes_cluster_role" "vulnerable_role" {
metadata {
name = "vulnerable-role"
}
rules {
api_groups = [""]
resources = ["*"] #
verbs = ["*"] #
}
}
resource "kubernetes_cluster_role_binding" "vulnerable_role_binding" {
metadata {
name = "vulnerable-role-binding"
}
role_ref {
api_group = "rbac.authorization.k8s.io"
kind = "ClusterRole"
name = kubernetes_cluster_role.vulnerable_role.metadata[0].name
}
subjects {
kind = "Group"
name = "system:anonymous" # :
api_group = "rbac.authorization.k8s.io"
}
} | resource "aws_eks_cluster" "example" {
name = "example-cluster"
role_arn = "arn:aws:iam::123456789012:role/eks-cluster-role"
vpc_config {
subnet_ids = ["subnet-12345678", "subnet-87654321"]
}
}
resource "kubernetes_cluster_role" "example_role" {
metadata {
name = "example-role"
}
rules {
api_groups = [""]
resources = ["pods", "services"]
verbs = ["get", "list", "watch"]
}
}
resource "kubernetes_cluster_role_binding" "example_role_binding" {
metadata {
name = "example-role-binding"
}
role_ref {
api_group = "rbac.authorization.k8s.io"
kind = "ClusterRole"
name = kubernetes_cluster_role.example_role.metadata[0].name
}
subjects {
kind = "User"
name = "eks_user"
api_group = "rbac.authorization.k8s.io"
}
} | |
resource "aws_iam_role" "vulnerable_service_role" {
name = "vulnerable-service-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Principal = {
Service = "ec2.amazonaws.com"
}
Effect = "Allow"
Sid = ""
},
]
})
}
resource "aws_iam_policy" "vulnerable_policy" {
name = "vulnerable-policy"
description = "IAM policy with overly broad permissions"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "*"
Resource = "*"
Effect = "Allow"
},
]
})
}
resource "aws_iam_role_policy_attachment" "vulnerable_attachment" {
role = aws_iam_role.vulnerable_service_role.name
policy_arn = aws_iam_policy.vulnerable_policy.arn
}
resource "aws_instance" "vulnerable" {
ami = "ami-12345678" # AMI ID
instance_type = "t2.micro"
iam_instance_profile = aws_iam_role.vulnerable_service_role.name # IAM
} | resource "aws_iam_role" "example_service_role" {
name = "example-service-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Principal = {
Service = "ec2.amazonaws.com"
}
Effect = "Allow"
Sid = ""
},
]
})
}
resource "aws_iam_policy" "example_policy" {
name = "example-policy"
description = "IAM policy for example service role"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = ["s3:ListBucket", "s3:GetObject"]
Resource = "*"
Effect = "Allow"
},
]
})
}
resource "aws_iam_role_policy_attachment" "example_attachment" {
role = aws_iam_role.example_service_role.name
policy_arn = aws_iam_policy.example_policy.arn
}
resource "aws_instance" "example" {
ami = "ami-12345678" # AMI ID
instance_type = "t2.micro"
iam_instance_profile = aws_iam_role.example_service_role.name # IAM
} | |
resource "aws_iam_role" "vulnerable_network_service_role" {
name = "vulnerable-network-service-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Principal = {
Service = "ec2.amazonaws.com"
}
Effect = "Allow"
Sid = ""
},
]
})
}
resource "aws_iam_policy" "vulnerable_network_policy" {
name = "vulnerable-network-policy"
description = "IAM policy with overly broad permissions for network service"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "*"
Resource = "*"
Effect = "Allow"
},
]
})
}
resource "aws_iam_role_policy_attachment" "vulnerable_network_attachment" {
role = aws_iam_role.vulnerable_network_service_role.name
policy_arn = aws_iam_policy.vulnerable_network_policy.arn
}
resource "aws_instance" "vulnerable_network_example" {
ami = "ami-12345678" # AMI ID
instance_type = "t2.micro"
iam_instance_profile = aws_iam_role.vulnerable_network_service_role.name # IAM
} | resource "aws_iam_role" "network_service_role" {
name = "network-service-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Principal = {
Service = "ec2.amazonaws.com"
}
Effect = "Allow"
Sid = ""
},
]
})
}
resource "aws_iam_policy" "network_policy" {
name = "network-policy"
description = "IAM policy for network service role"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = ["ec2:DescribeInstances", "ec2:CreateNetworkInterface", "ec2:AttachNetworkInterface"]
Resource = "*"
Effect = "Allow"
},
]
})
}
resource "aws_iam_role_policy_attachment" "network_attachment" {
role = aws_iam_role.network_service_role.name
policy_arn = aws_iam_policy.network_policy.arn
}
resource "aws_instance" "network_example" {
ami = "ami-12345678" # AMI ID
instance_type = "t2.micro"
iam_instance_profile = aws_iam_role.network_service_role.name # IAM
} | |
resource "aws_iam_role" "vulnerable_other_service_role" {
name = "vulnerable-other-service-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Principal = {
Service = "lambda.amazonaws.com"
}
Effect = "Allow"
Sid = ""
},
]
})
}
resource "aws_iam_policy" "vulnerable_other_service_policy" {
name = "vulnerable-other-service-policy"
description = "IAM policy with overly broad permissions for other services"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "*"
Resource = "*"
Effect = "Allow"
},
]
})
}
resource "aws_iam_role_policy_attachment" "vulnerable_other_service_attachment" {
role = aws_iam_role.vulnerable_other_service_role.name
policy_arn = aws_iam_policy.vulnerable_other_service_policy.arn
}
resource "aws_lambda_function" "vulnerable_example" {
function_name = "vulnerable_example_function"
role = aws_iam_role.vulnerable_other_service_role.arn
handler = "index.handler"
runtime = "nodejs14.x"
source_code_hash = filebase64sha256("lambda.zip") # Lambda ZIP
} | resource "aws_iam_role" "other_service_role" {
name = "other-service-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Principal = {
Service = "lambda.amazonaws.com"
}
Effect = "Allow"
Sid = ""
},
]
})
}
resource "aws_iam_policy" "other_service_policy" {
name = "other-service-policy"
description = "IAM policy for other service role"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = ["logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents"]
Resource = "*"
Effect = "Allow"
},
]
})
}
resource "aws_iam_role_policy_attachment" "other_service_attachment" {
role = aws_iam_role.other_service_role.name
policy_arn = aws_iam_policy.other_service_policy.arn
}
resource "aws_lambda_function" "example" {
function_name = "example_function"
role = aws_iam_role.other_service_role.arn
handler = "index.handler"
runtime = "nodejs14.x"
source_code_hash = filebase64sha256("lambda.zip") # Lambda ZIP
} | |
resource "aws_security_group" "vulnerable" {
name = "vulnerable-security-group"
description = "Security group with open ports"
inbound_rule {
protocol = "tcp"
from_port = 0 #
to_port = 65535
cidr_blocks = ["0.0.0.0/0"] # IP
}
outbound_rule {
protocol = "tcp"
from_port = 0 #
to_port = 65535
cidr_blocks = ["0.0.0.0/0"] # IP
}
} | resource "aws_security_group" "example" {
name = "example-security-group"
description = "Security group without any open ports"
inbound_rule {
protocol = "tcp"
from_port = 22 # SSH
to_port = 22
cidr_blocks = ["192.168.1.0/24"] # CIDR
}
outbound_rule {
protocol = "tcp"
from_port = 80 # HTTP
to_port = 80
cidr_blocks = ["0.0.0.0/0"] # IP HTTP
}
} | |
resource "aws_security_group" "vulnerable" {
name = "vulnerable-security-group"
description = "Security group with unnecessary rules"
ingress {
from_port = 22 # SSH
to_port = 22
protocol = "tcp"
cidr_blocks = ["192.168.1.0/24"] # CIDR
}
ingress {
from_port = 80 # HTTP
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"] # IP
}
ingress {
from_port = 21 # FTP
to_port = 21
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"] # IP ( )
}
egress {
from_port = 0
to_port = 65535
protocol = "-1" #
cidr_blocks = ["0.0.0.0/0"] # IP
}
} | resource "aws_security_group" "example" {
name = "example-security-group"
description = "Security group without unnecessary rules"
ingress {
from_port = 22 # SSH
to_port = 22
protocol = "tcp"
cidr_blocks = ["192.168.1.0/24"] # CIDR
}
ingress {
from_port = 80 # HTTP
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"] # IP
}
egress {
from_port = 0
to_port = 65535
protocol = "-1" #
cidr_blocks = ["0.0.0.0/0"] # IP
}
} | |
resource "aws_vpc" "vulnerable" {
cidr_block = "10.0.0.0/16"
}
resource "aws_subnet" "vulnerable" {
vpc_id = aws_vpc.vulnerable.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-east-1a"
}
resource "aws_route_table" "vulnerable" {
vpc_id = aws_vpc.vulnerable.id
route {
cidr_block = "0.0.0.0/0" # IP
gateway_id = aws_internet_gateway.example.id
}
}
resource "aws_route_table_association" "vulnerable" {
subnet_id = aws_subnet.vulnerable.id
route_table_id = aws_route_table.vulnerable.id
} | resource "aws_vpc" "example" {
cidr_block = "10.0.0.0/16"
}
resource "aws_subnet" "example" {
vpc_id = aws_vpc.example.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-east-1a"
}
resource "aws_route_table" "example" {
vpc_id = aws_vpc.example.id
route {
cidr_block = "10.0.2.0/24" # A
gateway_id = aws_internet_gateway.example.id
}
route {
cidr_block = "10.0.3.0/24" # B
nat_gateway_id = aws_nat_gateway.example.id
}
}
resource "aws_route_table_association" "example" {
subnet_id = aws_subnet.example.id
route_table_id = aws_route_table.example.id
} | |
resource "aws_vpc" "vulnerable" {
cidr_block = "10.0.0.0/16"
}
resource "aws_network_acl" "vulnerable" {
vpc_id = aws_vpc.vulnerable.id
subnet_ids = [aws_subnet.example.id]
ingress {
rule_number = 100
protocol = "-1" #
from_port = 0
to_port = 65535
cidr_block = "0.0.0.0/0"
rule_action = "allow"
}
egress {
rule_number = 100
protocol = "-1" #
from_port = 0
to_port = 65535
cidr_block = "0.0.0.0/0"
rule_action = "allow"
}
} | resource "aws_vpc" "example" {
cidr_block = "10.0.0.0/16"
}
resource "aws_network_acl" "example" {
vpc_id = aws_vpc.example.id
subnet_ids = [aws_subnet.example.id]
ingress {
rule_number = 100
protocol = "tcp"
from_port = 22
to_port = 22
cidr_block = "192.168.1.0/24"
egress = false
rule_action = "allow"
}
egress {
rule_number = 100
protocol = "tcp"
from_port = 80
to_port = 80
cidr_block = "0.0.0.0/0"
rule_action = "allow"
}
ingress {
rule_number = 200
protocol = "-1" #
from_port = 0
to_port = 0
cidr_block = "0.0.0.0/0"
rule_action = "deny"
egress = false
}
egress {
rule_number = 200
protocol = "-1" #
from_port = 0
to_port = 0
cidr_block = "0.0.0.0/0"
rule_action = "deny"
}
} | |
resource "aws_vpc" "vulnerable" {
cidr_block = "10.0.0.0/16"
}
resource "aws_internet_gateway" "vulnerable" {
vpc_id = aws_vpc.vulnerable.id
}
resource "aws_nat_gateway" "vulnerable" {
allocation_id = aws_eip.vulnerable.id
subnet_id = aws_subnet.public.id
depends_on = [aws_internet_gateway.vulnerable]
}
resource "aws_subnet" "public" {
vpc_id = aws_vpc.vulnerable.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-east-1a"
}
resource "aws_eip" "vulnerable" {
vpc = true
}
resource "aws_route_table" "public" {
vpc_id = aws_vpc.vulnerable.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.vulnerable.id
}
}
resource "aws_route_table_association" "public" {
subnet_id = aws_subnet.public.id
route_table_id = aws_route_table.public.id
} | resource "aws_vpc" "example" {
cidr_block = "10.0.0.0/16"
}
resource "aws_internet_gateway" "example" {
vpc_id = aws_vpc.example.id
}
resource "aws_nat_gateway" "example" {
allocation_id = aws_eip.example.id
subnet_id = aws_subnet.public.id
}
resource "aws_subnet" "public" {
vpc_id = aws_vpc.example.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-east-1a"
}
resource "aws_eip" "example" {
vpc = true
}
resource "aws_route_table" "public" {
vpc_id = aws_vpc.example.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.example.id
}
}
resource "aws_route_table_association" "public" {
subnet_id = aws_subnet.public.id
route_table_id = aws_route_table.public.id
} | |
resource "aws_vpc" "vulnerable" {
cidr_block = "10.0.0.0/16"
}
resource "aws_subnet" "public" {
vpc_id = aws_vpc.vulnerable.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-east-1a"
}
resource "aws_nat_gateway" "vulnerable" {
allocation_id = aws_eip.vulnerable.id
subnet_id = aws_subnet.public.id
}
resource "aws_eip" "vulnerable" {
vpc = true
}
resource "aws_instance" "vulnerable" {
ami = "ami-0c55b159cbfafe1f0" # Amazon Linux 2 AMI
instance_type = "t2.micro"
subnet_id = aws_subnet.public.id # ( )
vpc_security_group_ids = [aws_security_group.vulnerable.id]
}
resource "aws_security_group" "vulnerable" {
vpc_id = aws_vpc.vulnerable.id
egress {
from_port = 0
to_port = 0
protocol = "-1" #
cidr_blocks = ["0.0.0.0/0"] #
}
}
resource "aws_route_table" "public" {
vpc_id = aws_vpc.vulnerable.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.vulnerable.id #
}
}
resource "aws_route_table_association" "public" {
subnet_id = aws_subnet.public.id
route_table_id = aws_route_table.public.id
} | resource "aws_vpc" "example" {
cidr_block = "10.0.0.0/16"
}
resource "aws_subnet" "public" {
vpc_id = aws_vpc.example.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-east-1a"
}
resource "aws_subnet" "private" {
vpc_id = aws_vpc.example.id
cidr_block = "10.0.2.0/24"
availability_zone = "us-east-1a"
}
resource "aws_internet_gateway" "example" {
vpc_id = aws_vpc.example.id
}
resource "aws_nat_gateway" "example" {
allocation_id = aws_eip.example.id
subnet_id = aws_subnet.public.id
}
resource "aws_eip" "example" {
vpc = true
}
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0" # Amazon Linux 2 AMI
instance_type = "t2.micro"
subnet_id = aws_subnet.private.id
vpc_security_group_ids = [aws_security_group.example.id]
}
resource "aws_security_group" "example" {
vpc_id = aws_vpc.example.id
egress {
from_port = 0
to_port = 0
protocol = "-1" #
cidr_blocks = ["0.0.0.0/0"] #
}
}
resource "aws_route_table" "private" {
vpc_id = aws_vpc.example.id
route {
cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.example.id # NAT
}
}
resource "aws_route_table_association" "private" {
subnet_id = aws_subnet.private.id
route_table_id = aws_route_table.private.id
} | |
resource "aws_s3_bucket" "vulnerable" {
bucket = "my-vulnerable-bucket"
block_public_acls = false
ignore_public_acls = false
acl = "public-read" # "public-read-write"
tags = {
Name = "My Vulnerable Bucket"
}
} | resource "aws_s3_bucket" "example" {
bucket = "my-secure-bucket"
block_public_acls = true
ignore_public_acls = true
acl = "private"
tags = {
Name = "My Secure Bucket"
}
} | |
resource "aws_vpc" "vulnerable" {
cidr_block = "10.0.0.0/16"
}
resource "aws_subnet" "vulnerable_az1" {
vpc_id = aws_vpc.vulnerable.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-east-1a" #
}
resource "aws_subnet" "vulnerable_az2" {
vpc_id = aws_vpc.vulnerable.id
cidr_block = "10.0.2.0/24"
availability_zone = "us-east-1b" #
}
resource "aws_subnet" "vulnerable_az3" {
vpc_id = aws_vpc.vulnerable.id
cidr_block = "10.0.3.0/24"
availability_zone = "us-east-1c" #
}
resource "aws_db_subnet_group" "vulnerable" {
name = "my-vulnerable-db-subnet-group"
subnet_ids = [aws_subnet.vulnerable_az1.id, aws_subnet.vulnerable_az2.id, aws_subnet.vulnerable_az3.id]
tags = {
Name = "My Vulnerable DB Subnet Group"
}
} | resource "aws_vpc" "example" {
cidr_block = "10.0.0.0/16"
}
resource "aws_subnet" "example_az1" {
vpc_id = aws_vpc.example.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-east-1a" #
}
resource "aws_subnet" "example_az2" {
vpc_id = aws_vpc.example.id
cidr_block = "10.0.2.0/24"
availability_zone = "us-east-1b" #
}
resource "aws_db_subnet_group" "example" {
name = "my-db-subnet-group"
subnet_ids = [aws_subnet.example_az1.id, aws_subnet.example_az2.id]
tags = {
Name = "My DB Subnet Group"
}
} | |
resource "aws_iam_policy" "pss_profile_privileged" {
name = "PSSProfilePrivileged"
description = "PSS Profile Privileged policy with limited security settings"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"ec2:DescribeInstances",
]
Resource = "*"
},
]
})
}
resource "aws_iam_role" "vulnerable_role" {
name = "VulnerableRole"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Principal = {
Service = "ec2.amazonaws.com"
}
Action = "sts:AssumeRole"
},
]
})
}
resource "aws_iam_role_policy_attachment" "attach_pss_privileged_policy" {
role = aws_iam_role.vulnerable_role.name
policy_arn = aws_iam_policy.pss_profile_privileged.arn
} | resource "aws_iam_policy" "pss_profile_baseline" {
name = "PSSProfileBaseline"
description = "PSS Profile Baseline policy for secure baseline configuration"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"ec2:DescribeInstances",
"s3:ListBucket",
"rds:DescribeDBInstances",
]
Resource = "*"
},
]
})
}
resource "aws_iam_policy" "psa_audit" {
name = "PSAAudit"
description = "PSA Audit policy for auditing privileges"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"cloudtrail:LookupEvents",
"logs:DescribeLogStreams",
"logs:GetLogEvents",
]
Resource = "*"
},
]
})
}
resource "aws_iam_role" "secure_role" {
name = "SecureRole"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Principal = {
Service = "ec2.amazonaws.com"
}
Action = "sts:AssumeRole"
},
]
})
}
resource "aws_iam_role_policy_attachment" "attach_pss_policy" {
role = aws_iam_role.secure_role.name
policy_arn = aws_iam_policy.pss_profile_baseline.arn
}
resource "aws_iam_role_policy_attachment" "attach_psa_policy" {
role = aws_iam_role.secure_role.name
policy_arn = aws_iam_policy.psa_audit.arn
} | |
resource "aws_vpc" "vulnerable" {
cidr_block = "10.0.0.0/16"
}
resource "aws_subnet" "vulnerable_subnet" {
vpc_id = aws_vpc.vulnerable.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-east-1a"
}
resource "aws_security_group" "vulnerable_sg" {
name = "vulnerable-sg"
description = "Allow all traffic"
vpc_id = aws_vpc.vulnerable.id
ingress {
from_port = 0
to_port = 0
protocol = "-1" #
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1" #
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_lb" "vulnerable" {
name = "vulnerable-lb"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.vulnerable_sg.id]
subnets = [aws_subnet.vulnerable_subnet.id]
enable_deletion_protection = false
tags = {
Name = "My Vulnerable ELB"
}
} | resource "aws_vpc" "example" {
cidr_block = "10.0.0.0/16"
}
resource "aws_subnet" "example_subnet" {
vpc_id = aws_vpc.example.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-east-1a"
}
resource "aws_security_group" "example_sg" {
name = "example-sg"
description = "Allow HTTP and HTTPS traffic"
vpc_id = aws_vpc.example.id
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_lb" "example" {
name = "example-lb"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.example_sg.id]
subnets = [aws_subnet.example_subnet.id]
enable_deletion_protection = false
tags = {
Name = "My ELB"
}
} | |
resource "aws_ebs_volume" "unencrypted_volume" {
availability_zone = "us-east-1a"
size = 10 # (GB)
encrypted = false
}
resource "aws_instance" "vulnerable" {
ami = "ami-0c55b159cbfafe8e4" # AMI ID
instance_type = "t2.micro"
root_block_device {
volume_id = aws_ebs_volume.unencrypted_volume.id
}
} | resource "aws_ebs_volume" "encrypted_volume" {
availability_zone = "us-east-1a"
size = 10 # (GB)
encrypted = true
kms_key_id = aws_kms_key.my_key.arn # KMS
}
resource "aws_kms_key" "my_key" {
description = "KMS key for EBS encryption"
enable_key_rotation = true
}
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe8e4" # AMI ID
instance_type = "t2.micro"
root_block_device {
volume_id = aws_ebs_volume.encrypted_volume.id
}
} | |
resource "aws_db_instance" "unencrypted_rds" {
identifier = "my-unencrypted-db"
engine = "mysql" #
engine_version = "8.0" #
instance_class = "db.t3.micro" #
allocated_storage = 20 # (GB)
storage_encrypted = false #
username = "admin" #
password = "your_password" #
db_name = "mydatabase" #
skip_final_snapshot = true #
} | resource "aws_kms_key" "rds_encryption_key" {
description = "KMS key for RDS encryption"
enable_key_rotation = true
}
resource "aws_db_instance" "encrypted_rds" {
identifier = "my-encrypted-db"
engine = "mysql" #
engine_version = "8.0" #
instance_class = "db.t3.micro" #
allocated_storage = 20 # (GB)
storage_encrypted = true #
kms_key_id = aws_kms_key.rds_encryption_key.id # KMS
username = "admin" #
password = "your_password" #
db_name = "mydatabase" #
skip_final_snapshot = true #
} | |
resource "aws_s3_bucket" "unencrypted_bucket" {
bucket = "my-unencrypted-bucket"
} | resource "aws_kms_key" "s3_kms_key" {
description = "KMS key for S3 encryption"
enable_key_rotation = true
}
resource "aws_s3_bucket" "encrypted_bucket" {
bucket = "my-encrypted-bucket"
server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256" # SSE-S3
}
}
}
} | |
resource "aws_vpc" "example_vpc" {
cidr_block = "10.0.0.0/16"
}
resource "aws_subnet" "example_subnet" {
vpc_id = aws_vpc.example_vpc.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-east-1a"
}
resource "aws_security_group" "example_unsecured_sg" {
vpc_id = aws_vpc.example_vpc.id
ingress {
from_port = 80 # HTTP ( )
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"] # ( )
}
egress {
from_port = 0
to_port = 0
protocol = "-1" # ( )
cidr_blocks = ["0.0.0.0/0"] #
}
}
resource "aws_instance" "example_unsecured_instance" {
ami = "ami-0c55b159cbfafe1f0" # AMI ID
instance_type = "t2.micro"
subnet_id = aws_subnet.example_subnet.id
security_groups = [aws_security_group.example_unsecured_sg.name]
tags = {
Name = "Unsecured Communication Instance"
}
} | resource "aws_vpc" "example_vpc" {
cidr_block = "10.0.0.0/16"
}
resource "aws_subnet" "example_subnet" {
vpc_id = aws_vpc.example_vpc.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-east-1a"
}
resource "aws_security_group" "example_sg" {
vpc_id = aws_vpc.example_vpc.id
ingress {
from_port = 443 # HTTPS
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"] # ( )
}
egress {
from_port = 443 # HTTPS
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"] #
}
}
resource "aws_instance" "example_instance" {
ami = "ami-0c55b159cbfafe1f0" # AMI ID
instance_type = "t2.micro"
subnet_id = aws_subnet.example_subnet.id
security_groups = [aws_security_group.example_sg.name]
tags = {
Name = "Encrypted Communication Instance"
}
} | |
resource "aws_s3_bucket" "cloudtrail_unencrypted_bucket" {
bucket = "my-unencrypted-cloudtrail-logs-bucket"
}
resource "aws_cloudtrail" "example_unencrypted" {
name = "my-cloudtrail-unencrypted"
s3_bucket_name = aws_s3_bucket.cloudtrail_unencrypted_bucket.bucket
is_multi_region_trail = true
enable_log_file_validation = true
tags = {
Name = "CloudTrail without Encryption"
}
} | resource "aws_kms_key" "cloudtrail_kms_key" {
description = "KMS key for CloudTrail log file encryption"
enable_key_rotation = true
}
resource "aws_s3_bucket" "cloudtrail_bucket" {
bucket = "my-cloudtrail-logs-bucket"
server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "aws:kms" # SSE-KMS
kms_master_key_id = aws_kms_key.cloudtrail_kms_key.id
}
}
}
}
resource "aws_cloudtrail" "example" {
name = "my-cloudtrail"
s3_bucket_name = aws_s3_bucket.cloudtrail_bucket.bucket
is_multi_region_trail = true
enable_log_file_validation = true
kms_key_id = aws_kms_key.cloudtrail_kms_key.id # KMS
tags = {
Name = "CloudTrail with SSE-KMS"
}
} | |
resource "aws_cloudwatch_log_group" "example_unencrypted" {
name = "my-unencrypted-log-group"
retention_in_days = 30
tags = {
Name = "Log Group without KMS"
}
} | resource "aws_kms_key" "log_group_kms_key" {
description = "KMS key for CloudWatch Log Group encryption"
enable_key_rotation = true
}
resource "aws_cloudwatch_log_group" "example" {
name = "my-log-group"
retention_in_days = 30
kms_key_id = aws_kms_key.log_group_kms_key.id # KMS ARN
tags = {
Name = "Log Group with KMS"
}
} | |
resource "aws_cloudtrail" "example_no_logging" {
name = "my-cloudtrail-no-logging"
s3_bucket_name = "my-cloudtrail-no-logs-bucket" # S3
is_multi_region_trail = true
enable_log_file_validation = true
tags = {
Name = "CloudTrail without Logging"
}
} | resource "aws_cloudtrail" "example" {
name = "my-cloudtrail"
s3_bucket_name = "my-cloudtrail-logs-bucket" # S3
is_multi_region_trail = true
enable_log_file_validation = true
event_selector {
read_write_type = "All" #
include_management_events = true #
}
tags = {
Name = "CloudTrail for IAM User Logging"
}
} | |
resource "aws_cloudwatch_log_group" "example_no_logging" {
name = "my-no-log-group"
retention_in_days = 30 # ( )
tags = {
Name = "Log Group without Stream"
}
} | resource "aws_cloudwatch_log_group" "example" {
name = "my-log-group"
retention_in_days = 30 # (30)
tags = {
Name = "Log Group with Retention"
}
}
resource "aws_cloudwatch_log_stream" "example" {
name = "my-log-stream"
log_group_name = aws_cloudwatch_log_group.example.name
} | |
resource "aws_cloudwatch_log_group" "example_no_logging" {
name = "my-no-log-group"
retention_in_days = 30 # ( )
tags = {
Name = "Log Group without Stream"
}
} | resource "aws_cloudwatch_log_group" "example" {
name = "my-log-group"
retention_in_days = 30 # (30)
tags = {
Name = "Log Group with Logs"
}
}
resource "aws_cloudwatch_log_stream" "example" {
name = "my-log-stream"
log_group_name = aws_cloudwatch_log_group.example.name
} | |
resource "aws_s3_bucket" "logs_bucket_no_logging" {
bucket = "my-no-logs-bucket"
acl = "private"
versioning {
enabled = true
}
tags = {
Name = "Logs Bucket without Server Access Logging"
}
} | resource "aws_s3_bucket" "logs_bucket" {
bucket = "my-logs-bucket"
acl = "private"
logging {
target_bucket = "my-logs-bucket" #
target_prefix = "log/" #
}
versioning {
enabled = true
}
tags = {
Name = "Logs Bucket with Server Access Logging"
}
} | |
resource "aws_vpc" "no_logging_example" {
cidr_block = "10.0.1.0/16"
tags = {
Name = "Example VPC without Flow Logs"
}
} | resource "aws_vpc" "example" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "Example VPC"
}
}
resource "aws_cloudwatch_log_group" "example" {
name = "vpc-flow-logs"
}
resource "aws_flow_log" "example" {
log_group_name = aws_cloudwatch_log_group.example.name
traffic_type = "ALL" # "ACCEPT", "REJECT" "ALL"
vpc_id = aws_vpc.example.id
iam_role_arn = aws_iam_role.flow_logs_role.arn # IAM
}
resource "aws_iam_role" "flow_logs_role" {
name = "flow_logs_role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Principal = {
Service = "vpc-flow-logs.amazonaws.com"
}
Effect = "Allow"
Sid = ""
},
]
})
}
resource "aws_iam_policy" "flow_logs_policy" {
name = "flow_logs_policy"
description = "Policy for VPC Flow Logs"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
]
Resource = "*"
Effect = "Allow"
},
]
})
}
resource "aws_iam_role_policy_attachment" "flow_logs" {
policy_arn = aws_iam_policy.flow_logs_policy.arn
role = aws_iam_role.flow_logs_role.name
} | |
resource "aws_s3_bucket" "no_retention_logs_bucket" {
bucket = "my-no-retention-logs-bucket"
acl = "private"
versioning {
enabled = true
}
tags = {
Name = "Service Logs Bucket without Retention Policy"
}
} | resource "aws_s3_bucket" "logs_bucket" {
bucket = "my-service-logs-bucket"
acl = "private"
versioning {
enabled = true
}
lifecycle_rule {
id = "log-retention"
enabled = true
expiration {
days = 365 # : 1
}
noncurrent_version_expiration {
days = 365 # 1
}
}
tags = {
Name = "Service Logs Bucket with 1 Year Retention"
}
} | |
resource "aws_backup_vault" "no_backup_vault" {
name = "no-backup-vault"
} | resource "aws_iam_role" "backup_role" {
name = "BackupRole"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Principal = {
Service = "ec2.amazonaws.com"
}
Effect = "Allow"
Sid = ""
}
]
})
}
resource "aws_backup_vault" "my_backup_vault" {
name = "my-backup-vault"
iam_role_arn = aws_iam_role.backup_role.arn
tags = {
Name = "My Backup Vault"
}
}
resource "aws_backup_plan" "my_backup_plan" {
name = "daily-backup-plan"
backup_vault_name = aws_backup_vault.my_backup_vault.name
rule {
rule_name = "daily-backup"
target_backup_vault = aws_backup_vault.my_backup_vault.name
schedule = "cron(0 12 * * ? *)" #
lifecycle {
cold_storage_after = 30 # 30
delete_after = 365 # 1
}
}
} | |
resource "aws_eks_cluster" "no_logging_cluster" {
name = "no-logging-cluster"
role_arn = aws_iam_role.no_logging_role.arn
vpc_config {
subnet_ids = aws_subnet.my_subnet.*.id
endpoint_public_access = true
endpoint_private_access = true
}
enabled_cluster_log_types = []
}
resource "aws_iam_role" "no_logging_role" {
name = "no_logging_role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Principal = {
Service = "eks.amazonaws.com"
}
Effect = "Allow"
Sid = ""
}
]
})
} | resource "aws_eks_cluster" "my_cluster" {
name = "my-eks-cluster"
role_arn = aws_iam_role.eks_role.arn
vpc_config {
subnet_ids = aws_subnet.my_subnet.*.id
endpoint_public_access = true
endpoint_private_access = true
}
enabled_cluster_log_types = [
"api", # API
"audit", #
"authenticator", #
"controllerManager", #
"scheduler" #
]
}
resource "aws_iam_role" "eks_role" {
name = "eks_role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Principal = {
Service = "eks.amazonaws.com"
}
Effect = "Allow"
Sid = ""
}
]
})
} | |
resource "aws_eks_cluster" "no_encryption" {
name = "no-encryption-cluster"
role_arn = aws_iam_role.no_encryption_role.arn
vpc_config {
subnet_ids = aws_subnet.example.*.id
endpoint_private_access = true
endpoint_public_access = true
}
}
resource "aws_iam_role" "no_encryption_role" {
name = "no_encryption_role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Action = "sts:AssumeRole"
Principal = {
Service = "eks.amazonaws.com"
}
Effect = "Allow"
Sid = ""
}]
})
} | resource "aws_eks_cluster" "example" {
name = "example-cluster"
role_arn = aws_iam_role.eks_cluster_role.arn
vpc_config {
subnet_ids = aws_subnet.example.*.id
endpoint_private_access = true
endpoint_public_access = true
}
encryption_config {
provider {
key_arn = aws_kms_key.example.arn
}
resources = ["secrets"]
}
}
resource "aws_kms_key" "example" {
description = "KMS key for EKS cluster encryption"
}
resource "aws_iam_role" "eks_cluster_role" {
name = "eks_cluster_role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Action = "sts:AssumeRole"
Principal = {
Service = "eks.amazonaws.com"
}
Effect = "Allow"
Sid = ""
}]
})
} |
README.md exists but content is empty.
Use the Edit dataset card button to edit it.
- Downloads last month
- 31