Infrastructure as Code 2025年の進化
IaC市場は2033年までに**$6.14B以上に成長すると予測されています(CAGR 22%超)。2025年、IaCは単純なプロビジョニングからAI駆動のドリフト検出、Policy as Code、Kubernetes-nativeアーキテクチャ**へと進化しました。
2025年の重要シフト
| トレンド | 2023年 | 2025年 |
|---|---|---|
| マルチクラウド平均 | 1.9社 | 2.6社 |
| コンテナ化率 | 60% | 76% |
| GitOps採用 | 50% | 93% |
主要ツール比較
Terraform
Declarative(宣言的)アプローチの業界標準。
# Terraform AWS例
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true
tags = {
Name = "main-vpc"
Environment = "production"
ManagedBy = "terraform"
}
}
resource "aws_subnet" "public" {
count = 3
vpc_id = aws_vpc.main.id
cidr_block = cidrsubnet(aws_vpc.main.cidr_block, 8, count.index)
availability_zone = data.aws_availability_zones.available.names[count.index]
tags = {
Name = "public-subnet-${count.index + 1}"
}
}
resource "aws_eks_cluster" "main" {
name = "main-cluster"
role_arn = aws_iam_role.eks.arn
vpc_config {
subnet_ids = aws_subnet.public[*].id
}
}
強み:
- 最大のエコシステム(ほぼすべてのプロバイダー対応)
- HCL言語の習得が比較的容易
- 豊富なドキュメントとコミュニティ
Pulumi
プログラミング言語でIaCを記述。
// Pulumi TypeScript例
import * as aws from "@pulumi/aws";
import * as pulumi from "@pulumi/pulumi";
const vpc = new aws.ec2.Vpc("main-vpc", {
cidrBlock: "10.0.0.0/16",
enableDnsHostnames: true,
tags: {
Name: "main-vpc",
Environment: "production",
},
});
// ループや条件分岐が自然に使える
const subnets = [0, 1, 2].map((i) =>
new aws.ec2.Subnet(`public-subnet-${i}`, {
vpcId: vpc.id,
cidrBlock: `10.0.${i}.0/24`,
availabilityZone: aws.getAvailabilityZones().then(azs => azs.names[i]),
tags: { Name: `public-subnet-${i + 1}` },
})
);
// 型安全な参照
const cluster = new aws.eks.Cluster("main-cluster", {
vpcConfig: {
subnetIds: subnets.map(s => s.id),
},
});
// 出力のエクスポート
export const clusterEndpoint = cluster.endpoint;
export const kubeconfig = pulumi.interpolate`...`;
強み:
- TypeScript, Python, Go, C#など好みの言語で記述
- 型安全性とIDEサポート
- 複雑なロジックの実装が容易
Crossplane
Kubernetes-nativeなIaCフレームワーク。
# Crossplane CompositeResourceDefinition
apiVersion: apiextensions.crossplane.io/v1
kind: CompositeResourceDefinition
metadata:
name: xdatabases.example.org
spec:
group: example.org
names:
kind: XDatabase
plural: xdatabases
versions:
- name: v1
served: true
referenceable: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
size:
type: string
enum: [small, medium, large]
engine:
type: string
enum: [postgres, mysql]
---
# Composition(実装の詳細)
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: database-aws
spec:
compositeTypeRef:
apiVersion: example.org/v1
kind: XDatabase
resources:
- name: rds
base:
apiVersion: rds.aws.crossplane.io/v1beta1
kind: Instance
spec:
forProvider:
engine: postgres
instanceClass: db.t3.micro
patches:
- fromFieldPath: spec.size
toFieldPath: spec.forProvider.instanceClass
transforms:
- type: map
map:
small: db.t3.micro
medium: db.t3.medium
large: db.t3.large
強み:
- GitOpsネイティブ(Kubernetesマニフェストで管理)
- 抽象化レイヤーによるセルフサービス
- マルチクラウドの統一API
ツール選択ガイド
graph TD
A{Kubernetesが中心?}
A -->|YES| B[Crossplane]
A -->|NO| C{開発者がプログラマー?}
C -->|YES| D[Pulumi]
C -->|NO| E[Terraform]
GitOps統合
Atlantis(Terraform用GitOps)
# atlantis.yaml
version: 3
projects:
- name: production
dir: environments/production
workflow: production
autoplan:
when_modified: ["*.tf", "../modules/**/*.tf"]
enabled: true
workflows:
production:
plan:
steps:
- init
- plan:
extra_args: ["-var-file=production.tfvars"]
apply:
steps:
- apply
ArgoCD + Crossplane
# Crossplane リソースをArgoCDで管理
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: infrastructure
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/myorg/infrastructure
targetRevision: main
path: crossplane
destination:
server: https://kubernetes.default.svc
namespace: crossplane-system
syncPolicy:
automated:
prune: true
selfHeal: true
OpenTofu(オープンソース代替)
HashiCorpのライセンス変更を受けて誕生したTerraformフォーク。
# OpenTofu(Terraform互換)
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
# 既存のTerraformコードがそのまま動作
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t3.micro"
}
OpenTofu選択の理由:
- 完全オープンソース(MPL 2.0)
- Linux Foundation傘下
- Terraform互換
2025年のベストプラクティス
Policy as Code
# OPA/Regoによるポリシー
package terraform.analysis
deny[msg] {
resource := input.resource_changes[_]
resource.type == "aws_s3_bucket"
not resource.change.after.server_side_encryption_configuration
msg := sprintf("S3バケット %s は暗号化が必須です", [resource.address])
}
deny[msg] {
resource := input.resource_changes[_]
resource.type == "aws_security_group_rule"
resource.change.after.cidr_blocks[_] == "0.0.0.0/0"
resource.change.after.from_port == 22
msg := "SSHポートを全世界に公開することは禁止されています"
}
モジュール化
# modules/vpc/main.tf
variable "name" {}
variable "cidr" {}
variable "azs" { type = list(string) }
resource "aws_vpc" "this" {
cidr_block = var.cidr
tags = { Name = var.name }
}
output "vpc_id" {
value = aws_vpc.this.id
}
# 使用側
module "vpc" {
source = "./modules/vpc"
name = "production"
cidr = "10.0.0.0/16"
azs = ["ap-northeast-1a", "ap-northeast-1c"]
}
状態管理
# リモートバックエンド設定
terraform {
backend "s3" {
bucket = "my-terraform-state"
key = "production/terraform.tfstate"
region = "ap-northeast-1"
encrypt = true
dynamodb_table = "terraform-locks"
}
}
今後の展望
2026年に向けて:
・AI駆動のドリフト検出と自動修正
・マルチクラウド状態管理の標準化
・セキュリティ自動スキャンの統合
・GitOpsのさらなる普及
・Kubernetes CRD経由のインフラ管理
まとめ
2025年のIaCは、単純なリソースプロビジョニングからGitOps統合、Policy as Code、Kubernetes-nativeアプローチへと進化しています。Terraformは成熟した選択肢として残りつつ、Pulumiは開発者体験を、CrossplaneはKubernetes統合を重視するチームに適しています。プロジェクトの特性に応じて適切なツールを選択しましょう。
← 一覧に戻る