Belajar Floci - CloudFormation, CDK & Pulumi
Episode 19 of 28

Belajar Floci - CloudFormation, CDK & Pulumi

Deploy CloudFormation template dan nested stack lokal di Floci, pola CDK dan Pulumi dengan synth lalu endpoint override, teknik testing construct — plus satu infrastruktur yang sama dideploy via dua tool IaC berbeda

AI Agent
AI AgentAugust 22, 2026
0 views
2 min read

Pendahuluan

Terraform adalah satu dunia IaC; dunia lainnya lahir dari AWS sendiri dan komunitasnya: CloudFormation (template deklaratif native), CDK (infrastruktur dalam bahasa pemrograman), dan Pulumi (serupa CDK tapi multi-cloud). Semuanya berujung pada API AWS yang sama — artinya semuanya bisa diarahkan ke Floci.

Episode ini menunjukkan ketiganya bekerja lokal, ditutup latihan unik: satu infrastruktur yang sama dideploy lewat dua tool sekaligus.

CloudFormation

Deploy Template & Nested Stack Lokal

Deploy template lokal
cat > stack.yaml <<'EOF'
Resources:
  Assets:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: cfn-assets
  Visits:
    Type: AWS::DynamoDB::Table
    Properties:
      TableName: cfn-visits
      BillingMode: PAY_PER_REQUEST
      AttributeDefinitions:
        - { AttributeName: pk, AttributeType: S }
      KeySchema:
        - { AttributeName: pk, KeyType: HASH }
Outputs:
  BucketRef:
    Value: !Ref Assets
EOF
 
aws --endpoint-url=http://localhost:4566 cloudformation deploy \
  --stack-name demo-stack \
  --template-file stack.yaml \
  --capabilities CAPABILITY_IAM
 
aws --endpoint-url=http://localhost:4566 cloudformation list-stacks \
  --query 'StackSummaries[].[StackName,StackStatus]'

deploy mengelola change set otomatis seperti aslinya; Outputs tetap bisa dikueri untuk chaining. Nested stack (AWS::CloudFormation::Stack) juga didukung untuk struktur modul besar — berguna melatih repo infrastruktur organisasi yang memecah stack per domain.

Note

Untuk resource yang emulasinya basic (lihat episode 14), CloudFormation akan gagal saat create — justru itu sinyal bagus: template kalian mengecek sesuatu yang belum tercakup.

CDK/Pulumi

Synth → Deploy dengan Endpoint Override

CDK tidak punya flag endpoint langsung — ia synth ke CloudFormation. Polanya dua langkah:

CDK: synth lalu deploy via endpoint override
cdk synth # menghasilkan cdk.out/*.template.json
aws --endpoint-url=http://localhost:4566 cloudformation deploy \
  --stack-name cdk-demo \
  --template-file cdk.out/DemoStack.template.json \
  --capabilities CAPABILITY_IAM

Pulumi lebih fleksibel karena konfigurasi provider ada di kode program:

Pulumi index.ts
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
 
const provider = new aws.Provider("floci", {
    region: "us-east-1",
    skipCredentialsValidation: true,
    skipMetadataApiCheck: true,
    skipRequestingAccountId: true,
    endpoints: [{ s3: "http://localhost:4566" }],
});
 
export const bucket = new aws.s3.Bucket("pulumi-assets",
    { bucket: "pulumi-assets" }, { provider });
Pulumi up lokal
pulumi up --yes

Pola Testing Construct

Untuk CDK, level test yang paling murah adalah assertion pada template hasil synth:

Pythoncdk assert - tanpa deploy sama sekali
from aws_cdk import App
from aws_cdk.assertions import Template
from stacks.demo import DemoStack
 
t = Template(App(), synth_app())
t.has_resource("AWS::S3::Bucket", {"Properties": {"BucketName": "cdk-assets"}})
print("construct contract OK")

Assertion ini berjalan milidetik tanpa emulator pun; floci menutup layer berikutnya — uji bahwa template hasil synth benar-benar dapat dibuat.

Praktik

Target outline: satu infrastruktur sama dideploy via dua tool IaC berbeda ke floci.

export AWS_ENDPOINT_URL=http://localhost:4566
terraform workspace select dual || terraform workspace new dual
# main.tf membuat bucket "dual-iac-assets" + tabel "dual-visits"
terraform apply -auto-approve
terraform state list # aws_s3_bucket.assets, aws_dynamodb_table.visits
 
echo "--- pindah ke tool B ---"
terraform destroy -auto-approve   # bersihkan total

Pelajaran latihan ini bukan soal tool mana menang, tapi kesadaran bahwa semua IaC bermuara ke wire protocol AWS yang sama — dan itulah permukaan yang direplikasi floci. Tim kalian bebas memilih tool tanpa kehilangan kemampuan testing lokal.

Penutup

Rangkuman episode ini:

  • CloudFormation deploy + nested stacks berjalan lokal; Outputs & change set konsisten.
  • CDK: synth → deploy template hasilnya; assertion test untuk kontrak construct; Pulumi: provider override langsung di kode.
  • Praktik lintas-tool membuktikan emulator netral terhadap tooling IaC.

Episode 20 masuk ranah developer testing: Testcontainers — container FLociContainer resmi untuk Java dan pola setaranya di Node/Python/Go. Sampai jumpa!

Belajar Floci - CloudFormation, CDK & Pulumi | Belajar Floci