infracost_cloud_update_tagging_policy
Update tagging policies in Infracost Cloud to validate allowed tag values in pull requests, ensuring compliance with organizational standards.
Instructions
Update tagging policies in Infracost Cloud with allowed tag values for validation in pull requests. Requires INFRACOST_SERVICE_TOKEN environment variable.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| orgSlug | No | Organization slug from Infracost Cloud (defaults to INFRACOST_ORG env var) | |
| policyId | Yes | Policy ID from the URL in Infracost Cloud UI | |
| name | No | Name for the tagging policy | |
| message | No | The message to display in the PR comment | |
| prComment | No | Whether to add a comment to the PR | |
| blockPr | No | Whether to block the PR | |
| tags | No | Array of tag definitions | |
| filters | No | Filters to limit scope of the policy |
Implementation Reference
- src/tools.ts:406-431 (handler)Handler function in InfracostTools that processes the tool call, validates arguments, determines orgSlug, calls the API client to update the policy, and returns the result.
async handleUpdateTaggingPolicy(args: z.infer<typeof UpdateTaggingPolicySchema>) { if (!this.cloudApiClient) { throw new Error('INFRACOST_SERVICE_TOKEN is not configured for Infracost Cloud API operations'); } const orgSlug = args.orgSlug || this.config.orgSlug; if (!orgSlug) { throw new Error('Organization slug is required. Provide it via orgSlug parameter or set INFRACOST_ORG environment variable'); } const { policyId, orgSlug: _, ...updateData } = args; const result = await this.cloudApiClient.updateTaggingPolicy(orgSlug, policyId, updateData); if (!result.success) { throw new Error(result.error || 'Update tagging policy request failed'); } return { content: [ { type: 'text', text: result.output || 'Tagging policy updated successfully', }, ], }; } - src/api.ts:137-176 (helper)Core API client method that sends PATCH request to Infracost Cloud API to update the tagging policy.
async updateTaggingPolicy( orgSlug: string, policyId: string, request: UpdateTaggingPolicyRequest ): Promise<CommandResult> { try { const response = await fetch( `${INFRACOST_CLOUD_API_BASE}/orgs/${orgSlug}/tagging-policies/${policyId}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${this.serviceToken}`, }, body: JSON.stringify({ data: { type: 'tagging-policies', attributes: request } }), } ); if (!response.ok) { const errorText = await response.text(); return { success: false, error: `API request failed with status ${response.status}: ${errorText}`, }; } const data = await response.json(); return { success: true, output: JSON.stringify(data, null, 2), data, }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : 'Unknown error occurred', }; } } - src/tools.ts:65-106 (schema)Zod schema defining the input parameters and validation for the tool.
export const UpdateTaggingPolicySchema = z.object({ orgSlug: z.string().optional().describe('Organization slug from Infracost Cloud (defaults to INFRACOST_ORG env var)'), policyId: z.string().describe('Policy ID from the URL in Infracost Cloud UI'), name: z.string().optional().describe('Name for the tagging policy'), message: z.string().optional().describe('The message to display in the PR comment'), prComment: z.boolean().optional().describe('Whether to add a comment to the PR'), blockPr: z.boolean().optional().describe('Whether to block the PR'), tags: z .array( z.object({ key: z.string().describe('Tag key name'), mandatory: z.boolean().describe('Whether the tag is required'), valueType: z.enum(['ANY', 'LIST', 'REGEX']).describe('Value type: ANY (any value), LIST (predefined values), or REGEX (regex pattern)'), allowedValues: z.array(z.string()).optional().describe('List of allowed values (for LIST type)'), allowedRegex: z.string().optional().describe('Regex pattern for allowed values (for REGEX type)'), message: z.string().optional().describe('Optional message to display if the tag is missing/invalid'), }) ) .optional() .describe('Array of tag definitions'), filters: z .object({ repos: z.object({ include: z.array(z.string()).optional(), exclude: z.array(z.string()).optional(), }).optional().describe('Repository filters'), projects: z.object({ include: z.array(z.string()).optional(), exclude: z.array(z.string()).optional(), }).optional().describe('Project filters'), baseBranches: z.object({ include: z.array(z.string()).optional(), exclude: z.array(z.string()).optional(), }).optional().describe('Base branch filters'), resources: z.object({ include: z.array(z.string()).optional(), exclude: z.array(z.string()).optional(), }).optional().describe('Resource filters'), }) .optional() .describe('Filters to limit scope of the policy'), }); - src/index.ts:366-467 (registration)Tool registration in ListToolsRequestHandler, including name, description, and input schema.
name: 'infracost_cloud_update_tagging_policy', description: 'Update tagging policies in Infracost Cloud with allowed tag values for validation in pull requests. Requires INFRACOST_SERVICE_TOKEN environment variable.', inputSchema: { type: 'object', properties: { orgSlug: { type: 'string', description: 'Organization slug from Infracost Cloud (defaults to INFRACOST_ORG env var)', }, policyId: { type: 'string', description: 'Policy ID from the URL in Infracost Cloud UI', }, name: { type: 'string', description: 'Name for the tagging policy', }, message: { type: 'string', description: 'The message to display in the PR comment', }, prComment: { type: 'boolean', description: 'Whether to add a comment to the PR', }, blockPr: { type: 'boolean', description: 'Whether to block the PR', }, tags: { type: 'array', description: 'Array of tag definitions', items: { type: 'object', properties: { key: { type: 'string', description: 'Tag key name' }, mandatory: { type: 'boolean', description: 'Whether the tag is required' }, valueType: { type: 'string', enum: ['ANY', 'LIST', 'REGEX'], description: 'Value type: ANY (any value), LIST (predefined values), or REGEX (regex pattern)', }, allowedValues: { type: 'array', items: { type: 'string' }, description: 'List of allowed values (for LIST type)', }, allowedRegex: { type: 'string', description: 'Regex pattern for allowed values (for REGEX type)', }, message: { type: 'string', description: 'Optional message to display if the tag is missing/invalid', }, }, required: ['key', 'mandatory', 'valueType'], }, }, filters: { type: 'object', description: 'Filters to limit scope of the policy', properties: { repos: { type: 'object', description: 'Repository filters', properties: { include: { type: 'array', items: { type: 'string' } }, exclude: { type: 'array', items: { type: 'string' } }, }, }, projects: { type: 'object', description: 'Project filters', properties: { include: { type: 'array', items: { type: 'string' } }, exclude: { type: 'array', items: { type: 'string' } }, }, }, baseBranches: { type: 'object', description: 'Base branch filters', properties: { include: { type: 'array', items: { type: 'string' } }, exclude: { type: 'array', items: { type: 'string' } }, }, }, resources: { type: 'object', description: 'Resource filters', properties: { include: { type: 'array', items: { type: 'string' } }, exclude: { type: 'array', items: { type: 'string' } }, }, }, }, }, }, required: ['policyId'], }, }, - src/index.ts:744-747 (registration)Registration in CallToolRequestHandler switch statement, dispatching to the handler.
case 'infracost_cloud_update_tagging_policy': { const validatedArgs = UpdateTaggingPolicySchema.parse(args); return await tools.handleUpdateTaggingPolicy(validatedArgs); }