У нас вы можете посмотреть бесплатно Terraform Tutorial | Terraform Configuration Language Components Explained | Day 11 или скачать в максимальном доступном качестве, видео которое было загружено на ютуб. Для загрузки выберите вариант из формы ниже:
Если кнопки скачивания не
загрузились
НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если возникают проблемы со скачиванием видео, пожалуйста напишите в поддержку по адресу внизу
страницы.
Спасибо за использование сервиса ClipSaver.ru
Hey everyone, welcome to my channel! 👋 🔹 What you’ll learn in this video: Resource Blocks Basic Syntax of a Resource resource "PROVIDER_TYPE" "NAME" { argument1 = value argument2 = value } PROVIDER_TYPE Resource type (e.g., aws_instance) NAME Local name you give the resource Inside {} Configuration arguments Example: AWS EC2 Instance resource "aws_instance" "web_server" { ami = "ami-0c55b159cbfafe1f0" instance_type = "t2.micro" tags = { Name = "MyWebServer" } } 🔎 Explanation aws_instance → EC2 instance resource type web_server → Local Terraform name ami → Machine image ID instance_type → Instance size tags → Metadata Example: AWS S3 Bucket resource "aws_s3_bucket" "app_bucket" { bucket = "my-unique-app-bucket-12345" tags = { Environment = "Dev" } } 🔎 What This Does Creates an S3 bucket Bucket name must be globally unique Adds a tag Example: Azure Resource Group resource "azurerm_resource_group" "rg" { name = "my-resource-group" location = "East US" } This creates a resource group in Microsoft Azure. Example: Google Cloud Compute Instance resource "google_compute_instance" "vm_instance" { name = "my-vm" machine_type = "e2-medium" zone = "us-central1-a" boot_disk { initialize_params { image = "debian-cloud/debian-11" } } network_interface { network = "default" access_config {} } } Important Concept Each resource has: resource "TYPE" "NAME" { You reference it like: aws_instance.web_server.id Format: resource_type.resource_name.attribute Terraform Data Sources ✅ Basic Syntax data "PROVIDER_TYPE" "NAME" { argument = value } You reference it like: data.type.nameattribute Example: Get Latest AWS AMI Instead of hardcoding AMI ID, fetch the latest automatically. data "aws_ami" "latest_amazon_linux" { most_recent = true owners = ["amazon"] filter { name = "name" values = ["amzn2-ami-hvm-*-x86_64-gp2"] } } Now use it in a resource: resource "aws_instance" "web" { ami = data.aws_ami.latest_amazon_linux.id instance_type = "t2.micro" } 🔎 What Happens? Terraform queries Amazon Web Services Gets latest Amazon Linux 2 AMI Uses it to launch EC2 ✅ No hardcoding ✅ Always latest image terraform init terraform appply Example: Get Existing VPC Suppose VPC already exists — don’t recreate it. data "aws_vpc" "existing_vpc" { filter { name = "tag:Name" values = ["production-vpc"] } } Use it: resource "aws_subnet" "new_subnet" { vpc_id = data.aws_vpc.existing_vpc.id cidr_block = "172.31.16.0/20" # change the subnet cidr range } 🔎 What This Does Finds VPC by tag Uses its ID Creates subnet inside it terraform init terraform appply Example: Azure Existing Resource Group data "azurerm_resource_group" "existing_rg" { name = "my-resource-group" } Use it: resource "azurerm_storage_account" "storage" { name = "mystorageaccount123" resource_group_name = data.azurerm_resource_group.existing_rg.name location = data.azurerm_resource_group.existing_rg.location account_tier = "Standard" account_replication_type = "LRS" } This reads an existing resource group in Microsoft Azure. Example: Get Current AWS Account Info data "aws_caller_identity" "current" {} Use it: output "account_id" { value = data.aws_caller_identity.current.account_id } 🔎 What It Returns AWS Account ID User ARN User ID Very useful for dynamic naming. terraform init terraform appply 🎯 Resource vs Data Comparison Feature Resource Data Source Creates infrastructure ✅ Yes ❌ No Reads existing infra ❌ No ✅ Yes Managed by Terraform ✅ Yes ❌ No 🧠 Real-World Scenario Imagine: Network team created VPC Security team created Security Groups You deploy EC2 instances You should: Use data for VPC & SG Use resource for EC2 That’s proper enterprise Terraform design. Notes: https://manjunathaga.blogspot.com/202... 👍 If you’re new to my channel, please **like, subscribe, and share**. More DevOps and Terraform @FreeTrainingCloudDevops