Skip to content

TFC: Implement run panel for viewing plan #1590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

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

35 changes: 34 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,13 @@
"name": "Runs",
"contextualTitle": "Terraform Cloud runs"
}
],
"terraform-cloud-panel": [
{
"id": "terraform.cloud.run.plan",
"name": "Plan",
"when": "terraform.cloud.run.viewingPlan"
}
]
},
"viewsContainers": {
Expand All @@ -679,6 +700,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 +751,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 +783,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
21 changes: 19 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,14 @@ 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,
planDataProvider,
runDataProvider,
workspaceDataProvider,
workspaceView,
);

workspaceView.onDidChangeSelection((event) => {
if (event.selection.length <= 0) {
Expand All @@ -89,6 +104,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 +116,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