terraform のコードを AI に任せると、うまくいかないことが多い感覚はないでしょうか?
必ずしも 100% の解決とはいきませんが、多少改善する方法として、MCP を使って公式 document を読ませる方法を紹介します。
MCP の説明は割愛します。
MCP server の pull
(2025/06/28 時点)
$ docker pull hashicorp/terraform-mcp-server Using default tag: latest latest: Pulling from hashicorp/terraform-mcp-server b0f6f1c319a1: Pull complete 50222a595f96: Pull complete Digest: sha256:9b01dbb948b9362575b9fb7d70fac1739365eeae5d7b264db809f4b11b5da6c3 Status: Downloaded newer image for hashicorp/terraform-mcp-server:latest docker.io/hashicorp/terraform-mcp-server:latest
https://hub.docker.com/r/hashicorp/terraform-mcp-server/tags
Claude Code に MCP サーバーを登録
shell で以下を実行
$ claude mcp add terraform-mcp-server -s project -- docker run -i --rm hashicorp/terraform-mcp-server Added stdio MCP server terraform-mcp-server with command: docker run -i --rm hashicorp/terraform-mcp-server to project config
-s project は scope の指定です。
MCP は数が多いと AI が混乱するので、制限したほうが性能に期待できます。そのため、 project ごとに設定することをおすすめします。
上記コマンドで、以下のファイルが生成されます
{
"mcpServers": {
"terraform-mcp-server": {
"type": "stdio",
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"hashicorp/terraform-mcp-server"
],
"env": {}
}
}
}
実践
App Runner の auto_scaling_configuration について雑に聞いてみます
$ claude
> what is auto_scaling_configuration?
● I'll help you understand the auto_scaling_configuration in Terraform. Let me search for information about this resource
using the Terraform MCP server.
● terraform-mcp-server:resolveProviderDocID (MCP)(providerName: "aws", providerNamespace: "hashicorp", serviceSlug:
"auto_scaling_configuration", providerDataType: "resources")
● terraform-mcp-server:resolveProviderDocID (MCP)(providerName: "aws", providerNamespace: "hashicorp", serviceSlug:
"auto_scaling_configuration", providerDataType: "resources")
⎿ Available Documentation (top matches) for resources in Terraform provider hashicorp/aws version: 6.0.0
● auto_scaling_configuration is an AWS App Runner resource that controls how your application scales in response to
traffic.
Key parameters:
- max_concurrency: Maximum requests per instance before scaling up
- max_size: Maximum number of instances (default 25 in your variables)
- min_size: Minimum number of instances (default 1 in your variables)
Your App Runner service currently uses default auto-scaling settings. To add custom scaling, you'd create an
aws_apprunner_auto_scaling_configuration_version resource and reference it in the service.