基于 SOC 职业分类
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/ffsshhttiikk/opencode-agents-skills --skill infrastructure-as-code命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| name | infrastructure-as-code |
| description | Managing and provisioning infrastructure through machine-readable definition files |
| license | MIT |
| compatibility | ["terraform","pulumi","aws-cdk","azure-bicep","google-deployment-manager"] |
| audience | DevOps engineers, cloud architects, platform engineers |
| category | devops |
I provide expertise in Infrastructure as Code (IaC) - defining and managing infrastructure through version-controlled, declarative configuration files. I cover Terraform, Pulumi, AWS CDK, and cloud-native IaC tools for provisioning networks, compute, databases, and services. IaC enables consistent, repeatable, and auditable infrastructure management across multiple environments with full lifecycle control.
# environments/prod/main.tf
terraform {
required_version = "~> 1.7"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.30"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = "~> 2.24"
}
helm = {
source = "hashicorp/helm"
version = "~> 2.12"
}
}
backend "s3" {
bucket = "company-terraform-state"
key = "prod/network/terraform.tfstate"
region = "us-east-1"
encrypt = true
dynamodb_table = "terraform-state-lock"
acl = "bucket-owner-full-control"
}
}
module "vpc" {
source = "../../modules/networking/vpc"
environment = "prod"
cidr_block = "10.0.0.0/16"
azs = ["us-east-1a", "us-east-1b", "us-east-1c"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
enable_nat_gateway = true
single_nat_gateway = false
enable_dns_hostnames = true
enable_dns_support = true
tags = {
Environment = "prod"
ManagedBy = "terraform"
Project = "api-platform"
}
}
module "eks" {
source = "../../modules/compute/eks"
cluster_name = "api-prod-eks"
cluster_version = "1.29"
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnet_ids
cluster_endpoint = "public"
enable_irsa = true
node_groups = {
general = {
instance_types = ["m6i.xlarge", "m5.xlarge"]
min_size = 3
max_size = 20
desired_size = 5
capacity_type = "ON_DEMAND"
},
spot = {
instance_types = ["m6i.2xlarge", "m5.2xlarge", "m5a.2xlarge"]
min_size = 1
max_size = 10
desired_size = 2
capacity_type = "SPOT"
}
}
enable_autoscaling = true
cluster_autoscaler = {
min_size = 1
max_size = 20
}
addons = {
vpc-cni = { version = "v1.16.0-eksbuild.1" }
coredns = { version = "v1.11.1-eksbuild.3" }
kube-proxy = { version = "v1.29.0-eksbuild.2" }
aws-ebs-csi-driver = { version = "v1.25.0-eksbuild.1" }
}
enable_monitoring = true
enable_logging = ["api", "audit", "authenticator", "controllerManager", "scheduler"]
tags = {
Environment = "prod"
Project = "api-platform"
}
}
module "rds_postgres" {
source = "../../modules/data/postgres"
identifier = "api-prod-postgres"
engine = "postgres"
engine_version = "15.5"
instance_class = "db.r6g.2xlarge"
allocated_storage = 500
max_allocated_storage = 1000
db_name = "api_production"
username = "api_admin"
password = random_password.db_password.result
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnet_ids
security_group_ids = [module.vpc.security_group_id]
backup_retention_period = 35
deletion_protection = true
skip_final_snapshot = false
final_snapshot_identifier = "api-prod-postgres-final"
performance_insights_enabled = true
enable_logging = ["postgresql", "upgrade"]
maintenance_window = "sun:02:00-sun:06:00"
backup_window = "08:00-12:00"
tags = {
Environment = "prod"
Project = "api-platform"
}
}
resource "random_password" "db_password" {
length = 32
special = false
}
output "cluster_endpoint" {
value = module.eks.cluster_endpoint
}
output "rds_endpoint" {
value = module.rds_postgres.endpoint
sensitive = true
}
# modules/kubernetes/namespace/main.tf
variable "name" {
description = "Namespace name"
type = string
}
variable "labels" {
description = "Additional labels"
type = map(string)
default = {}
}
variable "annotations" {
description = "Additional annotations"
type = map(string)
default = {}
}
variable "quota" {
description = "Resource quota configuration"
type = object({
limits_cpu = string
limits_memory = string
requests_cpu = string
requests_memory = string
pods = number
services = number
})
default = null
}
variable "network_policy" {
description = "Network policy configuration"
type = object({
default_deny_ingress = bool
default_deny_egress = bool
ingress_cidrs = list(string)
egress_cidrs = list(string)
})
default = null
}
resource "kubernetes_namespace" "this" {
metadata {
name = var.name
labels = var.labels
annotations = var.annotations
}
}
resource "kubernetes_resource_quota" "this" {
count = var.quota != null ? 1 : 0
metadata {
name = "${var.name}-quota"
namespace = kubernetes_namespace.this.metadata[0].name
}
spec {
hard = {
cpu = var.quota.limits_cpu
memory = var.quota.limits_memory
pods = var.quota.pods
}
}
}
resource "kubernetes_network_policy" "this" {
count = var.network_policy != null ? 1 : 0
metadata {
name = "${var.name}-network-policy"
namespace = kubernetes_namespace.this.metadata[0].name
}
spec {
pod_selector {
match_labels = {
"kubernetes.io/metadata.name" = kubernetes_namespace.this.metadata[0].name
}
}
dynamic "ingress" {
for_each = var.network_policy.default_deny_ingress ? [] : [1]
content {
from {
ip_block {
cidr = var.network_policy.ingress_cidrs[count.index]
}
}
}
}
dynamic "egress" {
for_each = var.network_policy.default_deny_egress ? [] : [1]
content {
to {
ip_block {
cidr = var.network_policy.egress_cidrs[count.index]
}
}
}
}
policy_types = ["Ingress", "Egress"]
}
}
output "namespace_name" {
value = kubernetes_namespace.this.metadata[0].name
}
output "namespace_uid" {
value = kubernetes_namespace.this.metadata[0].uid
}
// infrastructure/index.ts
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as kubernetes from "@pulumi/kubernetes";
const config = new pulumi.Config();
const env = pulumi.getStack();
const project = "api-platform";
// VPC Configuration
const vpc = new aws.ec2.Vpc(`${project}-vpc-${env}`, {
cidrBlock: config.require("vpcCidr"),
enableDnsHostnames: true,
enableDnsSupport: true,
tags: {
Name: `${project}-vpc-${env}`,
Environment: env,
ManagedBy: "pulumi",
},
});
const publicSubnets: aws.ec2.Subnet[] = [];
const privateSubnets: aws.ec2.Subnet[] = [];
const availabilityZones = aws.({ : });
(availabilityZones.( azs..(, ).( {
publicSubnet = aws..(, {
: vpc.,
: config.(),
: az,
: ,
: {
: ,
: ,
: env,
},
});
publicSubnets.(publicSubnet);
privateSubnet = aws..(, {
: vpc.,
: config.(),
: az,
: {
: ,
: ,
: env,
},
});
privateSubnets.(privateSubnet);
})));
eksRole = aws..(, {
: aws..({ : }),
});
aws..(, {
: ,
: eksRole.,
});
aws..(, {
: ,
: eksRole.,
});
cluster = aws..(, {
: eksRole.,
: {
: privateSubnets.( s.),
: ,
: ,
: [],
},
: {
: ,
},
: [, , ],
: {
: env,
: ,
},
});
k8sProvider = kubernetes.(, {
: cluster..(
),
}, { : cluster });
namespace = kubernetes...(, {
: {
: ,
: {
: env,
},
},
}, { : k8sProvider });
vpcId = vpc.;
clusterName = cluster.;
kubeconfig = cluster..(
.(c.!., ).()
);
namespaceName = namespace..;
# infrastructure/app.py
from aws_cdk import (
App, Stack, Duration,
aws_ec2 as ec2,
aws_ecs as ecs,
aws_ecr as ecr,
aws_rds as rds,
aws_secretsmanager as secrets,
aws_elasticloadbalancingv2 as elbv2,
aws_autoscaling as autoscaling,
aws_iam as iam,
)
from constructs import Construct
class ApiPlatformStack(Stack):
def __init__(self, scope: Construct, id: str, *, environment: str = "prod", **kwargs):
super().__init__(scope, id, **kwargs)
self.environment = environment
self.project = "api-platform"
# VPC
self.vpc = ec2.Vpc(
self, "Vpc",
cidr="10.0.0.0/16",
max_azs=2,
nat_gateways=1,
subnet_configuration=[
ec2.SubnetConfiguration(
name="Public",
subnet_type=ec2.SubnetType.PUBLIC,
cidr_mask=24,
),
ec2.SubnetConfiguration(
name="Private",
subnet_type=ec2.SubnetType.PRIVATE_WITH_NAT,
cidr_mask=24,
),
],
)
# ECR Repository
.repository = ecr.Repository(
, ,
repository_name=,
lifecycle_rules=[
ecr.LifecycleRule(
description=,
max_image_count=,
),
],
)
.cluster = ecs.Cluster(
, ,
cluster_name=,
container_insights=,
)
.database = rds.DatabaseInstance(
, ,
engine=rds.DatabaseInstanceEngine.postgres(
version=rds.PostgresEngineVersion.VER_15_5
),
instance_type=ec2.InstanceType.of(
ec2.InstanceClass.M6I, ec2.InstanceSize.XLARGE2
),
vpc=.vpc,
vpc_subnets=ec2.SubnetSelection(
subnet_type=ec2.SubnetType.PRIVATE
),
deletion_protection=(environment == ),
backup_retention=Duration.days(),
)
.load_balancer = elbv2.ApplicationLoadBalancer(
, ,
vpc=.vpc,
internet_facing=(environment == ),
vpc_subnets=ec2.SubnetSelection(
subnet_type=ec2.SubnetType.PUBLIC
environment == ec2.SubnetType.PRIVATE
),
)
.create_ecs_service()
():
task_definition = ecs.FargateTaskDefinition(
, ,
cpu=,
memory_mib=,
runtime_platform={
: ecs.OperatingSystemFamily.LINUX,
: ecs.CpuArchitecture.X86_64,
},
)
container = task_definition.add_container(
,
image=ecs.ContainerImage.from_ecr_repository(
.repository,
),
port_mappings=[ecs.PortMapping(container_port=)],
environment={
: .environment,
: .database.db_instance_endpoint_address,
},
secrets={
: ecs.Secret.from_secrets_manager(
.database.secret
),
},
logging=ecs.LogDrivers.aws_logs(
stream_prefix=
),
)
ecs.FargateService(
, ,
cluster=.cluster,
task_definition=task_definition,
desired_count=,
vpc_subnets=ec2.SubnetSelection(
subnet_type=ec2.SubnetType.PRIVATE
),
load_balancer=.load_balancer,
target_group=elbv2.ApplicationTargetGroup(
, ,
port=,
vpc=.vpc,
health_check=elbv2.HealthCheck(
path=,
interval=Duration.seconds(),
healthy_threshold_count=,
unhealthy_threshold_count=,
),
),
)
app = App()
ApiPlatformStack(app, , environment=)
app.synth()
terraform plan output to review changes before applyingterraform destroy or terraform plan -destroy for safe cleanup