<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Terraform-Agents on Chen Kai Blog</title><link>https://www.chenk.top/en/series/terraform-agents/</link><description>Recent content in Terraform-Agents on Chen Kai Blog</description><generator>Hugo</generator><language>en</language><lastBuildDate>Thu, 26 Mar 2026 09:00:00 +0000</lastBuildDate><atom:link href="https://www.chenk.top/en/series/terraform-agents/index.xml" rel="self" type="application/rss+xml"/><item><title>Terraform for AI Agents (8): End-to-End — research-agent-stack in One Apply</title><link>https://www.chenk.top/en/terraform-agents/08-end-to-end-walkthrough/</link><pubDate>Thu, 26 Mar 2026 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/terraform-agents/08-end-to-end-walkthrough/</guid><description>&lt;p>This is where everything from articles 2 through 7 lands in one place. By the end you&amp;rsquo;ll have run &lt;code>terraform apply&lt;/code> once and produced a complete, observable, budgeted agent runtime stack on Alibaba Cloud — about 31 resources, ~7 minutes of wall clock, ¥12,530/month all-in at prod sizing.&lt;/p>
&lt;p>The stack we&amp;rsquo;re building:&lt;/p>
&lt;p>&lt;figure class="article-figure">
 &lt;img src="https://blog-pic-ck.oss-cn-beijing.aliyuncs.com/posts/en/terraform-agents/08-end-to-end-walkthrough/fig1_full_stack.png" alt="research-agent-stack: every box, one terraform apply" loading="lazy" decoding="async" class="content-image">
 
&lt;/figure>
&lt;/p>
&lt;p>Five layers — edge, compute, memory, platform, ops — composed from the modules we built across this series. Eleven Aliyun products under the hood: VPC, ECS, ALB, OSS, RDS for PostgreSQL, OpenSearch, KMS, SLS, ARMS, CloudMonitor, and DashScope (the LLM provider, accessed via the gateway).&lt;/p></description></item><item><title>Terraform for AI Agents (7): Observability, SLS Dashboards, and Cost Alarms</title><link>https://www.chenk.top/en/terraform-agents/07-observability-and-cost-control/</link><pubDate>Tue, 24 Mar 2026 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/terraform-agents/07-observability-and-cost-control/</guid><description>&lt;p>Agents are non-deterministic, multi-step, and call expensive APIs. This combination means you can&amp;rsquo;t debug them after the fact unless you instrumented them from the start. This article sets up three pipelines through Terraform — logs, traces, and metrics — into a unified dashboard, adds six SLS queries to solve real incidents, and sets up four alarms that have actually fired and saved my projects in production.&lt;/p>
&lt;p>By the end, you&amp;rsquo;ll have a DingTalk channel that alerts you before the bill explodes, latency increases, the error rate spikes, or an agent starts looping on itself — plus SLO budgets that turn operational feelings into data.&lt;/p></description></item><item><title>Terraform for AI Agents (6): LLM Gateway and Secrets Management</title><link>https://www.chenk.top/en/terraform-agents/06-llm-gateway-and-secrets/</link><pubDate>Sun, 22 Mar 2026 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/terraform-agents/06-llm-gateway-and-secrets/</guid><description>&lt;p>A pattern I see repeatedly in immature agent stacks: each agent has its own copy of &lt;code>OPENAI_API_KEY&lt;/code> in its own &lt;code>.env&lt;/code> file. Sometimes the same key, sometimes different ones, sometimes a colleague&amp;rsquo;s personal key from when they prototyped. When the bill arrives nobody can tell which agent caused which token spend, and when a key leaks (it always does) you&amp;rsquo;re playing whack-a-mole across a dozen &lt;code>.env&lt;/code> files.&lt;/p>
&lt;p>The real wake-up call hit me two years ago. A contractor finished his three-month engagement on a Friday, his laptop went home, and on the following Tuesday DashScope billing flagged 12 million tokens of &lt;code>qwen-max&lt;/code> traffic from an IP we didn&amp;rsquo;t recognise. His personal API key — copy-pasted into a side project — was still sitting in our agent&amp;rsquo;s &lt;code>.env&lt;/code>. Rotating it took six hours: three engineers, four repos, two CI pipelines, one panicked Slack thread. Never again.&lt;/p></description></item><item><title>Terraform for AI Agents (5): Storage — Vector, Relational, and Object Memory</title><link>https://www.chenk.top/en/terraform-agents/05-storage-for-agent-memory/</link><pubDate>Fri, 20 Mar 2026 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/terraform-agents/05-storage-for-agent-memory/</guid><description>&lt;p>Most tutorials gloss over an agent&amp;rsquo;s memory. &amp;lsquo;Just put the embeddings in Pinecone, the sessions in Postgres, and the screenshots in S3.&amp;rsquo; On Aliyun, all three are managed services. Correctly provisioning them with Terraform can mean the difference between a working memory and losing three weeks of conversation history because the disk filled up at 4 AM.&lt;/p>
&lt;p>This article covers all three layers, their Terraform configurations, the critical but tedious backup and disaster recovery (DR) setup, the major version upgrade process, and the Saturday outage that changed how I do things.&lt;/p></description></item><item><title>Terraform for AI Agents (4): Compute — ECS, ACK, or Function Compute?</title><link>https://www.chenk.top/en/terraform-agents/04-compute-for-agent-runtime/</link><pubDate>Wed, 18 Mar 2026 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/terraform-agents/04-compute-for-agent-runtime/</guid><description>&lt;p>The single most important architectural decision in an agent system is &lt;em>where the agent loop process runs&lt;/em>. There are three good options on Aliyun, plus a fourth that almost everyone forgets. Picking the wrong one isn&amp;rsquo;t catastrophic — you can migrate later — but it costs weeks of unnecessary work and several thousand RMB a month in idle compute.&lt;/p>
&lt;p>This article covers all four options with working Terraform, cost crossovers, and operational gotchas I often encounter.&lt;/p></description></item><item><title>Terraform for AI Agents (3): A Reusable VPC and Security Baseline</title><link>https://www.chenk.top/en/terraform-agents/03-vpc-and-security-baseline/</link><pubDate>Mon, 16 Mar 2026 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/terraform-agents/03-vpc-and-security-baseline/</guid><description>&lt;p>This article builds the single most copied piece of Terraform in my agent projects: a &lt;code>vpc-baseline&lt;/code> module that gives every later component (ECS, RDS, OpenSearch, ACK) a sane place to land. It&amp;rsquo;s about 200 lines of HCL all-in. Worth typing once, refer to it forever.&lt;/p>
&lt;p>By the end you&amp;rsquo;ll have:&lt;/p>
&lt;ul>
&lt;li>A VPC across three availability zones in one region&lt;/li>
&lt;li>Six vSwitches (one public + one private per zone) with non-overlapping CIDRs&lt;/li>
&lt;li>A NAT Gateway with EIP for private-subnet outbound to LLM APIs&lt;/li>
&lt;li>Three security groups stacked by tier (ALB → agent runtime → memory)&lt;/li>
&lt;li>Three KMS customer master keys, one per data domain (memory, secrets, logs)&lt;/li>
&lt;li>A clean module interface: &lt;code>name + CIDR + zones&lt;/code> in, IDs out&lt;/li>
&lt;li>Drift detection in CI, semver-pinned module references, and a per-line cost model&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2 id="the-mental-model" class="heading-anchor">The mental model&lt;a href="#the-mental-model" class="heading-link" aria-label="Permalink to this section" title="Copy link to this section">#&lt;/a>
&lt;/h2>&lt;p>Before code, the picture:&lt;/p></description></item><item><title>Terraform for AI Agents (2): Provider, Auth, and Remote State on OSS</title><link>https://www.chenk.top/en/terraform-agents/02-provider-and-state-setup/</link><pubDate>Sat, 14 Mar 2026 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/terraform-agents/02-provider-and-state-setup/</guid><description>&lt;p>This article is where you stop reading and start typing. By the end, you&amp;rsquo;ll have:&lt;/p>
&lt;ol>
&lt;li>The &lt;code>alicloud&lt;/code> Terraform provider installed and version-pinned.&lt;/li>
&lt;li>Authentication wired up — through the right method, not the convenient one.&lt;/li>
&lt;li>Remote state on an OSS bucket with Tablestore-based locking.&lt;/li>
&lt;li>Three workspaces (&lt;code>dev&lt;/code>, &lt;code>staging&lt;/code>, &lt;code>prod&lt;/code>) that share a backend but isolate state.&lt;/li>
&lt;li>A working &lt;code>terraform plan&lt;/code> against an empty config.&lt;/li>
&lt;/ol>
&lt;p>Nothing here provisions an agent yet. This lays the foundation for all future articles. If you skip this and try to wing it in article 3, you&amp;rsquo;ll likely face a state-corruption incident within a week.&lt;/p></description></item><item><title>Terraform for AI Agents (1): Why IaC Is the Only Sane Way to Ship Agents</title><link>https://www.chenk.top/en/terraform-agents/01-why-terraform-for-agents/</link><pubDate>Thu, 12 Mar 2026 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/terraform-agents/01-why-terraform-for-agents/</guid><description>&lt;p>I have shipped four agent systems on Alibaba Cloud in the last eighteen months. Three of them started life as a &lt;code>tmux&lt;/code> session on a single ECS instance someone created by clicking through the console. All three of those needed a panicked weekend of rebuilding when the second engineer joined the project, when the prod region had a stockout, or when the security team asked for a network diagram.&lt;/p>
&lt;p>The fourth started life as &lt;code>terraform apply&lt;/code>. It was the only one I haven&amp;rsquo;t lost a weekend to.&lt;/p></description></item></channel></rss>