Skip to main content
InterviewHubPRO
Section Overview
Q3

Question 3 of 50

Part 1: Terraform Core Architecture, HCL & Providers (1 - 15)

6%
Terraform & IaC (50 Qs)•Part 1: Terraform Core Architecture, HCL & Providers (1 - 15)

Explain HCL Syntax Fundamentals: Variables, Locals, Outputs, and Data Sources.

senior LevelCode ExampleFormsCI/CD & DevOpsSystem Design

In Simple Words:

  • Variables (variable): Configurable parameters passed into modules (can have default values, types, and validation rules).
  • Locals (locals): Internal computed variables or constants scoped to the module to prevent repetitive expressions.
  • Outputs (output): Return values exported by a module, printed to the console or consumed by other modules.
  • Data Sources (data): Read-only queries that fetch information about existing infrastructure outside Terraform (e.g. latest Amazon Linux AMI ID).
hcl
variable "environment" {
  type        = string
  description = "Target deployment environment"
  default     = "production"
}

locals {
  common_tags = {
    Environment = var.environment
    ManagedBy   = "Terraform"
  }
}

data "aws_vpc" "default" {
  default = true
}

output "vpc_id" {
  value = data.aws_vpc.default.id
}