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:
- The Security Group name
datacenter-sgshould be stored in a variable namedKKE_sg.
Note:
-
- The configuration values should be stored in a
variables.tffile.
- The configuration values should be stored in a
-
- The Terraform script should be structured with a
main.tffile referencingvariables.tf.
- The Terraform script should be structured with a
-
The Terraform working directory is
/home/bob/terraform. -
Right-click under the
EXPLORERsection inVS Codeand selectOpen in Integrated Terminalto 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