What is Terraform and how does its declarative model work?
basicTerraform is an infrastructure-as-code tool: you declare desired resources in HCL, and Terraform computes the difference between desired config, recorded state and real infrastructure, then applies the needed API calls through providers.
terraform {
required_providers {
aws = { source = "hashicorp/aws", version = "~> 5.0" }
}
}
resource "aws_s3_bucket" "logs" {
bucket = "acme-orders-logs"
}- Core loop:
init(download providers/modules, configure backend),plan,apply,destroy. - Resources form a dependency graph from references; independent ones are created in parallel.
- Is order in the file significant? No, the dependency graph determines order.
- What does
~> 5.0allow? Any 5.x version, not 6.0.