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.
- awslabs/__init__.py +17 -0
- awslabs/terraform_mcp_server/__init__.py +17 -0
- awslabs/terraform_mcp_server/impl/resources/__init__.py +25 -0
- awslabs/terraform_mcp_server/impl/resources/terraform_aws_provider_resources_listing.py +66 -0
- awslabs/terraform_mcp_server/impl/resources/terraform_awscc_provider_resources_listing.py +69 -0
- awslabs/terraform_mcp_server/impl/tools/__init__.py +33 -0
- awslabs/terraform_mcp_server/impl/tools/execute_terraform_command.py +223 -0
- awslabs/terraform_mcp_server/impl/tools/execute_terragrunt_command.py +320 -0
- awslabs/terraform_mcp_server/impl/tools/run_checkov_scan.py +376 -0
- awslabs/terraform_mcp_server/impl/tools/search_aws_provider_docs.py +691 -0
- awslabs/terraform_mcp_server/impl/tools/search_awscc_provider_docs.py +641 -0
- awslabs/terraform_mcp_server/impl/tools/search_specific_aws_ia_modules.py +458 -0
- awslabs/terraform_mcp_server/impl/tools/search_user_provided_module.py +349 -0
- awslabs/terraform_mcp_server/impl/tools/utils.py +572 -0
- awslabs/terraform_mcp_server/models/__init__.py +49 -0
- awslabs/terraform_mcp_server/models/models.py +381 -0
- awslabs/terraform_mcp_server/scripts/generate_aws_provider_resources.py +1240 -0
- awslabs/terraform_mcp_server/scripts/generate_awscc_provider_resources.py +1039 -0
- awslabs/terraform_mcp_server/scripts/scrape_aws_terraform_best_practices.py +143 -0
- awslabs/terraform_mcp_server/server.py +440 -0
- awslabs/terraform_mcp_server/static/AWSCC_PROVIDER_RESOURCES.md +3125 -0
- awslabs/terraform_mcp_server/static/AWS_PROVIDER_RESOURCES.md +3833 -0
- awslabs/terraform_mcp_server/static/AWS_TERRAFORM_BEST_PRACTICES.md +2523 -0
- awslabs/terraform_mcp_server/static/MCP_INSTRUCTIONS.md +142 -0
- awslabs/terraform_mcp_server/static/TERRAFORM_WORKFLOW_GUIDE.md +330 -0
- awslabs/terraform_mcp_server/static/__init__.py +38 -0
- awslabs_terraform_mcp_server-1.0.14.dist-info/METADATA +166 -0
- awslabs_terraform_mcp_server-1.0.14.dist-info/RECORD +30 -0
- awslabs_terraform_mcp_server-1.0.14.dist-info/WHEEL +4 -0
- awslabs_terraform_mcp_server-1.0.14.dist-info/entry_points.txt +2 -0
|
@@ -0,0 +1,381 @@
|
|
|
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
|
+
from pydantic import BaseModel, Field
|
|
16
|
+
from typing import Any, Dict, List, Literal, Optional
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class TerraformExecutionRequest(BaseModel):
|
|
20
|
+
"""Request model for Terraform command execution with parameters.
|
|
21
|
+
|
|
22
|
+
Attributes:
|
|
23
|
+
command: The Terraform command to execute (init, plan, validate, apply, destroy).
|
|
24
|
+
directory: Directory containing Terraform configuration files.
|
|
25
|
+
variables: Optional dictionary of Terraform variables to pass.
|
|
26
|
+
aws_region: Optional AWS region to use.
|
|
27
|
+
strip_ansi: Whether to strip ANSI color codes from command output.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
command: Literal['init', 'plan', 'validate', 'apply', 'destroy'] = Field(
|
|
31
|
+
..., description='Terraform command to execute'
|
|
32
|
+
)
|
|
33
|
+
working_directory: str = Field(..., description='Directory containing Terraform files')
|
|
34
|
+
variables: Optional[Dict[str, str]] = Field(None, description='Terraform variables to pass')
|
|
35
|
+
aws_region: Optional[str] = Field(None, description='AWS region to use')
|
|
36
|
+
strip_ansi: bool = Field(True, description='Whether to strip ANSI color codes from output')
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class SubmoduleInfo(BaseModel):
|
|
40
|
+
"""Model representing a Terraform submodule.
|
|
41
|
+
|
|
42
|
+
Attributes:
|
|
43
|
+
name: The name of the submodule.
|
|
44
|
+
path: Path to the submodule within the parent module.
|
|
45
|
+
description: Brief description of the submodule purpose.
|
|
46
|
+
readme_content: The README content of the submodule, when available.
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
name: str
|
|
50
|
+
path: str
|
|
51
|
+
description: Optional[str] = 'No description available'
|
|
52
|
+
readme_content: Optional[str] = None
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class TerraformVariable(BaseModel):
|
|
56
|
+
"""Model representing a Terraform variable definition.
|
|
57
|
+
|
|
58
|
+
Attributes:
|
|
59
|
+
name: The name of the variable.
|
|
60
|
+
type: The data type of the variable (string, number, bool, etc.).
|
|
61
|
+
description: Description of the variable's purpose.
|
|
62
|
+
default: Default value of the variable, if any.
|
|
63
|
+
required: Whether the variable is required (no default value).
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
name: str
|
|
67
|
+
type: Optional[str] = None
|
|
68
|
+
description: Optional[str] = None
|
|
69
|
+
default: Optional[Any] = None
|
|
70
|
+
required: bool = True
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class TerraformOutput(BaseModel):
|
|
74
|
+
"""Model representing a Terraform output definition.
|
|
75
|
+
|
|
76
|
+
Attributes:
|
|
77
|
+
name: The name of the output.
|
|
78
|
+
description: Description of the output's purpose.
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
name: str
|
|
82
|
+
description: Optional[str] = None
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class ModuleSearchResult(BaseModel):
|
|
86
|
+
"""Model representing search results from Terraform module registry.
|
|
87
|
+
|
|
88
|
+
Attributes:
|
|
89
|
+
name: The name of the Terraform module.
|
|
90
|
+
namespace: The module's namespace/organization.
|
|
91
|
+
provider: The provider (aws).
|
|
92
|
+
version: Latest version of the module.
|
|
93
|
+
url: URL to the module in the Terraform registry.
|
|
94
|
+
description: Brief description of the module's purpose.
|
|
95
|
+
readme_content: The README content of the module, when available.
|
|
96
|
+
input_count: Number of input variables defined by the module.
|
|
97
|
+
output_count: Number of outputs provided by the module.
|
|
98
|
+
version_details: Detailed information about the version from GitHub releases.
|
|
99
|
+
submodules: List of submodules contained in this module.
|
|
100
|
+
has_submodules: Whether this module contains submodules.
|
|
101
|
+
variables: List of variables defined in the module's variables.tf file.
|
|
102
|
+
variables_content: Raw content of the variables.tf file.
|
|
103
|
+
outputs: List of outputs defined in the module's README file.
|
|
104
|
+
"""
|
|
105
|
+
|
|
106
|
+
name: str
|
|
107
|
+
namespace: str
|
|
108
|
+
provider: str = 'aws'
|
|
109
|
+
version: str
|
|
110
|
+
url: str
|
|
111
|
+
description: str
|
|
112
|
+
readme_content: Optional[str] = None
|
|
113
|
+
input_count: Optional[int] = None
|
|
114
|
+
output_count: Optional[int] = None
|
|
115
|
+
version_details: Optional[Dict[str, Any]] = None
|
|
116
|
+
submodules: Optional[list[SubmoduleInfo]] = None
|
|
117
|
+
variables: Optional[List[TerraformVariable]] = None
|
|
118
|
+
variables_content: Optional[str] = None
|
|
119
|
+
outputs: Optional[List[TerraformOutput]] = None
|
|
120
|
+
|
|
121
|
+
@property
|
|
122
|
+
def has_submodules(self) -> bool:
|
|
123
|
+
"""Check if the module has any submodules."""
|
|
124
|
+
return self.submodules is not None and len(self.submodules) > 0
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
class TerraformProviderDocsResult(BaseModel):
|
|
128
|
+
"""Abstract Model representing documentation results for Terraform Providers.
|
|
129
|
+
|
|
130
|
+
Attributes:
|
|
131
|
+
asset_name: Name of the AWS resource type.
|
|
132
|
+
asset_type: Type of the item - resource or data source.
|
|
133
|
+
description: Brief description of the resource.
|
|
134
|
+
url: URL to the documentation for this resource.
|
|
135
|
+
example_usage: List of example code snippets with titles.
|
|
136
|
+
"""
|
|
137
|
+
|
|
138
|
+
asset_name: str = Field(..., description='Name of the AWS resource type')
|
|
139
|
+
asset_type: Literal['both', 'resource', 'data_source'] = Field(
|
|
140
|
+
default='both', description="Type of the item - 'resource' or 'data_source' or 'both'"
|
|
141
|
+
)
|
|
142
|
+
description: Optional[str] = Field(..., description='Brief description of the resource')
|
|
143
|
+
url: Optional[str] = Field(None, description='URL to the documentation for this resource')
|
|
144
|
+
example_usage: Optional[List[Dict[str, str]]] = Field(
|
|
145
|
+
None, description='List of example snippets with titles'
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class TerraformAWSProviderDocsResult(TerraformProviderDocsResult):
|
|
150
|
+
"""Model representing documentation results for AWS Terraform Provider.
|
|
151
|
+
|
|
152
|
+
Attributes:
|
|
153
|
+
arguments: List of arguments with descriptions specific to AWS provider resources.
|
|
154
|
+
attributes: List of attributes with descriptions specific to AWS provider resources.
|
|
155
|
+
"""
|
|
156
|
+
|
|
157
|
+
arguments: Optional[List[Dict[str, str]]] = Field(
|
|
158
|
+
None, description='List of arguments with descriptions'
|
|
159
|
+
)
|
|
160
|
+
attributes: Optional[List[Dict[str, str]]] = Field(
|
|
161
|
+
None, description='List of attributes with descriptions'
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
class TerraformAWSCCProviderDocsResult(TerraformProviderDocsResult):
|
|
166
|
+
"""Model representing documentation results for AWSCC Terraform Provider.
|
|
167
|
+
|
|
168
|
+
Attributes:
|
|
169
|
+
schema_arguments: List of schema arguments with descriptions where applicable.
|
|
170
|
+
Contains the full resource schema definition from the AWSCC provider split by section.
|
|
171
|
+
"""
|
|
172
|
+
|
|
173
|
+
schema_arguments: Optional[List[Dict[str, Any]]] = Field(
|
|
174
|
+
None,
|
|
175
|
+
description='List of schema arguments with descriptions where applicable',
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
class TerraformExecutionResult(BaseModel):
|
|
180
|
+
"""Result model for Terraform command execution.
|
|
181
|
+
|
|
182
|
+
Attributes:
|
|
183
|
+
command: The Terraform command that was executed.
|
|
184
|
+
status: Execution status (success/error).
|
|
185
|
+
return_code: The command's return code (0 for success).
|
|
186
|
+
stdout: Standard output from the Terraform command.
|
|
187
|
+
stderr: Standard error output from the Terraform command.
|
|
188
|
+
working_directory: Directory where the command was executed.
|
|
189
|
+
error_message: Optional error message if execution failed.
|
|
190
|
+
outputs: Dictionary of output values from Terraform (for apply command).
|
|
191
|
+
"""
|
|
192
|
+
|
|
193
|
+
command: str
|
|
194
|
+
status: Literal['success', 'error']
|
|
195
|
+
return_code: Optional[int] = None
|
|
196
|
+
stdout: Optional[str] = None
|
|
197
|
+
stderr: str = ''
|
|
198
|
+
working_directory: str
|
|
199
|
+
error_message: Optional[str] = None
|
|
200
|
+
outputs: Optional[Dict[str, Any]] = Field(
|
|
201
|
+
None, description='Terraform outputs (for apply command)'
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
class CheckovVulnerability(BaseModel):
|
|
206
|
+
"""Model representing a security vulnerability found by Checkov.
|
|
207
|
+
|
|
208
|
+
Attributes:
|
|
209
|
+
id: The Checkov check ID (e.g., CKV_AWS_1).
|
|
210
|
+
type: The type of check (e.g., terraform_aws).
|
|
211
|
+
resource: The resource identifier where the vulnerability was found.
|
|
212
|
+
file_path: Path to the file containing the vulnerability.
|
|
213
|
+
line: Line number where the vulnerability was found.
|
|
214
|
+
description: Description of the vulnerability.
|
|
215
|
+
guideline: Recommended fix or security guideline.
|
|
216
|
+
severity: Severity level of the vulnerability.
|
|
217
|
+
fixed: Whether the vulnerability has been fixed.
|
|
218
|
+
fix_details: Details about how the vulnerability was fixed (if applicable).
|
|
219
|
+
"""
|
|
220
|
+
|
|
221
|
+
id: str = Field(..., description='Checkov check ID')
|
|
222
|
+
type: str = Field(..., description='Type of security check')
|
|
223
|
+
resource: str = Field(..., description='Resource identifier')
|
|
224
|
+
file_path: str = Field(..., description='Path to the file with the vulnerability')
|
|
225
|
+
line: int = Field(..., description='Line number of the vulnerability')
|
|
226
|
+
description: str = Field(..., description='Description of the vulnerability')
|
|
227
|
+
guideline: Optional[str] = Field(None, description='Recommended fix or guideline')
|
|
228
|
+
severity: str = Field('MEDIUM', description='Severity level (HIGH, MEDIUM, LOW)')
|
|
229
|
+
fixed: bool = Field(False, description='Whether the vulnerability has been fixed')
|
|
230
|
+
fix_details: Optional[str] = Field(None, description='Details about the fix applied')
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
class CheckovScanRequest(BaseModel):
|
|
234
|
+
"""Request model for Checkov scan execution.
|
|
235
|
+
|
|
236
|
+
Attributes:
|
|
237
|
+
working_directory: Directory containing Terraform files to scan.
|
|
238
|
+
framework: Framework to scan (default: terraform).
|
|
239
|
+
check_ids: Optional list of specific check IDs to run.
|
|
240
|
+
skip_check_ids: Optional list of check IDs to skip.
|
|
241
|
+
output_format: Format for the scan results output.
|
|
242
|
+
"""
|
|
243
|
+
|
|
244
|
+
working_directory: str = Field(..., description='Directory containing Terraform files')
|
|
245
|
+
framework: str = Field(
|
|
246
|
+
'terraform', description='Framework to scan (terraform, cloudformation, etc.)'
|
|
247
|
+
)
|
|
248
|
+
check_ids: Optional[List[str]] = Field(None, description='Specific check IDs to run')
|
|
249
|
+
skip_check_ids: Optional[List[str]] = Field(None, description='Check IDs to skip')
|
|
250
|
+
output_format: str = Field('json', description='Output format (json, cli, etc.)')
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
class CheckovScanResult(BaseModel):
|
|
254
|
+
"""Result model for Checkov scan execution.
|
|
255
|
+
|
|
256
|
+
Attributes:
|
|
257
|
+
status: Execution status (success/error).
|
|
258
|
+
return_code: The command's return code (0 for success).
|
|
259
|
+
working_directory: Directory where the scan was executed.
|
|
260
|
+
error_message: Optional error message if execution failed.
|
|
261
|
+
vulnerabilities: List of vulnerabilities found by the scan.
|
|
262
|
+
summary: Summary of the scan results.
|
|
263
|
+
raw_output: Raw output from the Checkov command.
|
|
264
|
+
"""
|
|
265
|
+
|
|
266
|
+
status: Literal['success', 'error']
|
|
267
|
+
return_code: Optional[int] = None
|
|
268
|
+
working_directory: str
|
|
269
|
+
error_message: Optional[str] = None
|
|
270
|
+
vulnerabilities: List[CheckovVulnerability] = Field(
|
|
271
|
+
[], description='List of found vulnerabilities'
|
|
272
|
+
)
|
|
273
|
+
summary: Dict[str, Any] = Field({}, description='Summary of scan results')
|
|
274
|
+
raw_output: Optional[str] = Field(None, description='Raw output from Checkov')
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
class SearchUserProvidedModuleRequest(BaseModel):
|
|
278
|
+
"""Request model for searching user-provided Terraform modules.
|
|
279
|
+
|
|
280
|
+
Attributes:
|
|
281
|
+
module_url: URL of the Terraform module in the registry (e.g., 'hashicorp/consul/aws').
|
|
282
|
+
version: Optional specific version of the module to analyze.
|
|
283
|
+
variables: Optional dictionary of variables to use when analyzing the module.
|
|
284
|
+
"""
|
|
285
|
+
|
|
286
|
+
module_url: str = Field(
|
|
287
|
+
..., description='URL or identifier of the Terraform module (e.g., "hashicorp/consul/aws")'
|
|
288
|
+
)
|
|
289
|
+
version: Optional[str] = Field(None, description='Specific version of the module to analyze')
|
|
290
|
+
variables: Optional[Dict[str, Any]] = Field(
|
|
291
|
+
None, description='Variables to use when analyzing the module'
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
class SearchUserProvidedModuleResult(BaseModel):
|
|
296
|
+
"""Result model for searching user-provided Terraform modules.
|
|
297
|
+
|
|
298
|
+
Attributes:
|
|
299
|
+
status: Execution status (success/error).
|
|
300
|
+
module_name: Name of the analyzed module.
|
|
301
|
+
module_url: URL of the module in the registry.
|
|
302
|
+
module_version: Version of the module that was analyzed.
|
|
303
|
+
module_description: Description of the module.
|
|
304
|
+
variables: List of variables defined by the module.
|
|
305
|
+
outputs: List of outputs provided by the module.
|
|
306
|
+
readme_content: The README content of the module.
|
|
307
|
+
error_message: Optional error message if execution failed.
|
|
308
|
+
"""
|
|
309
|
+
|
|
310
|
+
status: Literal['success', 'error']
|
|
311
|
+
module_name: str
|
|
312
|
+
module_url: str
|
|
313
|
+
module_version: str
|
|
314
|
+
module_description: str
|
|
315
|
+
variables: List[TerraformVariable] = Field([], description='Variables defined by the module')
|
|
316
|
+
outputs: List[TerraformOutput] = Field([], description='Outputs provided by the module')
|
|
317
|
+
readme_content: Optional[str] = Field(None, description='README content of the module')
|
|
318
|
+
error_message: Optional[str] = Field(None, description='Error message if execution failed')
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
class TerragruntExecutionRequest(BaseModel):
|
|
322
|
+
"""Request model for Terragrunt command execution with parameters.
|
|
323
|
+
|
|
324
|
+
Attributes:
|
|
325
|
+
command: The Terragrunt command to execute (init, plan, validate, apply, destroy, etc.).
|
|
326
|
+
working_directory: Directory containing Terragrunt configuration files.
|
|
327
|
+
variables: Optional dictionary of Terraform variables to pass.
|
|
328
|
+
aws_region: Optional AWS region to use.
|
|
329
|
+
strip_ansi: Whether to strip ANSI color codes from command output.
|
|
330
|
+
include_dirs: Optional list of directories to include in a multi-module run.
|
|
331
|
+
exclude_dirs: Optional list of directories to exclude from a multi-module run.
|
|
332
|
+
run_all: Whether to run the command in all subdirectories with terragrunt.hcl files.
|
|
333
|
+
"""
|
|
334
|
+
|
|
335
|
+
command: Literal['init', 'plan', 'validate', 'apply', 'destroy', 'output', 'run-all'] = Field(
|
|
336
|
+
..., description='Terragrunt command to execute'
|
|
337
|
+
)
|
|
338
|
+
working_directory: str = Field(..., description='Directory containing Terragrunt files')
|
|
339
|
+
variables: Optional[Dict[str, str]] = Field(None, description='Terraform variables to pass')
|
|
340
|
+
aws_region: Optional[str] = Field(None, description='AWS region to use')
|
|
341
|
+
strip_ansi: bool = Field(True, description='Whether to strip ANSI color codes from output')
|
|
342
|
+
include_dirs: Optional[List[str]] = Field(
|
|
343
|
+
None, description='Directories to include in a multi-module run'
|
|
344
|
+
)
|
|
345
|
+
exclude_dirs: Optional[List[str]] = Field(
|
|
346
|
+
None, description='Directories to exclude from a multi-module run'
|
|
347
|
+
)
|
|
348
|
+
run_all: bool = Field(False, description='Run command on all modules in subdirectories')
|
|
349
|
+
terragrunt_config: Optional[str] = Field(
|
|
350
|
+
None, description='Path to a custom terragrunt config file (not valid with run-all)'
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
class TerragruntExecutionResult(BaseModel):
|
|
355
|
+
"""Result model for Terragrunt command execution.
|
|
356
|
+
|
|
357
|
+
Attributes:
|
|
358
|
+
command: The Terragrunt command that was executed.
|
|
359
|
+
status: Execution status (success/error).
|
|
360
|
+
return_code: The command's return code (0 for success).
|
|
361
|
+
stdout: Standard output from the Terragrunt command.
|
|
362
|
+
stderr: Standard error output from the Terragrunt command.
|
|
363
|
+
working_directory: Directory where the command was executed.
|
|
364
|
+
error_message: Optional error message if execution failed.
|
|
365
|
+
outputs: Dictionary of output values from Terragrunt (for apply command).
|
|
366
|
+
affected_dirs: List of directories affected by a run-all command.
|
|
367
|
+
"""
|
|
368
|
+
|
|
369
|
+
command: str
|
|
370
|
+
status: Literal['success', 'error']
|
|
371
|
+
return_code: Optional[int] = None
|
|
372
|
+
stdout: Optional[str] = None
|
|
373
|
+
stderr: str = ''
|
|
374
|
+
working_directory: str
|
|
375
|
+
error_message: Optional[str] = None
|
|
376
|
+
outputs: Optional[Dict[str, Any]] = Field(
|
|
377
|
+
None, description='Terragrunt outputs (for apply or output command)'
|
|
378
|
+
)
|
|
379
|
+
affected_dirs: Optional[List[str]] = Field(
|
|
380
|
+
None, description='Directories affected by a run-all command'
|
|
381
|
+
)
|