Public/Set-Terraform.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
function Set-Terraform {

    Param(
        [Parameter(Mandatory=$false,Position=1)]
        [string]$Path
    )

    $Params = @{}

    if ($PSBoundParameters['Path']) {
        $Params['Path'] = $PSBoundParameters['Path']
    }

    # Execute Terraform config
    Write-Verbose "Creating plan with command 'terraform plan -out=./create.plan'"
    Invoke-Terraform -ArgumentList "plan","-out=`"./create.plan`"" -Path $Path -Attach
    Write-Verbose "Applying plan with command 'terraform apply ./create.plan'"
    Invoke-Terraform -ArgumentList "apply","./create.plan" -Path $Path -Attach

    Remove-Item -Path (Join-Path $Path "/create.plan") -Force

    # Get config from key vault
    Set-Environment -VaultName (Get-TerraformOutput -Path $Path -OutputName key_vault_name)

}