Created
May 31, 2019 09:57
-
-
Save mamoorkhan/1a5a02fc34f3f3c9df064ea5d08cea0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[string]$environment, | |
[string]$location, | |
[string]$subscription_id, | |
[string]$client_id, | |
[string]$client_secret, | |
[string]$tenant_id, | |
[string]$service_principal_id | |
) | |
$Error.Clear() | |
try { | |
Push-Location (Split-Path $MyInvocation.MyCommand.Path) | |
$tfvars = "terraform.tfvars" | |
if (Test-Path $tfvars) { | |
Remove-Item $tfvars | |
} | |
New-Item -Path 'terraform.tfvars' -ItemType File | |
Add-Content terraform.tfvars "environment = `"$environment`"" | |
Add-Content terraform.tfvars "location = `"$location`"" | |
Add-Content terraform.tfvars "subscription_id = `"$subscription_id`"" | |
Add-Content terraform.tfvars "client_id = `"$client_id`"" | |
Add-Content terraform.tfvars "client_secret = `"$client_secret`"" | |
Add-Content terraform.tfvars "tenant_id = `"$tenant_id`"" | |
Add-Content terraform.tfvars "service_principal_id = `"$service_principal_id`"" | |
(Get-Content provider.txt).replace('[subscription_id]', $subscription_id) | Set-Content provider.tf | |
(Get-Content provider.tf).replace('[client_id]', $client_id) | Set-Content provider.tf | |
(Get-Content provider.tf).replace('[client_secret]', $client_secret) | Set-Content provider.tf | |
(Get-Content provider.tf).replace('[tenant_id]', $tenant_id) | Set-Content provider.tf | |
(Get-Content provider.tf).replace('[container_name]', $environment) | Set-Content provider.tf | |
(Get-Content provider.tf).replace('[tfstate_key]', 'terraform.tfstate') | Set-Content provider.tf | |
.\terraform.exe init -input=false | |
.\terraform.exe plan -input=false | |
.\terraform.exe apply -input=false -auto-approve | |
Pop-Location | |
} | |
catch { | |
$Error[0] | format-list -force | |
$Error | Sort-Object | ForEach-Object { $ScriptError = $_.InvocationInfo; Write-Host ("Error on line " + $ScriptError.ScriptLineNumber + ", column " + $ScriptError.OffsetInLine + ' executing "' + $ScriptError.Line + '"') } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment