Skip to main content

Lab 36: Security Group Variable Setup Using Terraform

The Nautilus DevOps team is enhancing infrastructure automation and needs to provision a Security Group using Terraform with specific configurations.

For this task, create an AWS Security Group using Terraform with the following requirements:

  1. The Security Group name datacenter-sg should be stored in a variable named KKE_sg.

Note:

    1. The configuration values should be stored in a variables.tf file.
    1. The Terraform script should be structured with a main.tf file referencing variables.tf.
  1. The Terraform working directory is /home/bob/terraform.

  2. Right-click under the EXPLORER section in VS Code and select Open in Integrated Terminal to launch the terminal.

# /home/bob/terraform/variables.tf
variable "KKE_sg" {
description = "The name for the Security Group"
type = string
default = "datacenter-sg"
}

# /home/bob/terraform/main.tf

# Define the Security Group resource
resource "aws_security_group" "datacenter" {
name = var.KKE_sg
description = "Security Group for datacenter services"

# Optional: Default ingress/egress rules for illustration, though not explicitly required by the prompt
ingress {
description = "Allow all from within the Security Group"
from_port = 0
to_port = 0
protocol = "-1"
self = true
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}

tags = {
Name = var.KKE_sg
}
}
terraform init
# or apply forcefully without creating plan and applying it
terraform apply -auto-approve