-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gen-Providers.ps1
43 lines (33 loc) · 1.33 KB
/
Gen-Providers.ps1
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
41
42
43
param(
[Parameter(ValueFromPipelineByPropertyName = $true)]
[string]$VAULTNAME,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[string]$VAULTGROUP,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[string]$BUCKETREGION
)
# Check and create .\Deploy directory if it doesn't exist
$deployPath = ".\Deploy"
if (-not (Test-Path -Path $deployPath)) {
New-Item -ItemType Directory -Path $deployPath
}
# Copy providers.tf template to .\Deploy
$templatePath = ".\templates\providers.tf"
$deployFilePath = Join-Path $deployPath "providers.tf"
Copy-Item -Path $templatePath -Destination $deployFilePath -Force
# Function to replace placeholder in file
function Replace-PlaceholderInFile {
param($filePath, $placeholder, $value)
(Get-Content $filePath) -replace "<<<$placeholder>>>", $value | Set-Content $filePath
}
# Replace placeholders with parameter values
Replace-PlaceholderInFile -filePath $deployFilePath -placeholder "VAULTNAME" -value $VAULTNAME
Replace-PlaceholderInFile -filePath $deployFilePath -placeholder "VAULTGROUP" -value $VAULTGROUP
Replace-PlaceholderInFile -filePath $deployFilePath -placeholder "BUCKETREGION" -value $BUCKETREGION
# Pipeline USage
# $params = @{
# VAULTNAME = "myVaultName"
# VAULTGROUP = "myVaultGroup"
# BUCKETREGION = "westus"
# }
# $params | .\Gen-Providers.ps1