-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gen-Backend.ps1
63 lines (46 loc) · 1.98 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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"
$deployFilePath = Join-Path $deployPath "backend.tf"
Copy-Item -Path $templatePath -Destination $deployFilePath
# Function to replace placeholder in file
function Replace-PlaceholderInFile {
param($filePath, $placeholder, $value)
Write-Output "Replacing $placeholder with $value in $filePath"
# Read the file content
$content = Get-Content -Path $filePath -Raw
# Replace the content
$newContent = $content -replace "<<<$placeholder>>>", $value
# Write the new content back to the file
Set-Content -Path $filePath -Value $newContent
# Output the updated content for debugging
Write-Output "Updated content of $filePath"
Get-Content -Path $filePath
}
# Replace placeholders with parameter values
if ($BUCKET) { Replace-PlaceholderInFile -filePath $deployFilePath -placeholder "BUCKET" -value $BUCKET }
if ($BUCKETKEY) { Replace-PlaceholderInFile -filePath $deployFilePath -placeholder "BUCKETKEY" -value $BUCKETKEY }
if ($BUCKETREGION) { Replace-PlaceholderInFile -filePath $deployFilePath -placeholder "BUCKETREGION" -value $BUCKETREGION }
if ($BUCKETENDPOINT) { Replace-PlaceholderInFile -filePath $deployFilePath -placeholder "BUCKETENDPOINT" -value $BUCKETENDPOINT }
# Pip
# $params = @{
# BUCKET = "myBucketName"
# BUCKETKEY = "myBucketKey"
# BUCKETREGION = "myBucketRegion"
# BUCKETENDPOINT = "myBucketEndpoint"
# }
# $params | .\Gen-BackEnd.ps1