Skip to content
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

Feat/iac_init_service #125

Merged
merged 25 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
649c4c3
feat(iac): Add file watcher to init iac proj and download modules on …
May 12, 2024
6c18347
feat(settings): Add setting to enable service
May 12, 2024
0f95fb7
refac(command): Refactor init command to allow run for specific direc…
May 12, 2024
db20b34
rename models with iac prefix
May 12, 2024
f544b70
add semaphore
May 12, 2024
b478c8b
feat(projectHelper): Add new methods to get installed providers
May 12, 2024
70915e7
add service to startup when enabled
May 12, 2024
2da1b24
enable additional eslint rules and bump typscript target lang
May 12, 2024
e6bbcc3
some code cleanup
May 12, 2024
20a2c73
create new set
May 12, 2024
0394a7d
fix default value for setting and add experimental hint
Noahnc May 13, 2024
15313c3
feat(services): Split provider auto init and module fetch to individu…
May 13, 2024
610aaf3
refac(iacInitService): Change interval to delayd que for modules and …
May 21, 2024
8ea53dd
refac(iacAutoInit): Match installed provider version with constraint …
May 21, 2024
2782fd3
refac(iacParsing): Move parsing from ProjectHelper to own class
Noahnc May 22, 2024
5ce9f67
doc(README): Add doc regarding auto modules fetch and auto provider i…
Noahnc May 22, 2024
1ea87f6
feat(ProviderDetection): Add check if provider is installed in filesy…
Noahnc May 22, 2024
6470da6
refac(fileSystemOperations): Switch form sync file system operations …
May 26, 2024
80087b5
refac(iacInitService): Process modules and providers in single proces…
May 26, 2024
5477432
improve service logic
May 26, 2024
5207c3a
feat(settings): Add new setting to control the processQueue delay
May 26, 2024
162aa88
refac(initService): Improve parallelization
May 26, 2024
074acd3
doc(README): Add note regarding vscode auto save
May 26, 2024
28db1cd
Merge branch 'main' into feat/iac_init_service
Noahnc May 26, 2024
776fdc6
break(autoInit): Remove init all projects on startup setting
May 26, 2024
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
24 changes: 21 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
{
"env": {
"browser": true,
"es2021": true
"es2022": true
},
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest"
"ecmaVersion": "latest",
"project": "./tsconfig.json"
},
"plugins": ["@typescript-eslint"],
"rules": {
"prefer-template": "error",
"@typescript-eslint/no-floating-promises": "warn",
"@typescript-eslint/prefer-for-of": "error",
"id-match": "error",
"no-debugger": "error",
"no-multiple-empty-lines": "warn",
"no-trailing-spaces": "warn",
"no-underscore-dangle": "warn",
"no-var": "error",
"prefer-const": "error",
"@typescript-eslint/naming-convention": [
"error",
{
Expand Down Expand Up @@ -42,5 +52,13 @@
"format": ["PascalCase"]
}
]
}
},
"overrides": [
{
"files": ["*.ts"],
"parserOptions": {
"project": "./tsconfig.json"
}
}
]
}
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ VSCode extension adding a bunch of featurees regarding Terraform / OpenTofu and
- [Terraform / OpenTofu version manager](#terraform--opentofu-version-manager-1)
- [Terraform / OpenTofu workspace](#terraform--opentofu-workspace)
- [Terraform / OpenTofu Init](#terraform--opentofu-init)
- [Auto-install providers](#auto-install-providers)
- [Auto-fetch modules](#auto-fetch-modules)
- [Spacelift](#spacelift-1)
- [Important Notes](#important-notes)

Expand Down Expand Up @@ -112,10 +114,21 @@ Tired of switching between workspaces in the terminal? This extension adds a sta
Since the init command is required for many features of the official Hashicorp Terraform extension to work, this extension adds some features to make the terraform init process easier:

- Command [`tftoolbox.iac.initCurrentProject`]: Run terraform / tofu init in the current folder. Similar to the init Command of the official Hashicorp Terraform extension, but it allows you to specify additional init arguments with the setting `tftoolbox.iac.initArg`.
- Command [`tftoolbox.iac.initAllProjects`]: Finds all terraform folders in your open workspaces and runs terraform init in each of them asynchronically. With the setting `tftoolbox.iac.autoInitAllProjects` you can enable to auto init all folders when opening VSCode. More information can be found here: [Terraform init all projects](docs/initAllProjects.md)
- Command [`tftoolbox.iac.initAllProjects`]: Finds all terraform folders in your open workspaces and runs terraform init in each of them asynchronically. More information can be found here: [Terraform init all projects](docs/initAllProjects.md)
![terraform-init](Images/examples/terraform_init.gif)
- Command [`tftoolbox.iac.refreshModules`]: Installs missing modules for the current folder.

#### Auto-install providers

By enabling the setting `tftoolbox.iac.enableAutoInit`, the extension will automatically initialize a terraform / opentofu project when a changed .tf file contains a provider version constraint for which no provider is currently installed. The extension will then run terraform / opentofu init in that folder.

> [!IMPORTANT]
> This feature is experimental and might use lots of system resources when switching branches in git with many provider version changes. It is also not recommended to use in combination with the vscode setting `Auto Save: afterDelay`. Instead, use the setting `Auto Save: onFocusChange` or `Auto Save: onWindowChange`.

#### Auto-fetch modules

With the setting `tftoolbox.iac.enableAutoModuleFetch`, the extension will automatically fetch modules for a terraform / opentofu project when a .tf file with declared modules changes.

### Spacelift

Spacelift is a IaC CI/CD tool. They provide a cli-tool, called spacectl, that allows you to run proposed runs of your local code on Spacelift. However, the cli requires you to specify the Spacelift stack-id and the working directory of the project, for which the proposed run should be created. To make this process easier, this extension adds two commands as wrapper around the spacectl:
Expand Down
32 changes: 31 additions & 1 deletion package-lock.json

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

29 changes: 23 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,6 @@
"default": true,
"description": "When true, the terraform workspace will be set for each folder based on the .terraform-toolbox configuration file in the workspace root."
},
"tftoolbox.iac.autoInitAllProjects": {
"type": "boolean",
"default": false,
"description": "If set to true, the extension will run terraform init for all folders in your workspace containing terraform files on startup."
},
"tftoolbox.iac.initArg": {
"type": "string",
"default": "-upgrade",
Expand All @@ -135,6 +130,26 @@
"default": true,
"description": "Disable startup waring if spacectl is not installed and authenticated."
},
"tftoolbox.iac.enableAutoProviderInitialization": {
"type": "boolean",
"title": "Enable Provider auto init (experimental)",
"default": false,
"description": "Automatically initializes a terraform / opentofu project if a declared provider is not installed when a terraform / opentofu file is saved. This feature is experimental and may degrade performance."
},
"tftoolbox.iac.enableAutoModuleFetch": {
"type": "boolean",
"title": "Enable auto Module fetch",
"default": false,
"description": "If enabled, the extension will automatically fetch missing modules when a terraform / opentofu file is saved."
},
"tftoolbox.iac.resourceProcessingQueDelayMs": {
"type": "number",
"title": "Time in ms to delay the processing of projects",
"default": 600,
"minimum": 300,
"maximum": 5000,
"description": "Time in ms to wait before start processing .tf files added by the tftoolbox.iac.enableAutoModuleFetch or tftoolbox.iac.enableAutoProviderInitialization feature. This works as buffer when multiple files in the same folder change shortly after each other (e.g by a git pull or branch switch)."
},
"tftoolbox.iac.showNoIacProviderVersionInstalledMsgOnStart": {
"type": "boolean",
"default": true,
Expand Down Expand Up @@ -204,6 +219,7 @@
},
"devDependencies": {
"@types/chai": "^4.3.11",
"@types/chai-as-promised": "^7.1.8",
"@types/decompress": "^4.2.7",
"@types/glob": "^8.1.0",
"@types/mocha": "^10.0.6",
Expand All @@ -213,6 +229,8 @@
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.10.0",
"@vscode/test-electron": "^2.3.10",
"chai": "^4.3.10",
"chai-as-promised": "^7.1.2",
"depcheck": "^1.4.6",
"esbuild": "^0.20.2",
"eslint": "^8.57.0",
Expand All @@ -223,7 +241,6 @@
"dependencies": {
"@vscode-logging/wrapper": "^2.0.0",
"axios": "1.6.8",
"chai": "^4.3.10",
"decompress": "^4.2.1",
"graphql-request": "^6.1.0",
"hcl2-parser": "^1.0.3",
Expand Down
1 change: 1 addition & 0 deletions src/commands/BaseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export abstract class BaseCommand {

function handleError(error: Error) {
if (error instanceof UserShownError) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
vscode.window.showErrorMessage(error.message);
}
getLogger().error(`Error running command: ${error.toString()}`);
Expand Down
Loading
Loading