Day 4 - 클라우드 프로바이더
AWS · GCP 프로바이더로 실제 리소스 선언
목차
학습 목표
- provider 블록 설정
- 인증 방식 이해 (로컬 CLI 자격증명)
- 작은 리소스 1개 plan/apply (실습 계정)
AWS 프로바이더
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" {
region = "ap-northeast-2"
}
# 예: S3 버킷 (이름 전역 유일 — 실습 시 고유 접미사)
resource "aws_s3_bucket" "demo" {
bucket = "pista-tf-demo-${random_id.suf.hex}"
}
resource "random_id" "suf" {
byte_length = 4
}
사전: aws configure 또는 환경 변수 AWS_ACCESS_KEY_ID 등.
관련 학습: AWS 모듈, AWS CLI 노트.
GCP 프로바이더
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> 5.0"
}
}
}
provider "google" {
project = var.project_id
region = "asia-northeast3"
}
resource "google_storage_bucket" "demo" {
name = "pista-tf-demo-${random_id.suf.hex}"
location = "ASIA-NORTHEAST3"
}
사전: gcloud auth application-default login, 프로젝트 결제/API 활성화.
관련 학습: GCP 모듈.
공통 실무 체크
- state 원격 저장 (S3/GCS) + 잠금
- CI에서
plan결과를 PR 코멘트로 -
apply는 main 병합 후 또는 승인 후 - destroy 전 plan 확인 — 실수 삭제 방지