Skip to content

Commit

Permalink
TFC: Implement run panel for viewing plan
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Nov 14, 2023
1 parent d8961d5 commit 07a2105
Show file tree
Hide file tree
Showing 7 changed files with 664 additions and 17 deletions.
13 changes: 7 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 33 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,11 @@
{
"command": "terraform.cloud.run.plan.downloadLog",
"title": "View raw plan log",
"icon": "$(console)"
},
{
"command": "terraform.cloud.run.viewPlan",
"title": "View plan output",
"icon": "$(output)"
},
{
Expand Down Expand Up @@ -567,6 +572,10 @@
"command": "terraform.cloud.run.plan.downloadLog",
"when": "false"
},
{
"command": "terraform.cloud.run.viewPlan",
"when": "false"
},
{
"command": "terraform.cloud.run.apply.downloadLog",
"when": "false"
Expand Down Expand Up @@ -633,7 +642,12 @@
},
{
"command": "terraform.cloud.run.plan.downloadLog",
"when": "view == terraform.cloud.runs && viewItem =~ /hasPlan/",
"when": "view == terraform.cloud.runs && viewItem =~ /hasRawPlan/",
"group": "inline"
},
{
"command": "terraform.cloud.run.viewPlan",
"when": "view == terraform.cloud.runs && viewItem =~ /hasStructuredPlan/",
"group": "inline"
},
{
Expand Down Expand Up @@ -665,6 +679,12 @@
"name": "Runs",
"contextualTitle": "Terraform Cloud runs"
}
],
"terraform-cloud-panel": [
{
"id": "terraform.cloud.run.plan",
"name": "Plan"
}
]
},
"viewsContainers": {
Expand All @@ -679,6 +699,13 @@
"title": "HashiCorp Terraform Cloud",
"icon": "assets/icons/vs_code_terraform_cloud.svg"
}
],
"panel": [
{
"id": "terraform-cloud-panel",
"title": "Terraform Cloud",
"icon": "assets/icons/vs_code_terraform_cloud.svg"
}
]
},
"viewsWelcome": [
Expand Down Expand Up @@ -723,6 +750,10 @@
{
"view": "terraform.cloud.runs",
"contents": "Select a workspace to view a list of runs"
},
{
"view": "terraform.cloud.run.plan",
"contents": "Select a run to view a plan"
}
]
},
Expand Down Expand Up @@ -751,6 +782,7 @@
"@zodios/core": "^10.9.2",
"@zodios/plugins": "^10.6.0",
"axios": "^1.4.0",
"semver": "^7.5.4",
"vscode-languageclient": "8.1.0",
"vscode-uri": "^3.0.7",
"which": "^3.0.1",
Expand Down
14 changes: 12 additions & 2 deletions src/features/terraformCloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import TelemetryReporter from '@vscode/extension-telemetry';

import { WorkspaceTreeDataProvider, WorkspaceTreeItem } from '../providers/tfc/workspaceProvider';
import { RunTreeDataProvider } from '../providers/tfc/runProvider';
import { PlanTreeDataProvider } from '../providers/tfc/planProvider';
import { TerraformCloudAuthenticationProvider } from '../providers/authenticationProvider';
import {
CreateOrganizationItem,
Expand Down Expand Up @@ -56,7 +57,14 @@ export class TerraformCloudFeature implements vscode.Disposable {
),
);

const runDataProvider = new RunTreeDataProvider(this.context, this.reporter, outputChannel);
const planDataProvider = new PlanTreeDataProvider(this.context, this.reporter, outputChannel);
const planView = vscode.window.createTreeView('terraform.cloud.run.plan', {
canSelectMany: false,
showCollapseAll: true,
treeDataProvider: planDataProvider,
});

const runDataProvider = new RunTreeDataProvider(this.context, this.reporter, outputChannel, planDataProvider);
const runView = vscode.window.createTreeView('terraform.cloud.runs', {
canSelectMany: false,
showCollapseAll: true,
Expand All @@ -77,7 +85,7 @@ export class TerraformCloudFeature implements vscode.Disposable {
const organization = this.context.workspaceState.get('terraform.cloud.organization', '');
workspaceView.title = organization !== '' ? `Workspaces - (${organization})` : 'Workspaces';

this.context.subscriptions.push(runView, runDataProvider, workspaceDataProvider, workspaceView);
this.context.subscriptions.push(runView, planView, runDataProvider, workspaceDataProvider, workspaceView);

workspaceView.onDidChangeSelection((event) => {
if (event.selection.length <= 0) {
Expand All @@ -89,6 +97,7 @@ export class TerraformCloudFeature implements vscode.Disposable {
if (item instanceof WorkspaceTreeItem) {
// call the TFC Run provider with the workspace
runDataProvider.refresh(item);
planDataProvider.refresh();
}
});

Expand All @@ -100,6 +109,7 @@ export class TerraformCloudFeature implements vscode.Disposable {
workspaceDataProvider.reset();
workspaceDataProvider.refresh();
runDataProvider.refresh();
planDataProvider.refresh();
}
});

Expand Down
43 changes: 43 additions & 0 deletions src/providers/tfc/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import * as vscode from 'vscode';
import { ChangeAction, DiagnosticSeverity } from '../../terraformCloud/log';

export function GetPlanApplyStatusIcon(status?: string): vscode.ThemeIcon {
switch (status) {
Expand Down Expand Up @@ -148,6 +149,48 @@ export function GetRunStatusMessage(status?: string): string {
return 'No runs available';
}

export function GetChangeActionIcon(action: ChangeAction): vscode.ThemeIcon {
switch (action) {
case 'create':
return new vscode.ThemeIcon('diff-added', new vscode.ThemeColor('charts.green'));
case 'delete':
return new vscode.ThemeIcon('diff-removed', new vscode.ThemeColor('charts.red'));
case 'update':
return new vscode.ThemeIcon('diff-modified', new vscode.ThemeColor('charts.orange'));
case 'move':
return new vscode.ThemeIcon('diff-renamed', new vscode.ThemeColor('charts.orange'));
case 'replace':
return new vscode.ThemeIcon('arrow-swap', new vscode.ThemeColor('charts.orange'));
case 'read':
return new vscode.ThemeIcon('git-fetch', new vscode.ThemeColor('charts.blue'));
case 'import':
return new vscode.ThemeIcon('export', new vscode.ThemeColor('charts.blue'));
case 'noop':
return new vscode.ThemeIcon('diff-ignored', new vscode.ThemeColor('charts.grey'));
}
}

export function GetDriftChangeActionMessage(action: ChangeAction): string {
switch (action) {
case 'update':
return 'updated';
case 'delete':
return 'deleted';
default:
// Other actions are not defined for drifts
return 'unknown';
}
}

export function GetDiagnosticSeverityIcon(severity: DiagnosticSeverity): vscode.ThemeIcon {
switch (severity) {
case 'warning':
return new vscode.ThemeIcon('warning', new vscode.ThemeColor('charts.orange'));
case 'error':
return new vscode.ThemeIcon('error', new vscode.ThemeColor('charts.red'));
}
}

export function RelativeTimeFormat(d: Date): string {
const SECONDS_IN_MINUTE = 60;
const SECONDS_IN_HOUR = SECONDS_IN_MINUTE * 60;
Expand Down
Loading

0 comments on commit 07a2105

Please sign in to comment.