본문 바로가기
Boaz/Data Pipeline

[Data Engineering Zoomcamp #2] GCP, Terraform

by 남디윤 2025. 3. 31.

저는 윈도우 powershell + git bash 로 진행했습니다!

 

https://github.com/DataTalksClub/data-engineering-zoomcamp

 

GitHub - DataTalksClub/data-engineering-zoomcamp: Data Engineering Zoomcamp is a free nine-week course that covers the fundament

Data Engineering Zoomcamp is a free nine-week course that covers the fundamentals of data engineering. - DataTalksClub/data-engineering-zoomcamp

github.com

 

 


 

목차

🌏 Terraform

Introduction Terraform: Concepts and Overview, a primer

Terraform Basics: Simple one file Terraform Deployment

Deployment with a Variables File

 

챕터1_2. GCP Terraform

🌏 Terraform

Introduction Terraform: Concepts and Overview, a primer

  • https://www.youtube.com/watch?v=s2bOYDCKl_M&list=PL3MmuxUbc_hJed7dXYoJw8DoCuVHhGEQb&index=12
  • Terraforming: 생명체가 살 수 있는 조건을 만드는 과정
  • HashiCorp Terraform: 클라우드와 온프레미스 리소스를 정의할 수 있는 인프라 코드 도구
  • Terraform을 사용하는 이유
    • 간편하게 파일로 정의하여 인프라를 추적
    • 쉬운 협업
    • 재현성
    • 리소스 제거 보증
  • Terraform이 해주지 않는 것
    • 인프라 업데이트 코드를 관리 X
    • 불변 리소스를 변경할 수 있는 기능 제공 X
    • 정의되지 않은 리소스를 관리하는데 사용 X
  • Terraform=Infrastructure as code
    • Providers: 리소스를 관리하고 통신할 수 있도록 허용하는 코드
    • Command: init, plan, apply, destroy
  • 설치

 

 

Terraform Basics: Simple one file Terraform Deployment

 

  • 실습
    • key 설정
$env:GOOGLE_CREDENTIALS = "C:\Users\82105\zoomcamp\1_terraform\keys\my-creds.json"
  • 실습
    • terraform init: 초기화 작업
# main.tf
terraform {
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "6.27.0"
    }
  }
}

provider "google" {
  project     = "bold-mantis-452207-g9"
  region      = "us-central1"
}
terraform init
  • 실습
    • terraform plan: 수정된 부분만 반영
# main.tf
terraform {
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "6.27.0"
    }
  }
}

provider "google" {
  project     = "bold-mantis-452207-g9"
  region      = "us-central1"
}

resource "google_storage_bucket" "demo-bucket" {
  name          = "bold-mantis-452207-g9-terra-bucket"
  location      = "US"
  force_destroy = true

  lifecycle_rule {
    condition {
      age = 1
    }
    action {
      type = "AbortIncompleteMultipartUpload"
    }
  }
}
terraform plan
  • 실습
    • terraform apply: 배포
terraform apply

 

 

  • 실습
    • terraform destroy
terraform destroy

 

 

 

 

Deployment with a Variables File

terraform {
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "6.27.0"
    }
  }
}

provider "google" {
  project     = "bold-mantis-452207-g9"
  region      = "us-central1"
}

resource "google_storage_bucket" "demo-bucket" {
  name          = "bold-mantis-452207-g9-terra-bucket"
  location      = "US"
  force_destroy = true

  lifecycle_rule {
    condition {
      age = 1
    }
    action {
      type = "AbortIncompleteMultipartUpload"
    }
  }
}

resource "google_bigquery_dataset" "demo_dataset" {
  dataset_id = "demo_dataset"
}
terraform apply

 

 

 

  • 실습
    • 변수 설정
# main.tf
terraform {
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "6.27.0"
    }
  }
}

provider "google" {
  credentials = file(var.credentials)
  project     = var.project
  region      = var.region
}

resource "google_storage_bucket" "demo-bucket" {
  name          = var.gcs_bucket_name
  location      = var.location
  force_destroy = true

  lifecycle_rule {
    condition {
      age = 1
    }
    action {
      type = "AbortIncompleteMultipartUpload"
    }
  }
}

resource "google_bigquery_dataset" "demo_dataset" {
  dataset_id = var.bq_dataset_name
  location=var.location
}
# variables.tf
variable "credentials" {
  description = "My Credentials"
  default     = "./keys/my-creds.json"
}

variable "project" {
  description = "Project"
  default     = "bold-mantis-452207-g9"
}

variable "region" {
  description = "Region"
  default     = "us-central1"
}

variable "location" {
  description = "Project Location"
  default     = "US"
}

variable "bq_dataset_name" {
  description = "My BigQuery Dataset Name"
  default     = "demo_dataset"
}

variable "gcs_bucket_name" {
  description = "My Storage Bucket Name"
  default     = "bold-mantis-452207-g9-terra-bucket"
}

variable "gcs_storage_class" {
  description = "Bucket Storage Class"
  default     = "STANDARD"
}

'Boaz > Data Pipeline' 카테고리의 다른 글

[Data Engineering Zoomcamp #1] Docker, SQL  (0) 2025.03.28