blob: 3683513b72f1ec46f3c6209a034ebe0c193fbbb5 (
plain)
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
|
[CmdletBinding()]
param (
[Parameter()]
[string]
$PluginsDirectory
)
$script:PSDefaultParameterValues = @{
'*:Confirm' = $false
'*:ErrorAction' = 'Stop'
}
function Install-Provider {
[CmdletBinding()]
param (
[Parameter(Mandatory, Position=0, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[ValidateNotNullOrEmpty()]
[string]
$LiteralPath
)
PROCESS {
if (Test-Path -Path $LiteralPath) {
Write-Verbose -Message "Terraform Plugins directory [$LiteralPath] already exists"
}
else {
Write-Verbose -Message "Creating Terraform Plugins directory [$LiteralPath]"
$null = New-Item -Path $LiteralPath -ItemType Directory
}
Write-Host "Installing provider to $LiteralPath"
Copy-Item -Path (Join-Path -Path $BUILD_DIR -ChildPath '*') -Destination $LiteralPath -Force
}
}
if (-not $PluginsDirectory) {
. (Join-Path -Path $PSScriptRoot -ChildPath 'commons.ps1' -Resolve)
# https://www.terraform.io/docs/plugins/basics.html
# https://www.terraform.io/docs/extend/how-terraform-works.html#discovery
if ($env:OS -like '*Windows*') {
$PluginsBase = $env:APPDATA
}
else {
$PluginsBase = $HOME
}
$PluginsDirectory = [System.IO.Path]::Combine($PluginsBase, '.terraform.d', 'plugins')
Install-Provider -LiteralPath $PluginsDirectory
## Terraform >= v0.13 requires different layout
$ProviderName=Get-Content -LiteralPath "$PROVIDER_NAME_FILE"
$ProviderVersion=Get-Content -LiteralPath "$PROVIDER_VERSION_FILE"
$ProviderRegistry='registry.terraform.io'
$ProviderOrganization='terraform-providers'
$PluginsDirectory = [System.IO.Path]::Combine($PluginsDirectory, $ProviderRegistry, $ProviderOrganization, $ProviderName, $ProviderVersion, "${OS}_${PROC}")
Install-Provider -LiteralPath $PluginsDirectory
}
else {
Install-Provider -LiteralPath $PluginsDirectory
}
|