Terraform
Prompt a model connected to the Terraform MCP server
This topic provides example prompts for helping you write Terraform configuration after installing the Terraform model context protocol (MCP) server. Refer to Deploy the Terraform MCP server for instructions on how to deploy the server.
Note
This feature is currently in beta. Do not use beta functionality in production environments.
Overview
To trigger the MCP server tools, ask your LLM questions about your provider configuration or general questions about Terraform providers and modules. Note that for your LLM to use the server, your questions must pertain to provider configuration from the registry. The LLM uses other sources, such as content from the internet, to respond to general questions about Terraform configuration or requests to generate code.
Requirements
Verify that you have deployed the Terraform MCP server and configured your client. Refer to Deploy the Terraform MCP server for instructions.
Prompt your MCP client
Your model may still decide to use other resources to formulate responses, but you can use the following guidelines to help you create prompts that are more likely to be routed through the server:
- Include the names of specific providers or provider modules. For example, use
google_compute_disk
in your prompt instead ofthe compute disk
. - Use the full Terraform resource address in your query. Refer to Resource Address Reference in the Terraform CLI documentation for additional information about resource addresses.
- Ask for the latest information about the provider or module.
Examples
You can use the following set of prompts as a guide to help you write your own configuration. The following responses are returned from the server using ChatGPT 4.1 in GitHub Copilot on VS Code. Your responses may vary.
Get AI-related resources from the Google provider
The following prompt runs the resolveProviderDocID
tool, which obtains a list of related provider document IDs so that you can decide which resources to create:
"I need help understanding what resources are available in the Google provider that are for AI"
Response
The server sends the following request payload to the registry:
{
"providerDataType": "resources",
"providerName": "google",
"providerNamespace": "hashicorp",
"providerVersion": "latest",
"serviceSlug": "ai"
}
The server retrieves the following response from the registry. The response is truncated in this example:
Available Documentation (top matches) for resources in Terraform provider hashicorp/google version: 6.35.0
Each result includes:
- providerDocID: tfprovider-compatible identifier
- Title: Service or resource name
- Category: Type of document
For best results, select libraries based on the serviceSlug match and category of information requested.
---
- providerDocID: 8925589
- Title: vertex_ai_endpoint_iam
- Category: resources
---
- providerDocID: 8925590
- Title: vertex_ai_feature_group
- Category: resources
---
- providerDocID: 8925591
- Title: vertex_ai_feature_group_feature
- Category: resources
. . .
The client prints the following response using the context acquired from the MCP server:
The Google Terraform provider offers several resources related to AI, primarily under the Vertex AI and Document AI services. Here are the main AI-related resources available:
Vertex AI Resources
vertex_ai_dataset
vertex_ai_deployment_resource_pool
vertex_ai_endpoint
vertex_ai_endpoint_iam
vertex_ai_feature_group
vertex_ai_featurestore
vertex_ai_index
vertex_ai_metadata_store
vertex_ai_tensorboard
document_ai_processor
document_ai_warehouse_document_schema
These resources allow you to manage datasets, endpoints, feature stores, indexes, metadata, and more for AI/ML workflows on Google Cloud, as well as Document AI processors and schemas.
If you want details or documentation for any specific resource, let me know which one(s) you're interested in!
Get information about storage buckets in Azure
The following prompt runs the resolveProviderDocID
tool, which gets a list of provider documentation IDs. Next, the getProviderDocs
tool calls the appropriate documentation for the use case:
"I need help setting up storage buckets in the azure provider"
Response
The server sends a request payload for each tool:
resolveProviderDocId
{
"providerDataType": "resources",
"providerName": "azurerm",
"providerNamespace": "hashicorp",
"providerVersion": "latest",
"serviceSlug": "storage_account"
}
getProviderDocs
{
"providerDocID": "8957547"
}
getProviderDocs
{
"providerDocID": "8957555"
}
The server retrieves the following responses to each tool from the registry. The responses are truncated in this example:
resolveProviderDocId
Available Documentation (top matches) for resources in Terraform provider hashicorp/azurerm version: 4.29.0
Each result includes:
- providerDocID: tfprovider-compatible identifier
- Title: Service or resource name
- Category: Type of document
For best results, select libraries based on the serviceSlug match and category of information requested.
---
- providerDocID: 8956759
- Title: backup_container_storage_account
- Category: resources
---
- providerDocID: 8957097
- Title: key_vault_managed_storage_account
- Category: resources
---
- providerDocID: 8957098
- Title: key_vault_managed_storage_account_sas_token_definition
- Category: resources
---
- providerDocID: 8957145
- Title: log_analytics_linked_storage_account
- Category: resources
...
getProviderDoc
---
subcategory: "Storage"
layout: "azurerm"
page_title: "Azure Resource Manager: azurerm_storage_account"
description: |-
Manages a Azure Storage Account.
---
# azurerm_storage_account
Manages an Azure Storage Account.
## Example Usage
```hcl
resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "West Europe"
}
resource "azurerm_storage_account" "example" {
name = "storageaccountname"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "GRS"
tags = {
environment = "staging"
}
}
```
## Example Usage with Network Rules
...
getProviderDoc
---
subcategory: "Storage"
layout: "azurerm"
page_title: "Azure Resource Manager: azurerm_storage_container"
description: |-
Manages a Container within an Azure Storage Account.
---
# azurerm_storage_container
Manages a Container within an Azure Storage Account.
## Example Usage
```hcl
resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "West Europe"
}
resource "azurerm_storage_account" "example" {
name = "examplestoraccount"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "LRS"
tags = {
environment = "staging"
}
}
resource "azurerm_storage_container" "example" {
name = "vhds"
storage_account_id = azurerm_storage_account.example.id
container_access_type = "private"
}
```
## Argument Reference
...
The client prints the following response using the context acquired from the MCP server:
To set up storage buckets in Azure using the Terraform azurerm provider, you need to use the azurerm_storage_account resource. Here’s a quick guide and example configuration:
- Terraform Resource for Azure Storage Account
resource "azurerm_resource_group" "example" { name = "example-resources" location = "West Europe" } resource "azurerm_storage_account" "example" { name = "storageaccountname" # must be globally unique, lowercase resource_group_name = azurerm_resource_group.example.name location = azurerm_resource_group.example.location account_tier = "Standard" # or "Premium" account_replication_type = "GRS" # or "LRS", "RAGRS", "ZRS", etc. tags = { environment = "staging" } }
Get help creating an IBM VM
The following prompt runs the searchModules
tool, which gets a list of modules:
"Is there a module to help with setting up an IBM VM?"
Response
The server sends the following request payload:
{
"moduleQuery": "ibm vm"
}
The server retrieves the following response from the registry:
Available Terraform Modules (top matches) for ibm vm
Each result includes:
- moduleID: The module ID (format: namespace/name/provider-name/module-version)
- Name: The name of the module
- Description: A short description of the module
- Downloads: The total number of times the module has been downloaded
- Verified: Verification status of the module
- Published: The date and time when the module was published
---
- moduleID: intel/ibm-vm/intel/1.2.2
- Name: ibm-vm
- Description: Intel Cloud Optimization Module - IBM VM
- Downloads: 15
- Verified: false
- Published: 2024-09-25 20:31:58.951109 +0000 UTC
---
The client prints the following response using the context acquired from the MCP server:
Yes, there is a Terraform module to help with setting up an IBM VM:
- IBM VM Module
- ID: intel/ibm-vm/intel/1.2.2
- Description: Intel Cloud Optimization Module - IBM VM
- Module Version: 1.2.2
- Namespace: intel
- Source: GitHub - intel/terraform-intel-ibm-vm
You can use this module to set up and manage IBM VMs with Terraform. If you need more details or usage examples, let me know.