Pulumi는 TypeScript, Python, Go 등 범용 프로그래밍 언어로 클라우드 인프라를 정의하는 IaC(Infrastructure as Code) 플랫폼이다. AWS, Azure, GCP, Kubernetes를 지원한다.
| 항목 | Pulumi | Terraform |
|---|
| 언어 | TS/Python/Go/C# | HCL |
| 상태 저장 | Pulumi Cloud / 자체 | S3/원격 백엔드 |
| 테스트 | 단위 테스트 가능 | 제한적 |
| 루프/조건 | 언어 네이티브 | count/for_each |
| 패키지 | npm/pip 등 활용 | 모듈 레지스트리 |
TypeScript 예시: S3 정적 웹사이트
typescript
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// S3 버킷
const bucket = new aws.s3.Bucket("my-website", {
website: {
indexDocument: "index.html",
errorDocument: "error.html",
},
});
// 버킷 정책
const bucketPolicy = new aws.s3.BucketPolicy("bucket-policy", {
bucket: bucket.id,
policy: bucket.arn.apply(arn => JSON.stringify({
Version: "2012-10-17",
Statement: [{
Effect: "Allow",
Principal: "*",
Action: "s3:GetObject",
Resource: `${arn}/*`,
}],
})),
});
export const websiteUrl = bucket.websiteEndpoint;
주요 명령어
bash
# 프로젝트 생성
pulumi new aws-typescript
# 미리보기
pulumi preview
# 배포
pulumi up
# 스택 출력 확인
pulumi stack output
# 스택 삭제
pulumi destroy
스택과 설정
typescript
const config = new pulumi.Config();
const env = config.require("environment");
const instanceType = config.get("instanceType") ?? "t3.micro";
// 환경별 설정
pulumi config set environment production
pulumi config set instanceType t3.large
단위 테스트
typescript
import * as pulumi from "@pulumi/pulumi";
pulumi.runtime.setMocks({
newResource: (args) => ({ id: `${args.name}-id`, state: args.inputs }),
call: (args) => ({ outputs: {} }),
});
describe("S3 버킷 테스트", () => {
it("버킷이 버전 관리를 활성화해야 한다", async () => {
const infra = await import("../index");
const bucket = infra.bucket;
const versioning = await bucket.versioning;
expect(versioning?.enabled).toBe(true);
});
});