Open hoangquochung1110 opened 2 months ago
The main differences between locals and data sources in Terraform are:
locals { common_tags = { Environment = var.environment Project = var.project_name Owner = "DevOps Team" } } resource "aws_instance" "example" { ami = "ami-12345678" instance_type = "t2.micro" tags = local.common_tags }
data "aws_vpc" "existing" { filter { name = "tag:Name" values = ["main-vpc"] } } resource "aws_subnet" "example" { vpc_id = data.aws_vpc.existing.id cidr_block = "10.0.1.0/24" }
The main differences between locals and data sources in Terraform are:
Locals
Data Sources