-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathRemove-TerraformMetaFileSet.ps1
More file actions
40 lines (36 loc) · 1.34 KB
/
Remove-TerraformMetaFileSet.ps1
File metadata and controls
40 lines (36 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function Remove-TerraformMetaFileSet {
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[Parameter(Mandatory = $false)]
[string]$path,
[Parameter(Mandatory = $false)]
[array]$terraformFilesOrFoldersToRemove = $(
"terraform.tfstate",
"terraform.tfstate.backup",
".terraform",
"terraform.tfvars",
".terraform.lock.hcl",
"examples",
"yaml.tf",
".alzlib"
),
[Parameter(Mandatory = $false)]
[switch]$writeVerboseLogs
)
if ($PSCmdlet.ShouldProcess("Remove files", "modify")) {
Write-Verbose "Removing Terraform meta files and folders from $path"
if ($terraformFilesOrFoldersToRemove.Length -eq 0 ) {
Write-Verbose "No folders or files specified, so not removing anything from $path"
return
}
$filesAndFolders = Get-ChildItem -Path $path -Force
foreach ($fileOrFolder in $filesAndFolders) {
if ($terraformFilesOrFoldersToRemove -contains $fileOrFolder.Name) {
if ($writeVerboseLogs) {
Write-Verbose "Exact Match - Removing: $($fileOrFolder.FullName)"
}
Remove-Item -Path $fileOrFolder.FullName -Force -Recurse | Out-Null
}
}
}
}