-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gen-Backend.ps1
41 lines (34 loc) · 1.44 KB
/
Gen-Backend.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
param(
[Parameter(ValueFromPipelineByPropertyName = $true)]
[string]$BUCKET,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[string]$BUCKETKEY,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[string]$BUCKETREGION,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[string]$BUCKETENDPOINT
)
# 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 backend.tf template to .\Deploy
$templatePath = ".\templates\backend.tf"
if(Test-Path $templatePath){
$deployFilePath = Join-Path $deployPath "backend.tf"
Copy-Item -Path $templatePath -Destination $deployFilePath
function Replace-PlaceholderInFile {
param($filePath, $placeholder, $value)
Write-Output "replacing $placeholder with $value"
(Get-Content $filePath) -replace "<<<$placeholder>>>", $value | Set-Content $filePath
}
# Replace placeholders with parameter values
Replace-PlaceholderInFile -filePath $deployFilePath -placeholder "BUCKET" -value $BUCKET
Replace-PlaceholderInFile -filePath $deployFilePath -placeholder "BUCKETKEY" -value $BUCKETKEY
Replace-PlaceholderInFile -filePath $deployFilePath -placeholder "BUCKETREGION" -value $BUCKETREGION
Replace-PlaceholderInFile -filePath $deployFilePath -placeholder "BUCKETENDPOINT" -value $BUCKETENDPOINT
}
else {
Write-Output "No backend.tf found, skipping step."
}