-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathresource.ps1
executable file
·53 lines (46 loc) · 1.15 KB
/
resource.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
#!/usr/bin/env pwsh
param([Parameter(Mandatory)][string]$resource, $type = "resource")
function path()
{
if ($Env:OS -eq "Windows_NT")
{
$slash = "\"
}
else
{
$slash = "/"
}
$path = $args[0]
for ($i = 1; $i -lt $args.count; $i++) {
$path += $slash + $args[$i]
}
return $path
}
$provider = $resource.Split("_")[0]
$baseMapping = path $PSScriptRoot "src" "mapping" $provider
$mapping = path $baseMapping $type
write-host "Copying to $baseMapping"
if (test-path($baseMapping))
{
$source = path $mapping "template.json"
$destination = path $mapping "$resource.json"
Copy-Item -path $source -destination $destination
}
else
{
write-host "$baseMapping not found"
}
if ($type -eq "data")
{
$content = "data `"$resource`" `"pike`" {`n}`n`n"
$output = "output `"$resource`" {`n value = data.$resource.pike`n}"
$content = $content + $output
$tffile = path terraform $provider "$type.$resource.tf"
}
else
{
$content = "resource `"$resource`" `"pike`" {}"
$tffile = path terraform $provider "$resource.tf"
}
$tffile = path $PSScriptRoot $tffile
new-item $tffile -value $content