@@ -33,7 +33,7 @@ import (
3333 " context"
3434 " fmt"
3535 " log"
36-
36+
3737 " github.com/terramate-io/terramate-mcp-server/sdk/terramate"
3838)
3939
@@ -45,32 +45,32 @@ func main() {
4545 if err != nil {
4646 log.Fatalf (" Failed to load credentials: %v \n Run 'terramate cloud login' first" , err)
4747 }
48-
48+
4949 // Create client with JWT
5050 client , err := terramate.NewClient (credential,
5151 terramate.WithRegion (" eu" ))
5252 if err != nil {
5353 log.Fatal (err)
5454 }
55-
55+
5656 ctx := context.Background ()
57-
57+
5858 // List organizations
5959 memberships , _ , err := client.Memberships .List (ctx)
6060 if err != nil {
6161 log.Fatal (err)
6262 }
63-
63+
6464 orgUUID := memberships[0 ].OrgUUID
65-
65+
6666 // List drifted stacks
6767 stacks , _ , err := client.Stacks .List (ctx, orgUUID, &terramate.StacksListOptions {
6868 DriftStatus: []string {" drifted" },
6969 })
7070 if err != nil {
7171 log.Fatal (err)
7272 }
73-
73+
7474 fmt.Printf (" Found %d drifted stacks\n " , len (stacks.Stacks ))
7575}
7676```
@@ -308,11 +308,11 @@ details, _, err := client.ReviewRequests.Get(ctx, orgUUID, reviewRequestID, nil)
308308for _ , sp := range details.StackPreviews {
309309 fmt.Printf (" Stack: %s \n " , sp.Stack .Path )
310310 fmt.Printf (" Status: %s \n " , sp.Status )
311-
311+
312312 if sp.ChangesetDetails != nil {
313313 fmt.Println (sp.ChangesetDetails .ChangesetASCII ) // Terraform plan
314314 }
315-
315+
316316 // See change counts
317317 if sp.ResourceChanges != nil {
318318 fmt.Printf (" Creates: %d , Updates: %d , Deletes: %d \n " ,
@@ -345,7 +345,7 @@ deployments, _, err := client.Deployments.List(ctx, orgUUID,
345345
346346for _ , d := range deployments.Deployments {
347347 fmt.Printf (" Deployment #%d : %s \n " , d.ID , d.CommitTitle )
348- fmt.Printf (" Status: %s (%d ok, %d failed)\n " ,
348+ fmt.Printf (" Status: %s (%d ok, %d failed)\n " ,
349349 d.Status , d.OkCount , d.FailedCount )
350350}
351351
@@ -478,15 +478,15 @@ stacks, _, _ := client.Stacks.List(ctx, orgUUID, &terramate.StacksListOptions{
478478
479479// 2. For each drifted stack, get the drift details
480480for _ , stack := range stacks.Stacks {
481- drifts , _ , _ := client.Drifts .ListForStack (ctx, orgUUID, stack.StackID ,
481+ drifts , _ , _ := client.Drifts .ListForStack (ctx, orgUUID, stack.StackID ,
482482 &terramate.DriftsListOptions {
483483 DriftStatus: []string {" drifted" },
484484 PerPage: 1 , // Just the latest
485485 })
486-
486+
487487 if len (drifts.Drifts ) > 0 {
488488 drift , _ , _ := client.Drifts .Get (ctx, orgUUID, stack.StackID , drifts.Drifts [0 ].ID )
489-
489+
490490 fmt.Printf (" Stack: %s \n " , stack.MetaName )
491491 fmt.Printf (" Drift Plan:\n %s \n " , drift.DriftDetails .ChangesetASCII )
492492 }
@@ -503,7 +503,7 @@ reviews, _, _ := client.ReviewRequests.List(ctx, orgUUID,
503503 })
504504
505505// 2. Get PR with all stack terraform plans
506- details , _ , _ := client.ReviewRequests .Get (ctx, orgUUID,
506+ details , _ , _ := client.ReviewRequests .Get (ctx, orgUUID,
507507 reviews.ReviewRequests [0 ].ReviewRequestID , nil )
508508
509509// 3. Analyze each stack's changes
@@ -533,10 +533,10 @@ deployments, _, _ := client.Deployments.List(ctx, orgUUID,
533533for _ , d := range deployments.Deployments {
534534 fmt.Printf (" \n Deployment #%d : %s \n " , d.ID , d.CommitTitle )
535535 fmt.Printf (" Failed stacks: %d /%d \n " , d.FailedCount , d.StackDeploymentTotalCount )
536-
536+
537537 // 3. Get individual stack failures
538538 stackDeployments , _ , _ := client.Deployments .ListForWorkflow (ctx, orgUUID, d.ID , nil )
539-
539+
540540 for _ , sd := range stackDeployments.StackDeployments {
541541 if sd.Status == " failed" {
542542 deployment , _ , _ := client.Deployments .GetStackDeployment (ctx, orgUUID, sd.ID )
@@ -565,20 +565,20 @@ details, _, _ := client.ReviewRequests.Get(ctx, orgUUID, reviews.ReviewRequests[
565565for _ , sp := range details.StackPreviews {
566566 if sp.Status == " failed" {
567567 fmt.Printf (" \n ❌ Failed: %s (Preview ID: %d )\n " , sp.Stack .Path , sp.StackPreviewID )
568-
568+
569569 // 4. Get error logs for AI analysis
570570 logs , _ , _ := client.Previews .GetLogs (ctx, orgUUID, sp.StackPreviewID ,
571571 &terramate.PreviewLogsOptions {
572572 Channel: " stderr" , // Error messages
573573 PerPage: 100 ,
574574 })
575-
575+
576576 // 5. Display logs for AI to analyze
577577 fmt.Println (" Error logs:" )
578578 for _ , log := range logs.StackPreviewLogLines {
579579 fmt.Printf (" [%s ] %s \n " , log.Timestamp .Format (" 15:04:05" ), log.Message )
580580 }
581-
581+
582582 // AI can now analyze these logs and suggest fixes
583583 // Example errors:
584584 // - Provider authentication issues
@@ -611,19 +611,19 @@ stackDeps, _, _ := client.Deployments.ListForWorkflow(ctx, orgUUID, workflow.ID,
611611for _ , sd := range stackDeps.StackDeployments {
612612 if sd.Status == " failed" {
613613 // 4. Get deployment logs for AI analysis
614- logs , _ , _ := client.Deployments .GetDeploymentLogs (ctx, orgUUID,
614+ logs , _ , _ := client.Deployments .GetDeploymentLogs (ctx, orgUUID,
615615 sd.Stack .StackID , sd.DeploymentUUID ,
616616 &terramate.DeploymentLogsOptions {
617617 Channel: " stderr" ,
618618 PerPage: 100 ,
619619 })
620-
620+
621621 fmt.Printf (" \n ❌ Failed deployment: %s \n " , sd.Path )
622622 fmt.Println (" Error logs:" )
623623 for _ , log := range logs.DeploymentLogLines {
624624 fmt.Printf (" [%s ] %s \n " , log.Timestamp .Format (" 15:04:05" ), log.Message )
625625 }
626-
626+
627627 // AI analyzes logs and provides:
628628 // - Root cause identification
629629 // - Fix suggestions
0 commit comments