π¦ Lab 3: Terraform Modules (λͺ¨λ νμ©)
λͺ©ν: Terraform Registryμ μλ κ²μ¦λ μ€νμμ€ λͺ¨λ(terraform-google-modules)μ μ¬μ©νμ¬ λ³΅μ‘ν λ€νΈμν¬ κ΅¬μ±μ λ¨ λͺ μ€λ‘ ꡬνν΄λ΄
λλ€.
1. main.tf μμ± (Registry λͺ¨λ μ¬μ©)
μμ
λλ ν 리: terraform-labs/lab3/
provider "google" {
region = "us-central1"
}
# Googleμ΄ μ 곡νλ 곡μ λ€νΈμν¬ λͺ¨λ μ¬μ©
module "network" {
source = "terraform-google-modules/network/google"
version = "~> 6.0"
network_name = "terraform-vpc-module"
project_id = "[YOUR_PROJECT_ID]" # β¨ λ³ΈμΈ νλ‘μ νΈ ID μ
λ ₯ νμ
subnets = [
{
subnet_name = "subnet-01"
subnet_ip = "10.10.10.0/24"
subnet_region = "us-central1"
},
{
subnet_name = "subnet-02"
subnet_ip = "10.10.20.0/24"
subnet_region = "us-west1"
}
]
}
# λͺ¨λμ΄ λ§λ μλΈλ·μ VM μμ±
resource "google_compute_instance" "vm_module" {
name = "vm-from-module"
machine_type = "e2-micro"
zone = "us-central1-a"
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
}
}
network_interface {
# λͺ¨λμ μΆλ ₯κ°(Output) μ°Έμ‘° λ°©μ
subnetwork = module.network.subnets_names[0]
access_config {}
}
}2. μ€μ΅ κ°μ΄λ
terraform init: λͺ¨λ(terraform-google-modules/network/google)μ λ€μ΄λ‘λν©λλ€. μκ°μ΄ μ‘°κΈ κ±Έλ¦½λλ€.terraform apply:- λ΄κ° μΌμΌμ΄
google_compute_network,subnetwork,firewall리μμ€λ₯Ό μ μνμ§ μμλ λͺ¨λμ΄ μμμ λ€ λ§λ€μ΄μ€λλ€. - Tip: λͺ¨λμ μ°λ©΄ μ½λκ° ν¨μ¬ κ°κ²°ν΄μ§λλ€.
- λ΄κ° μΌμΌμ΄
terraform destroy: μμ±λ λͺ¨λ 리μμ€(VPC, μλΈλ· λ±) μΌκ΄ μμ .
3. π€ Gemini Prompt Tip (μ μ μμ²λ²)
λͺ¨λ μ¬μ© μ μ λ ₯ λ³μ(Input Variables)λ₯Ό λͺ νν μ§μ νλ κ²μ΄ μ€μν©λλ€.
Prompt:
Generate Terraform configuration using the 'terraform-google-modules/network/google' module based on the following specifications: * Module Source: terraform-google-modules/network/google * Network Name: terraform-vpc-module * Project ID: [YOUR_PROJECT_ID] * Subnet 1: subnet-01 (10.10.10.0/24 in us-central1) * Subnet 2: subnet-02 (10.10.20.0/24 in us-west1) * Output: Use the created subnet-01 for a new e2-micro VM instance.
Geminiκ° λ³΅μ‘ν λͺ¨λ λΈλ‘(module "network" { ... })μ μ νν λ¬Έλ²μΌλ‘ μμ±ν΄μ€λλ€.
Supported by gemini-3.0-pro preview