awslabs.terraform-mcp-server 1.0.14__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. awslabs/__init__.py +17 -0
  2. awslabs/terraform_mcp_server/__init__.py +17 -0
  3. awslabs/terraform_mcp_server/impl/resources/__init__.py +25 -0
  4. awslabs/terraform_mcp_server/impl/resources/terraform_aws_provider_resources_listing.py +66 -0
  5. awslabs/terraform_mcp_server/impl/resources/terraform_awscc_provider_resources_listing.py +69 -0
  6. awslabs/terraform_mcp_server/impl/tools/__init__.py +33 -0
  7. awslabs/terraform_mcp_server/impl/tools/execute_terraform_command.py +223 -0
  8. awslabs/terraform_mcp_server/impl/tools/execute_terragrunt_command.py +320 -0
  9. awslabs/terraform_mcp_server/impl/tools/run_checkov_scan.py +376 -0
  10. awslabs/terraform_mcp_server/impl/tools/search_aws_provider_docs.py +691 -0
  11. awslabs/terraform_mcp_server/impl/tools/search_awscc_provider_docs.py +641 -0
  12. awslabs/terraform_mcp_server/impl/tools/search_specific_aws_ia_modules.py +458 -0
  13. awslabs/terraform_mcp_server/impl/tools/search_user_provided_module.py +349 -0
  14. awslabs/terraform_mcp_server/impl/tools/utils.py +572 -0
  15. awslabs/terraform_mcp_server/models/__init__.py +49 -0
  16. awslabs/terraform_mcp_server/models/models.py +381 -0
  17. awslabs/terraform_mcp_server/scripts/generate_aws_provider_resources.py +1240 -0
  18. awslabs/terraform_mcp_server/scripts/generate_awscc_provider_resources.py +1039 -0
  19. awslabs/terraform_mcp_server/scripts/scrape_aws_terraform_best_practices.py +143 -0
  20. awslabs/terraform_mcp_server/server.py +440 -0
  21. awslabs/terraform_mcp_server/static/AWSCC_PROVIDER_RESOURCES.md +3125 -0
  22. awslabs/terraform_mcp_server/static/AWS_PROVIDER_RESOURCES.md +3833 -0
  23. awslabs/terraform_mcp_server/static/AWS_TERRAFORM_BEST_PRACTICES.md +2523 -0
  24. awslabs/terraform_mcp_server/static/MCP_INSTRUCTIONS.md +142 -0
  25. awslabs/terraform_mcp_server/static/TERRAFORM_WORKFLOW_GUIDE.md +330 -0
  26. awslabs/terraform_mcp_server/static/__init__.py +38 -0
  27. awslabs_terraform_mcp_server-1.0.14.dist-info/METADATA +166 -0
  28. awslabs_terraform_mcp_server-1.0.14.dist-info/RECORD +30 -0
  29. awslabs_terraform_mcp_server-1.0.14.dist-info/WHEEL +4 -0
  30. awslabs_terraform_mcp_server-1.0.14.dist-info/entry_points.txt +2 -0
@@ -0,0 +1,143 @@
1
+ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Script to download and extract content from AWS Terraform best practices PDF and save it as markdown."""
16
+
17
+ import io
18
+ import os
19
+ import PyPDF2
20
+ import re
21
+ import requests
22
+ from pathlib import Path
23
+
24
+
25
+ # URL to the PDF
26
+ PDF_URL = 'https://docs.aws.amazon.com/pdfs/prescriptive-guidance/latest/terraform-aws-provider-best-practices/terraform-aws-provider-best-practices.pdf'
27
+
28
+ # Output file path
29
+ OUTPUT_DIR = Path(__file__).parent.parent / 'static'
30
+ OUTPUT_FILE = 'AWS_TERRAFORM_BEST_PRACTICES.md'
31
+
32
+
33
+ def download_pdf(url):
34
+ """Download PDF from URL and return as bytes."""
35
+ print(f'Downloading PDF from {url}...')
36
+ response = requests.get(url)
37
+ response.raise_for_status() # Raise an exception for HTTP errors
38
+ return response.content
39
+
40
+
41
+ def extract_text_from_pdf(pdf_bytes):
42
+ """Extract text from PDF bytes."""
43
+ print('Extracting text from PDF...')
44
+ pdf_file = io.BytesIO(pdf_bytes)
45
+ reader = PyPDF2.PdfReader(pdf_file)
46
+
47
+ text = ''
48
+ for page_num in range(len(reader.pages)):
49
+ page = reader.pages[page_num]
50
+ text += page.extract_text() + '\n\n'
51
+
52
+ return text
53
+
54
+
55
+ def convert_to_markdown(text):
56
+ """Convert extracted text to markdown format."""
57
+ print('Converting text to markdown...')
58
+
59
+ # Add title
60
+ markdown = '# AWS Terraform Provider Best Practices\n\n'
61
+ markdown += (
62
+ '_This document was automatically extracted from the AWS Prescriptive Guidance PDF._\n\n'
63
+ )
64
+ markdown += f'_Source: [{PDF_URL}]({PDF_URL})_\n\n'
65
+
66
+ # Process the text
67
+ lines = text.split('\n')
68
+ current_section = ''
69
+
70
+ for line in lines:
71
+ # Skip empty lines
72
+ if not line.strip():
73
+ continue
74
+
75
+ # Try to identify headers
76
+ if re.match(r'^[A-Z][A-Za-z\s]{2,}$', line.strip()) and len(line.strip()) < 80:
77
+ # Looks like a header
78
+ current_section = line.strip()
79
+
80
+ # Stop before Document history section
81
+ if current_section.lower() == 'document history':
82
+ break
83
+
84
+ markdown += f'## {current_section}\n\n'
85
+ continue
86
+
87
+ # Process content
88
+ if re.match(r'^\d+\.\s+[A-Z]', line.strip()):
89
+ # Numbered section
90
+ markdown += f'### {line.strip()}\n\n'
91
+ else:
92
+ # Regular text
93
+ # Check if it's a bullet point
94
+ if line.strip().startswith('•') or line.strip().startswith('-'):
95
+ markdown += f'{line.strip()}\n\n'
96
+ else:
97
+ markdown += f'{line.strip()}\n\n'
98
+
99
+ # Clean up the markdown
100
+ # Remove page numbers and headers/footers
101
+ markdown = re.sub(r'\n\d+\n', '\n', markdown)
102
+
103
+ # Fix bullet points
104
+ markdown = markdown.replace('•', '*')
105
+
106
+ # Remove excessive newlines
107
+ markdown = re.sub(r'\n{3,}', '\n\n', markdown)
108
+
109
+ return markdown
110
+
111
+
112
+ def main():
113
+ """Execute the main workflow to download, extract, and convert AWS Terraform best practices to markdown.
114
+
115
+ Downloads the PDF from the specified URL, extracts the text content, converts it to markdown format,
116
+ and saves it to the output file. Creates the output directory if it doesn't exist.
117
+ """
118
+ # Create output directory if it doesn't exist
119
+ os.makedirs(OUTPUT_DIR, exist_ok=True)
120
+
121
+ try:
122
+ # Download the PDF
123
+ pdf_bytes = download_pdf(PDF_URL)
124
+
125
+ # Extract text from PDF
126
+ text = extract_text_from_pdf(pdf_bytes)
127
+
128
+ # Convert to markdown
129
+ markdown = convert_to_markdown(text)
130
+
131
+ # Write to file
132
+ output_path = OUTPUT_DIR / OUTPUT_FILE
133
+ with open(output_path, 'w', encoding='utf-8') as f:
134
+ f.write(markdown)
135
+
136
+ print(f'Successfully saved to {output_path}')
137
+
138
+ except Exception as e:
139
+ print(f'Error: {e}')
140
+
141
+
142
+ if __name__ == '__main__':
143
+ main()
@@ -0,0 +1,440 @@
1
+ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ #!/usr/bin/env python3
16
+ """terraform MCP server implementation."""
17
+
18
+ from awslabs.terraform_mcp_server.impl.resources import (
19
+ terraform_aws_provider_assets_listing_impl,
20
+ terraform_awscc_provider_resources_listing_impl,
21
+ )
22
+ from awslabs.terraform_mcp_server.impl.tools import (
23
+ execute_terraform_command_impl,
24
+ execute_terragrunt_command_impl,
25
+ run_checkov_scan_impl,
26
+ search_aws_provider_docs_impl,
27
+ search_awscc_provider_docs_impl,
28
+ search_specific_aws_ia_modules_impl,
29
+ search_user_provided_module_impl,
30
+ )
31
+ from awslabs.terraform_mcp_server.models import (
32
+ CheckovScanRequest,
33
+ CheckovScanResult,
34
+ ModuleSearchResult,
35
+ SearchUserProvidedModuleRequest,
36
+ SearchUserProvidedModuleResult,
37
+ TerraformAWSCCProviderDocsResult,
38
+ TerraformAWSProviderDocsResult,
39
+ TerraformExecutionRequest,
40
+ TerraformExecutionResult,
41
+ TerragruntExecutionRequest,
42
+ TerragruntExecutionResult,
43
+ )
44
+ from awslabs.terraform_mcp_server.static import (
45
+ AWS_TERRAFORM_BEST_PRACTICES,
46
+ MCP_INSTRUCTIONS,
47
+ TERRAFORM_WORKFLOW_GUIDE,
48
+ )
49
+ from mcp.server.fastmcp import FastMCP
50
+ from pydantic import Field
51
+ from typing import Any, Dict, List, Literal, Optional
52
+
53
+
54
+ mcp = FastMCP(
55
+ 'terraform_mcp_server',
56
+ instructions=f'{MCP_INSTRUCTIONS}',
57
+ dependencies=[
58
+ 'pydantic',
59
+ 'loguru',
60
+ 'requests',
61
+ 'beautifulsoup4',
62
+ 'PyPDF2',
63
+ ],
64
+ )
65
+
66
+
67
+ # * Tools
68
+ @mcp.tool(name='ExecuteTerraformCommand')
69
+ async def execute_terraform_command(
70
+ command: Literal['init', 'plan', 'validate', 'apply', 'destroy'] = Field(
71
+ ..., description='Terraform command to execute'
72
+ ),
73
+ working_directory: str = Field(..., description='Directory containing Terraform files'),
74
+ variables: Optional[Dict[str, str]] = Field(None, description='Terraform variables to pass'),
75
+ aws_region: Optional[str] = Field(None, description='AWS region to use'),
76
+ strip_ansi: bool = Field(True, description='Whether to strip ANSI color codes from output'),
77
+ ) -> TerraformExecutionResult:
78
+ """Execute Terraform workflow commands against an AWS account.
79
+
80
+ This tool runs Terraform commands (init, plan, validate, apply, destroy) in the
81
+ specified working directory, with optional variables and region settings.
82
+
83
+ Parameters:
84
+ command: Terraform command to execute
85
+ working_directory: Directory containing Terraform files
86
+ variables: Terraform variables to pass
87
+ aws_region: AWS region to use
88
+ strip_ansi: Whether to strip ANSI color codes from output
89
+
90
+ Returns:
91
+ A TerraformExecutionResult object containing command output and status
92
+ """
93
+ request = TerraformExecutionRequest(
94
+ command=command,
95
+ working_directory=working_directory,
96
+ variables=variables,
97
+ aws_region=aws_region,
98
+ strip_ansi=strip_ansi,
99
+ )
100
+ return await execute_terraform_command_impl(request)
101
+
102
+
103
+ @mcp.tool(name='ExecuteTerragruntCommand')
104
+ async def execute_terragrunt_command(
105
+ command: Literal['init', 'plan', 'validate', 'apply', 'destroy', 'output', 'run-all'] = Field(
106
+ ..., description='Terragrunt command to execute'
107
+ ),
108
+ working_directory: str = Field(..., description='Directory containing Terragrunt files'),
109
+ variables: Optional[Dict[str, str]] = Field(None, description='Terraform variables to pass'),
110
+ aws_region: Optional[str] = Field(None, description='AWS region to use'),
111
+ strip_ansi: bool = Field(True, description='Whether to strip ANSI color codes from output'),
112
+ include_dirs: Optional[List[str]] = Field(
113
+ None, description='Directories to include in a multi-module run'
114
+ ),
115
+ exclude_dirs: Optional[List[str]] = Field(
116
+ None, description='Directories to exclude from a multi-module run'
117
+ ),
118
+ run_all: bool = Field(False, description='Run command on all modules in subdirectories'),
119
+ terragrunt_config: Optional[str] = Field(
120
+ None, description='Path to a custom terragrunt config file (not valid with run-all)'
121
+ ),
122
+ ) -> TerragruntExecutionResult:
123
+ """Execute Terragrunt workflow commands against an AWS account.
124
+
125
+ This tool runs Terragrunt commands (init, plan, validate, apply, destroy, run-all) in the
126
+ specified working directory, with optional variables and region settings. Terragrunt extends
127
+ Terraform's functionality by providing features like remote state management, dependencies
128
+ between modules, and the ability to execute Terraform commands on multiple modules at once.
129
+
130
+ Parameters:
131
+ command: Terragrunt command to execute
132
+ working_directory: Directory containing Terragrunt files
133
+ variables: Terraform variables to pass
134
+ aws_region: AWS region to use
135
+ strip_ansi: Whether to strip ANSI color codes from output
136
+ include_dirs: Directories to include in a multi-module run
137
+ exclude_dirs: Directories to exclude from a multi-module run
138
+ run_all: Run command on all modules in subdirectories
139
+ terragrunt_config: Path to a custom terragrunt config file (not valid with run-all)
140
+
141
+ Returns:
142
+ A TerragruntExecutionResult object containing command output and status
143
+ """
144
+ request = TerragruntExecutionRequest(
145
+ command=command,
146
+ working_directory=working_directory,
147
+ variables=variables,
148
+ aws_region=aws_region,
149
+ strip_ansi=strip_ansi,
150
+ include_dirs=include_dirs,
151
+ exclude_dirs=exclude_dirs,
152
+ run_all=run_all,
153
+ terragrunt_config=terragrunt_config,
154
+ )
155
+ return await execute_terragrunt_command_impl(request)
156
+
157
+
158
+ @mcp.tool(name='SearchAwsProviderDocs')
159
+ async def search_aws_provider_docs(
160
+ asset_name: str = Field(
161
+ ...,
162
+ description='Name of the AWS service (asset) to look for (e.g., "aws_s3_bucket", "aws_lambda_function")',
163
+ ),
164
+ asset_type: str = Field(
165
+ 'resource',
166
+ description="Type of documentation to search - 'resource' (default), 'data_source', or 'both'",
167
+ ),
168
+ ) -> List[TerraformAWSProviderDocsResult]:
169
+ """Search AWS provider documentation for resources and attributes.
170
+
171
+ This tool searches the Terraform AWS provider documentation for information about
172
+ a specific asset in the AWS Provider Documentation, assets can be either resources or data sources. It retrieves comprehensive details including descriptions, example code snippets, argument references, and attribute references.
173
+
174
+ Use the 'asset_type' parameter to specify if you are looking for information about provider resources, data sources, or both. Valid values are 'resource', 'data_source' or 'both'.
175
+
176
+ The tool will automatically handle prefixes - you can search for either 'aws_s3_bucket' or 's3_bucket'.
177
+
178
+ Examples:
179
+ - To get documentation for an S3 bucket resource:
180
+ search_aws_provider_docs(asset_name='aws_s3_bucket')
181
+
182
+ - To search only for data sources:
183
+ search_aws_provider_docs(asset_name='aws_ami', asset_type='data_source')
184
+
185
+ - To search for both resource and data source documentation of a given name:
186
+ search_aws_provider_docs(asset_name='aws_instance', asset_type='both')
187
+
188
+ Parameters:
189
+ asset_name: Name of the service (asset) to look for (e.g., 'aws_s3_bucket', 'aws_lambda_function')
190
+ asset_type: Type of documentation to search - 'resource' (default), 'data_source', or 'both'
191
+
192
+ Returns:
193
+ A list of matching documentation entries with details including:
194
+ - Resource name and description
195
+ - URL to the official documentation
196
+ - Example code snippets
197
+ - Arguments with descriptions
198
+ - Attributes with descriptions
199
+ """
200
+ return await search_aws_provider_docs_impl(asset_name, asset_type)
201
+
202
+
203
+ @mcp.tool(name='SearchAwsccProviderDocs')
204
+ async def search_awscc_provider_docs(
205
+ asset_name: str = Field(
206
+ ...,
207
+ description='Name of the AWSCC service (asset) to look for (e.g., awscc_s3_bucket, awscc_lambda_function)',
208
+ ),
209
+ asset_type: str = Field(
210
+ 'resource',
211
+ description="Type of documentation to search - 'resource' (default), 'data_source', or 'both'",
212
+ ),
213
+ ) -> List[TerraformAWSCCProviderDocsResult]:
214
+ """Search AWSCC provider documentation for resources and attributes.
215
+
216
+ The AWSCC provider is based on the AWS Cloud Control API
217
+ and provides a more consistent interface to AWS resources compared to the standard AWS provider.
218
+
219
+ This tool searches the Terraform AWSCC provider documentation for information about
220
+ a specific asset in the AWSCC Provider Documentation, assets can be either resources or data sources. It retrieves comprehensive details including descriptions, example code snippets, and schema references.
221
+
222
+ Use the 'asset_type' parameter to specify if you are looking for information about provider resources, data sources, or both. Valid values are 'resource', 'data_source' or 'both'.
223
+
224
+ The tool will automatically handle prefixes - you can search for either 'awscc_s3_bucket' or 's3_bucket'.
225
+
226
+ Examples:
227
+ - To get documentation for an S3 bucket resource:
228
+ search_awscc_provider_docs(asset_name='awscc_s3_bucket')
229
+ search_awscc_provider_docs(asset_name='awscc_s3_bucket', asset_type='resource')
230
+
231
+ - To search only for data sources:
232
+ search_aws_provider_docs(asset_name='awscc_appsync_api', kind='data_source')
233
+
234
+ - To search for both resource and data source documentation of a given name:
235
+ search_aws_provider_docs(asset_name='awscc_appsync_api', kind='both')
236
+
237
+ - Search of a resource without the prefix:
238
+ search_awscc_provider_docs(resource_type='ec2_instance')
239
+
240
+ Parameters:
241
+ asset_name: Name of the AWSCC Provider resource or data source to look for (e.g., 'awscc_s3_bucket', 'awscc_lambda_function')
242
+ asset_type: Type of documentation to search - 'resource' (default), 'data_source', or 'both'. Some resources and data sources share the same name
243
+
244
+ Returns:
245
+ A list of matching documentation entries with details including:
246
+ - Resource name and description
247
+ - URL to the official documentation
248
+ - Example code snippets
249
+ - Schema information (required, optional, read-only, and nested structures attributes)
250
+ """
251
+ return await search_awscc_provider_docs_impl(asset_name, asset_type)
252
+
253
+
254
+ @mcp.tool(name='SearchSpecificAwsIaModules')
255
+ async def search_specific_aws_ia_modules(
256
+ query: str = Field(
257
+ ..., description='Optional search term to filter modules (empty returns all four modules)'
258
+ ),
259
+ ) -> List[ModuleSearchResult]:
260
+ """Search for specific AWS-IA Terraform modules.
261
+
262
+ This tool checks for information about four specific AWS-IA modules:
263
+ - aws-ia/bedrock/aws - Amazon Bedrock module for generative AI applications
264
+ - aws-ia/opensearch-serverless/aws - OpenSearch Serverless collection for vector search
265
+ - aws-ia/sagemaker-endpoint/aws - SageMaker endpoint deployment module
266
+ - aws-ia/serverless-streamlit-app/aws - Serverless Streamlit application deployment
267
+
268
+ It returns detailed information about these modules, including their README content,
269
+ variables.tf content, and submodules when available.
270
+
271
+ The search is performed across module names, descriptions, README content, and variable
272
+ definitions. This allows you to find modules based on their functionality or specific
273
+ configuration options.
274
+
275
+ Examples:
276
+ - To get information about all four modules:
277
+ search_specific_aws_ia_modules()
278
+
279
+ - To find modules related to Bedrock:
280
+ search_specific_aws_ia_modules(query='bedrock')
281
+
282
+ - To find modules related to vector search:
283
+ search_specific_aws_ia_modules(query='vector search')
284
+
285
+ - To find modules with specific configuration options:
286
+ search_specific_aws_ia_modules(query='endpoint_name')
287
+
288
+ Parameters:
289
+ query: Optional search term to filter modules (empty returns all four modules)
290
+
291
+ Returns:
292
+ A list of matching modules with their details, including:
293
+ - Basic module information (name, namespace, version)
294
+ - Module documentation (README content)
295
+ - Input and output parameter counts
296
+ - Variables from variables.tf with descriptions and default values
297
+ - Submodules information
298
+ - Version details and release information
299
+ """
300
+ return await search_specific_aws_ia_modules_impl(query)
301
+
302
+
303
+ @mcp.tool(name='RunCheckovScan')
304
+ async def run_checkov_scan(
305
+ working_directory: str = Field(..., description='Directory containing Terraform files'),
306
+ framework: str = Field(
307
+ 'terraform', description='Framework to scan (terraform, cloudformation, etc.)'
308
+ ),
309
+ check_ids: Optional[List[str]] = Field(None, description='Specific check IDs to run'),
310
+ skip_check_ids: Optional[List[str]] = Field(None, description='Check IDs to skip'),
311
+ output_format: str = Field('json', description='Output format (json, cli, etc.)'),
312
+ ) -> CheckovScanResult:
313
+ """Run Checkov security scan on Terraform code.
314
+
315
+ This tool runs Checkov to scan Terraform code for security and compliance issues,
316
+ identifying potential vulnerabilities and misconfigurations according to best practices.
317
+
318
+ Checkov (https://www.checkov.io/) is an open-source static code analysis tool that
319
+ can detect hundreds of security and compliance issues in infrastructure-as-code.
320
+
321
+ Parameters:
322
+ working_directory: Directory containing Terraform files to scan
323
+ framework: Framework to scan (default: terraform)
324
+ check_ids: Optional list of specific check IDs to run
325
+ skip_check_ids: Optional list of check IDs to skip
326
+ output_format: Format for scan results (default: json)
327
+
328
+ Returns:
329
+ A CheckovScanResult object containing scan results and identified vulnerabilities
330
+ """
331
+ request = CheckovScanRequest(
332
+ working_directory=working_directory,
333
+ framework=framework,
334
+ check_ids=check_ids,
335
+ skip_check_ids=skip_check_ids,
336
+ output_format=output_format,
337
+ )
338
+ return await run_checkov_scan_impl(request)
339
+
340
+
341
+ @mcp.tool(name='SearchUserProvidedModule')
342
+ async def search_user_provided_module(
343
+ module_url: str = Field(
344
+ ..., description='URL or identifier of the Terraform module (e.g., "hashicorp/consul/aws")'
345
+ ),
346
+ version: Optional[str] = Field(None, description='Specific version of the module to analyze'),
347
+ variables: Optional[Dict[str, Any]] = Field(
348
+ None, description='Variables to use when analyzing the module'
349
+ ),
350
+ ) -> SearchUserProvidedModuleResult:
351
+ """Search for a user-provided Terraform registry module and understand its inputs, outputs, and usage.
352
+
353
+ This tool takes a Terraform registry module URL and analyzes its input variables,
354
+ output variables, README, and other details to provide comprehensive information
355
+ about the module.
356
+
357
+ The module URL should be in the format "namespace/name/provider" (e.g., "hashicorp/consul/aws")
358
+ or "registry.terraform.io/namespace/name/provider".
359
+
360
+ Examples:
361
+ - To search for the HashiCorp Consul module:
362
+ search_user_provided_module(module_url='hashicorp/consul/aws')
363
+
364
+ - To search for a specific version of a module:
365
+ search_user_provided_module(module_url='terraform-aws-modules/vpc/aws', version='3.14.0')
366
+
367
+ - To search for a module with specific variables:
368
+ search_user_provided_module(
369
+ module_url='terraform-aws-modules/eks/aws',
370
+ variables={'cluster_name': 'my-cluster', 'vpc_id': 'vpc-12345'}
371
+ )
372
+
373
+ Parameters:
374
+ module_url: URL or identifier of the Terraform module (e.g., "hashicorp/consul/aws")
375
+ version: Optional specific version of the module to analyze
376
+ variables: Optional dictionary of variables to use when analyzing the module
377
+
378
+ Returns:
379
+ A SearchUserProvidedModuleResult object containing module information
380
+ """
381
+ request = SearchUserProvidedModuleRequest(
382
+ module_url=module_url,
383
+ version=version,
384
+ variables=variables,
385
+ )
386
+ return await search_user_provided_module_impl(request)
387
+
388
+
389
+ # * Resources
390
+ @mcp.resource(
391
+ name='terraform_development_workflow',
392
+ uri='terraform://development_workflow',
393
+ description='Terraform Development Workflow Guide with integrated validation and security scanning',
394
+ mime_type='text/markdown',
395
+ )
396
+ async def terraform_development_workflow() -> str:
397
+ """Provides guidance for developing Terraform code and integrates with Terraform workflow commands."""
398
+ return f'{TERRAFORM_WORKFLOW_GUIDE}'
399
+
400
+
401
+ @mcp.resource(
402
+ name='terraform_aws_provider_resources_listing',
403
+ uri='terraform://aws_provider_resources_listing',
404
+ description='Comprehensive listing of AWS provider resources and data sources by service category',
405
+ mime_type='text/markdown',
406
+ )
407
+ async def terraform_aws_provider_resources_listing() -> str:
408
+ """Provides an up-to-date categorized listing of all AWS provider resources and data sources."""
409
+ return await terraform_aws_provider_assets_listing_impl()
410
+
411
+
412
+ @mcp.resource(
413
+ name='terraform_awscc_provider_resources_listing',
414
+ uri='terraform://awscc_provider_resources_listing',
415
+ description='Comprehensive listing of AWSCC provider resources and data sources by service category',
416
+ mime_type='text/markdown',
417
+ )
418
+ async def terraform_awscc_provider_resources_listing() -> str:
419
+ """Provides an up-to-date categorized listing of all AWSCC provider resources and data sources."""
420
+ return await terraform_awscc_provider_resources_listing_impl()
421
+
422
+
423
+ @mcp.resource(
424
+ name='terraform_aws_best_practices',
425
+ uri='terraform://aws_best_practices',
426
+ description='AWS Terraform Provider Best Practices from AWS Prescriptive Guidance',
427
+ mime_type='text/markdown',
428
+ )
429
+ async def terraform_aws_best_practices() -> str:
430
+ """Provides AWS Terraform Provider Best Practices guidance."""
431
+ return f'{AWS_TERRAFORM_BEST_PRACTICES}'
432
+
433
+
434
+ def main():
435
+ """Run the MCP server with CLI argument support."""
436
+ mcp.run()
437
+
438
+
439
+ if __name__ == '__main__':
440
+ main()